doclist: sublists of multiple dates grouped by year
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 18 Nov 2019 15:12:26 +0000 (16:12 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 29 Nov 2019 23:02:03 +0000 (00:02 +0100)
widget/doclist.php

index a4657680edd7efc2fab2273a49e82ee8ecbe6f72..5c11c6867bace1d99f0c605eda64b5efa4c3709f 100644 (file)
@@ -6,11 +6,12 @@ foreach (glob("$Page$Args/2*") as $url) {
        $link = preg_replace('/\.html$/', '', $url);
        $name = pathinfo($link, PATHINFO_BASENAME);
        @list ($date, $suffix) = explode('.', $name, 2);
-       if (!isset($cal[$date])) {
-               $cal[$date] = [];
+       $group = substr($date, 0, 4);
+       if (!isset($cal[$group][$date])) {
+               $cal[$group][$date] = [];
        }
        if (!is_dir($url) and filesize($url)) {
-               $cal[$date][$suffix] = $link;
+               $cal[$group][$date][$suffix] = $link;
        }
 }
 
@@ -19,8 +20,17 @@ $scale = 8;  # em width per year
 $mindate = strtotime($date) + ($year / $scale * 3);  # first point plus about 3em for centered text
 
 print '<ul class="timeline">'."\n";
-foreach (array_reverse($cal) as $title => $versions) {
+foreach (array_reverse($cal, TRUE) as $group => $rows) {
+       if (count($rows) > 1) {
+               $time = ($mindate - strtotime("$group-12-31T23:59")) / $year * $scale;
+               printf('<li class="range" style="left:%.1fem; width:%sem">', $time, $scale);
+               print "<strong>$group</strong><ul>\n";
+       }
+       else {
                $time = 0;
+       }
+
+       foreach ($rows as $title => $versions) {
                $subtime = ($mindate - strtotime($title)) / $year * $scale - $time;
                printf('<li style="left:%.1fem">', $subtime);
                if ($url = @$versions['']) {
@@ -40,6 +50,11 @@ foreach (array_reverse($cal) as $title => $versions) {
                        print '</span>';
                }
                print "</li>\n";
+       }
+
+       if (count($rows) > 1) {
+               print "</ul></li>\n";
+       }
 }
 print "</ul>\n\n";