year calendar: only link to months that have posts
authorJoey Hess <joey@gnu.kitenet.net>
Mon, 12 Oct 2009 18:19:04 +0000 (14:19 -0400)
committerJoey Hess <joey@gnu.kitenet.net>
Mon, 12 Oct 2009 18:19:04 +0000 (14:19 -0400)
This does mean the year calendars depend on existence of all posts made in
the year and have to be updated.

IkiWiki/Plugin/calendar.pm

index d5a80795a1aee782f75b4ba266bed13d56e7ce50..ddcd1a82350d0058a1c22e4abd99297adb059773 100644 (file)
@@ -242,6 +242,20 @@ EOF
 
 sub format_year (@) {
        my %params=@_;
+       
+       my @post_months;
+       foreach my $p (pagespec_match_list($params{page}, 
+                               "creation_year($params{year}) and ($params{pages})",
+                               # add presence dependencies to update
+                               # year calendar's links to months when
+                               # pages are added/removed
+                               deptype => deptype("presence"))) {
+               my $mtime = $IkiWiki::pagectime{$p};
+               my @date  = localtime($mtime);
+               my $month = $date[4] + 1;
+
+               $post_months[$month]++;
+       }
                
        my $calendar="\n";
        
@@ -313,7 +327,8 @@ EOF
                        $tag = 'year-calendar-month-nolink';
                }
 
-               if ($pagesources{"$archivebase/$params{year}/$mtag"}) {
+               if ($pagesources{"$archivebase/$params{year}/$mtag"} &&
+                   $post_months[$mtag]) {
                        $murl = htmllink($params{page}, $params{destpage}, 
                                "$archivebase/$params{year}/$mtag",
                                noimageinline => 1,