Add sorting prefix "[0-9]+_"
authorChristian Weiske <cweiske@cweiske.de>
Wed, 25 Nov 2015 16:23:54 +0000 (17:23 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 25 Nov 2015 16:23:54 +0000 (17:23 +0100)
README.rst
www/index.php

index 9d86b21832d7d8ef9a347cde026972d6352c3a9b..afd652ef77d7dc1276f5ca5a3987096120e006ac 100644 (file)
@@ -62,6 +62,30 @@ Directory
 File extensions get removed for display purposes.
 
 
 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
 =====
 =====
 Setup
 =====
index 2a380377f89e175fcdfccfd73cfea60e9b4d909d..d7d758f2ff4fde49ba6a7a8bee98efa3fe99df64 100644 (file)
@@ -112,20 +112,23 @@ function sendDir($path)
     foreach ($entries as $entry) {
         $urlPath = pathEncode(substr($entry, strlen($varDir)));
         $ext = pathinfo($entry, PATHINFO_EXTENSION);
     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;
         if (is_dir($entry)) {
             ++$count;
-            $listItems[] = getDirItem(basename($entry), $urlPath . '/');
+            $listItems[] = getDirItem($titleBase, $urlPath . '/');
         } else if ($ext == 'url') {
             //podcast
             ++$count;
         } 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;
         } 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) {
         }
     }
     if (!$count) {