doclist: timeline styling to position links by age
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 16 Nov 2019 20:47:53 +0000 (21:47 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 27 Nov 2019 12:27:51 +0000 (13:27 +0100)
Calculate absolute "left" position based on average date lengths,
to be optionally used by the site's stylesheet.

widget/doclist.php

index 796a4ad2812a7e3592d8d020974bb00becd976de..2d858843fd4f84026b27103e7ddf19be36b982f9 100644 (file)
@@ -14,15 +14,17 @@ foreach (glob("$Page$Args/2*") as $url) {
        }
 }
 
-print '<ul';
-if (count($cal) > 5) print ' class="cols"';
-print ">\n";
+$mindate = strtotime($date);
+
+print '<ul class="timeline">'."\n";
 foreach (array_reverse($cal) as $title => $versions) {
-       print '<li>';
+       $time = ($mindate - strtotime($title)) / (3600 * 24 * 365 / 8); # ~8em/yr
+       printf('<li style="left:%.1fem">', $time);
        if ($url = @$versions['']) {
                printf('<a href="/%s">%s</a>', $url, $title);
        }
        else {
+               print '<span>';
                print $title;
                if ($versions and $User->admin("edit $Page$Args")) {
                        printf(' (%s)', implode(', ', array_map(
@@ -32,6 +34,7 @@ foreach (array_reverse($cal) as $title => $versions) {
                                array_keys($versions), $versions)
                        ));
                }
+               print '</span>';
        }
        print "</li>\n";
 }