From: Christian Weiske Date: Wed, 25 Nov 2015 16:23:54 +0000 (+0100) Subject: Add sorting prefix "[0-9]+_" X-Git-Tag: v0.1.0~6 X-Git-Url: https://git.cweiske.de/noxon-gateway.git/commitdiff_plain/66b32e4e390df8227c0367c868d33fbf2c9f736a Add sorting prefix "[0-9]+_" --- diff --git a/README.rst b/README.rst index 9d86b21..afd652e 100644 --- a/README.rst +++ b/README.rst @@ -62,6 +62,30 @@ Directory File extensions get removed for display purposes. +Sorting +======= +Files and directory are sorted alphabetically and get listed +in this order. + +You can prefix your files and directories with ``[0-9]+_``, +which lets you influence sorting and gets removed in the +listings. + +Consider the following files:: + + 01_temp.auto.sh + 02_warmer.sh + 03_colder.sh + +Would render as:: + + Temperature: 23°C + warmer + colder + +(given that ``01_temp.auto.sh`` outputs the temperature string) + + ===== Setup ===== diff --git a/www/index.php b/www/index.php index 2a38037..d7d758f 100644 --- a/www/index.php +++ b/www/index.php @@ -112,20 +112,23 @@ function sendDir($path) foreach ($entries as $entry) { $urlPath = pathEncode(substr($entry, strlen($varDir))); $ext = pathinfo($entry, PATHINFO_EXTENSION); + + $titleBase = basename($entry); + $titleBase = preg_replace('#^[0-9]+_#', '', $titleBase); if (is_dir($entry)) { ++$count; - $listItems[] = getDirItem(basename($entry), $urlPath . '/'); + $listItems[] = getDirItem($titleBase, $urlPath . '/'); } else if ($ext == 'url') { //podcast ++$count; - $listItems[] = getPodcastItem(basename($entry, '.url'), $urlPath); + $listItems[] = getPodcastItem(basename($titleBase, '.url'), $urlPath); } else if (substr($entry, -8) == '.auto.sh') { //automatically execute script while listing this directory addScriptOutput($listItems, $entry); } else if ($ext == 'txt' || $ext == 'sh') { //plain text file ++$count; - $listItems[] = getDirItem(basename($entry, '.' . $ext), $urlPath); + $listItems[] = getDirItem(basename($titleBase, '.' . $ext), $urlPath); } } if (!$count) {