From a6689f9c7a1ecad02b51962c0858df47352c4648 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Oct 2009 16:05:41 -0400 Subject: calendar: all dependencies are contentless --- IkiWiki/Plugin/calendar.pm | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index 5d16dff75..a5cc20882 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -104,19 +104,22 @@ sub format_month (@) { "$archivebase/$year/".sprintf("%02d", $month), linktext => " $monthname "); } - add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month)); + add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month), + content => 0); if (exists $cache{$pagespec}{"$pyear/$pmonth"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear/" . sprintf("%02d", $pmonth), linktext => " $pmonthname "); } - add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth)); + add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth), + content => 0); if (exists $cache{$pagespec}{"$nyear/$nmonth"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear/" . sprintf("%02d", $nmonth), linktext => " $nmonthname "); } - add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth)); + add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth), + content => 0); # Start producing the month calendar $calendar=< 0); # Explicitly add all currently linked pages as dependencies, so # that if they are removed, the calendar will be sure to be updated. foreach my $p (@list) { - add_depends($params{page}, $p); + add_depends($params{page}, $p, content => 0); } return $calendar; @@ -246,19 +249,19 @@ sub format_year (@) { "$archivebase/$year", linktext => "$year"); } - add_depends($params{page}, "$archivebase/$year"); + add_depends($params{page}, "$archivebase/$year", content => 0); if (exists $cache{$pagespec}{"$pyear"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear", linktext => "\←"); } - add_depends($params{page}, "$archivebase/$pyear"); + add_depends($params{page}, "$archivebase/$pyear", content => 0); if (exists $cache{$pagespec}{"$nyear"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear", linktext => "\→"); } - add_depends($params{page}, "$archivebase/$nyear"); + add_depends($params{page}, "$archivebase/$nyear", content => 0); # Start producing the year calendar $calendar=<$monthabbr\n}; } - add_depends($params{page}, "$archivebase/$year/$mtag"); + add_depends($params{page}, "$archivebase/$year/$mtag", content => 0); $calendar.=qq{\t\n} if ($month % $params{months_per_row} == 0); } -- cgit v1.2.3 From be032a7b87d1080f1a54327346cb5b40432a056c Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 4 Oct 2009 20:30:21 -0400 Subject: rework dependency types code Simplify, change default content depends number to 1, change interface to make more sense. --- IkiWiki.pm | 35 +++++++++++++++-------------------- IkiWiki/Plugin/calendar.pm | 18 +++++++++--------- IkiWiki/Plugin/edittemplate.pm | 2 +- IkiWiki/Plugin/listdirectives.pm | 2 +- IkiWiki/Plugin/meta.pm | 2 +- IkiWiki/Plugin/pagecount.pm | 4 ++-- IkiWiki/Plugin/postsparkline.pm | 2 +- IkiWiki/Plugin/progress.pm | 4 ++-- IkiWiki/Render.pm | 28 +++++++++++++--------------- doc/plugins/write.mdwn | 15 +++++++++------ ikiwiki-transition | 2 +- 11 files changed, 55 insertions(+), 59 deletions(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki.pm b/IkiWiki.pm index 5e5dc739d..c1d07531e 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -29,8 +29,8 @@ our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE our $installdir='/usr'; # INSTALLDIR_AUTOREPLACE done by Makefile, DNE # Page dependency types. -our $DEPEND_EXISTS=1; -our $DEPEND_CONTENT=2; +our $DEPEND_CONTENT=1; +our $DEPEND_PRESENCE=2; # Optimisation. use Memoize; @@ -1540,13 +1540,13 @@ sub loadindex () { if (exists $d->{dependslist}) { # old format $depends{$page}={ - map { $_ => $DEPEND_CONTENT | $DEPEND_EXISTS } + map { $_ => $DEPEND_CONTENT } @{$d->{dependslist}} }; } elsif (exists $d->{depends} && ! ref $d->{depends}) { # old format - $depends{$page}={$d->{depends} => $DEPEND_CONTENT | $DEPEND_EXISTS}; + $depends{$page}={$d->{depends} => $DEPEND_CONTENT }; } elsif (exists $d->{depends}) { $depends{$page}=$d->{depends}; @@ -1771,16 +1771,23 @@ sub add_depends ($$;@) { my $page=shift; my $pagespec=shift; + # Is the pagespec a simple page name? my $simple=$pagespec =~ /$config{wiki_file_regexp}/ && $pagespec !~ /[\s*?()!]/; - my $deptype=$DEPEND_CONTENT | $DEPEND_EXISTS; + my $deptype=$DEPEND_CONTENT; if (@_) { my %params=@_; - if (defined $params{content} && $params{content} == 0 && - ($simple || pagespec_contentless($pagespec))) { - $deptype=$deptype & ~$DEPEND_CONTENT; + + # Is the pagespec limited to terms that will continue + # to match pages as long as those pages exist? + my $limited=1; + while ($limited && $pagespec=~m/(\w+)\([^\)]*\)/g) { + $limited = $1 =~ /^(glob|internal|creation_month|creation_day|creation_year|created_before|created_after)$/; } + + $deptype=$deptype & ~$DEPEND_CONTENT & $DEPEND_PRESENCE + if $params{presence} && $limited; } if ($simple) { @@ -1976,18 +1983,6 @@ sub pagespec_valid ($) { return ! $@; } -sub pagespec_contentless ($) { - my $spec=shift; - - while ($spec=~m{ - (\w+)\([^\)]*\) # only match pagespec functions - }igx) { - return 0 unless $1=~/^(glob|internal|creation_month|creation_day|creation_year|created_before|created_after)$/; - } - - return 1; -} - sub glob2re ($) { my $re=quotemeta(shift); $re=~s/\\\*/.*/g; diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index a5cc20882..a1117992a 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -105,21 +105,21 @@ sub format_month (@) { linktext => " $monthname "); } add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month), - content => 0); + presence => 1); if (exists $cache{$pagespec}{"$pyear/$pmonth"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear/" . sprintf("%02d", $pmonth), linktext => " $pmonthname "); } add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth), - content => 0); + presence => 1); if (exists $cache{$pagespec}{"$nyear/$nmonth"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear/" . sprintf("%02d", $nmonth), linktext => " $nmonthname "); } add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth), - content => 0); + presence => 1); # Start producing the month calendar $calendar=< 0); + add_depends($params{page}, $params{pages}, presence => 1); # Explicitly add all currently linked pages as dependencies, so # that if they are removed, the calendar will be sure to be updated. foreach my $p (@list) { - add_depends($params{page}, $p, content => 0); + add_depends($params{page}, $p, presence => 1); } return $calendar; @@ -249,19 +249,19 @@ sub format_year (@) { "$archivebase/$year", linktext => "$year"); } - add_depends($params{page}, "$archivebase/$year", content => 0); + add_depends($params{page}, "$archivebase/$year", presence => 1); if (exists $cache{$pagespec}{"$pyear"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear", linktext => "\←"); } - add_depends($params{page}, "$archivebase/$pyear", content => 0); + add_depends($params{page}, "$archivebase/$pyear", presence => 1); if (exists $cache{$pagespec}{"$nyear"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear", linktext => "\→"); } - add_depends($params{page}, "$archivebase/$nyear", content => 0); + add_depends($params{page}, "$archivebase/$nyear", presence => 1); # Start producing the year calendar $calendar=<$monthabbr\n}; } - add_depends($params{page}, "$archivebase/$year/$mtag", content => 0); + add_depends($params{page}, "$archivebase/$year/$mtag", presence => 1); $calendar.=qq{\t\n} if ($month % $params{months_per_row} == 0); } diff --git a/IkiWiki/Plugin/edittemplate.pm b/IkiWiki/Plugin/edittemplate.pm index 89d450725..2dd1dbe68 100644 --- a/IkiWiki/Plugin/edittemplate.pm +++ b/IkiWiki/Plugin/edittemplate.pm @@ -58,7 +58,7 @@ sub preprocess (@) { $pagestate{$params{page}}{edittemplate}{$params{match}}=$link; return "" if ($params{silent} && IkiWiki::yesno($params{silent})); - add_depends($params{page}, $link, content => 0); + add_depends($params{page}, $link, presence => 1); return sprintf(gettext("edittemplate %s registered for %s"), htmllink($params{page}, $params{destpage}, $link), $params{match}); diff --git a/IkiWiki/Plugin/listdirectives.pm b/IkiWiki/Plugin/listdirectives.pm index 96150f986..4023ed7d7 100644 --- a/IkiWiki/Plugin/listdirectives.pm +++ b/IkiWiki/Plugin/listdirectives.pm @@ -84,7 +84,7 @@ sub preprocess (@) { foreach my $plugin (@pluginlist) { $result .= '
  • '; my $link=linkpage($config{directive_description_dir}."/".$plugin); - add_depends($params{page}, $link, content => 0); + add_depends($params{page}, $link, presence => 1); $result .= htmllink($params{page}, $params{destpage}, $link); $result .= '
  • '; } diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index eef3013a0..9b041a748 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -195,7 +195,7 @@ sub preprocess (@) { if (! length $link) { error gettext("redir page not found") } - add_depends($page, $link, content => 0); + add_depends($page, $link, presence => 1); $value=urlto($link, $page); $value.='#'.$redir_anchor if defined $redir_anchor; diff --git a/IkiWiki/Plugin/pagecount.pm b/IkiWiki/Plugin/pagecount.pm index 17eda0618..80561350b 100644 --- a/IkiWiki/Plugin/pagecount.pm +++ b/IkiWiki/Plugin/pagecount.pm @@ -23,8 +23,8 @@ sub preprocess (@) { $params{pages}="*" unless defined $params{pages}; # Needs to update count whenever a page is added or removed, so - # register a contentless dependency. - add_depends($params{page}, $params{pages}, content => 0); + # register a presence dependency. + add_depends($params{page}, $params{pages}, presence => 1); my @pages; if ($params{pages} eq "*") { diff --git a/IkiWiki/Plugin/postsparkline.pm b/IkiWiki/Plugin/postsparkline.pm index 694d39575..3205958d4 100644 --- a/IkiWiki/Plugin/postsparkline.pm +++ b/IkiWiki/Plugin/postsparkline.pm @@ -48,7 +48,7 @@ sub preprocess (@) { error gettext("unknown formula"); } - add_depends($params{page}, $params{pages}, content => 0); + add_depends($params{page}, $params{pages}, presence => 1); my @list=sort { $params{timehash}->{$b} <=> $params{timehash}->{$a} } pagespec_match_list( diff --git a/IkiWiki/Plugin/progress.pm b/IkiWiki/Plugin/progress.pm index 3b664f4cb..26c537a84 100644 --- a/IkiWiki/Plugin/progress.pm +++ b/IkiWiki/Plugin/progress.pm @@ -36,8 +36,8 @@ sub preprocess (@) { $fill.="%"; } elsif (defined $params{totalpages} and defined $params{donepages}) { - add_depends($params{page}, $params{totalpages}, content => 0); - add_depends($params{page}, $params{donepages}, content => 0); + add_depends($params{page}, $params{totalpages}, presence => 1); + add_depends($params{page}, $params{donepages}, presence => 1); my @pages=keys %pagesources; my $totalcount=0; diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index 3fc750925..cf0c3fe08 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -473,13 +473,11 @@ sub refresh () { if (exists $depends_simple{$p}) { foreach my $d (keys %{$depends_simple{$p}}) { - if ($depends_simple{$p}{$d} == $IkiWiki::DEPEND_EXISTS) { - if (exists $lc_exists_changed{$d}) { - $reason = $d; - last; - } - } - elsif (exists $lc_changed{$d}) { + if (($depends_simple{$p}{$d} & $IkiWiki::DEPEND_CONTENT && + exists $lc_changed{$d}) + || + ($depends_simple{$p}{$d} & $IkiWiki::DEPEND_PRESENCE && + exists $lc_exists_changed{$d})) { $reason = $d; last; } @@ -492,22 +490,22 @@ sub refresh () { next if $@ || ! defined $sub; my @candidates; - if ($depends{$p}{$d} == $IkiWiki::DEPEND_EXISTS) { - @candidates=@exists_changed; - } - else { + if ($depends_simple{$p}{$d} & $IkiWiki::DEPEND_CONTENT) { @candidates=@changed; } + elsif ($depends{$p}{$d} & $IkiWiki::DEPEND_PRESENCE) { + @candidates=@exists_changed; + } # only consider internal files # if the page explicitly depends # on such files if ($d =~ /internal\(/) { - if ($depends{$p}{$d} == $IkiWiki::DEPEND_EXISTS) { - push @candidates, @internal; - } - else { + if ($depends_simple{$p}{$d} & $IkiWiki::DEPEND_CONTENT) { push @candidates, @internal, @internal_change; } + elsif ($depends{$p}{$d} & $IkiWiki::DEPEND_PRESENCE) { + push @candidates, @internal; + } } foreach my $file (@candidates) { diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index c244c1f2f..73db6f12a 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -613,12 +613,15 @@ generating a link to a page. Makes the specified page depend on the specified [[ikiwiki/PageSpec]]. -Additional named parameters can be passed, to indicate what type of -dependency this is. - -Currently, only a "content" parameter is specified. If set to 0, the -dependency does not involve the content of pages matching the PageSpec, but -only their existence. +By default, dependencies are full content dependencies, meaning that the +page will be updated whenever anything matching the PageSpec is modified. +This default can be overridden by additional named parameters, which can be +used to indicate weaker types of dependencies: + +* `presence` if set to true, only the presence of a matching page triggers + the dependency. +* `links` if set to true, any change in the text of links on a matching page + triggers the dependency #### `pagespec_match($$;@)` diff --git a/ikiwiki-transition b/ikiwiki-transition index c50a748e8..1bebb1176 100755 --- a/ikiwiki-transition +++ b/ikiwiki-transition @@ -299,7 +299,7 @@ sub oldloadindex { $pagemtime{$page}=$items{mtime}[0]; $oldlinks{$page}=[@{$items{link}}]; $links{$page}=[@{$items{link}}]; - $depends{$page}={ $items{depends}[0] => $IkiWiki::DEPEND_CONTENT | $IkiWiki::DEPEND_EXISTS } if exists $items{depends}; + $depends{$page}={ $items{depends}[0] => $IkiWiki::DEPEND_CONTENT } if exists $items{depends}; $destsources{$_}=$page foreach @{$items{dest}}; $renderedfiles{$page}=[@{$items{dest}}]; $pagecase{lc $page}=$page; -- cgit v1.2.3 From 957ded9d64ca6abf0127c5c49e24177685bac5ae Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 7 Oct 2009 21:57:31 -0400 Subject: remove explicit addition of dependencies for displayed pages that hack is not needed, thanks to pagespec influences calculation --- IkiWiki/Plugin/calendar.pm | 5 ----- IkiWiki/Plugin/inline.pm | 6 ------ IkiWiki/Plugin/map.pm | 5 ----- 3 files changed, 16 deletions(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index a1117992a..ec8e232e1 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -213,11 +213,6 @@ EOF # Add dependencies to update the calendar whenever pages # matching the pagespec are added or removed. add_depends($params{page}, $params{pages}, presence => 1); - # Explicitly add all currently linked pages as dependencies, so - # that if they are removed, the calendar will be sure to be updated. - foreach my $p (@list) { - add_depends($params{page}, $p, presence => 1); - } return $calendar; } diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index cebd9037c..fc4e00a83 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -247,12 +247,6 @@ sub preprocess_inline (@) { @list=@list[0..$params{show} - 1]; } - # Explicitly add all currently displayed pages as dependencies, so - # that if they are removed, the inline will be sure to be updated. - foreach my $p ($#list >= $#feedlist ? @list : @feedlist) { - add_depends($params{page}, $p, presence => $quick); - } - if ($feeds && exists $params{feedpages}) { @feedlist=pagespec_match_list(\@feedlist, $params{feedpages}, location => $params{page}); } diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm index 625cfdfca..46f11dc89 100644 --- a/IkiWiki/Plugin/map.pm +++ b/IkiWiki/Plugin/map.pm @@ -71,11 +71,6 @@ sub preprocess (@) { # cases, when its content changes, if show= is specified), so # register a dependency. add_depends($params{page}, $params{pages}, presence => ! exists $params{show}); - # Explicitly add all currently shown pages, to detect when pages - # are removed. - foreach my $item (keys %mapitems) { - add_depends($params{page}, $item, presence => ! exists $params{show}); - } # Create the map. my $parent=""; -- cgit v1.2.3 From c57908b9d073500608d656adaf2bd3048c8cef67 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Oct 2009 16:49:03 -0400 Subject: change how dependency types are specified to add_depends Also, this fixes 2 bugs in dependency info. --- IkiWiki/Plugin/brokenlinks.pm | 2 +- IkiWiki/Plugin/calendar.pm | 17 +++++++++-------- IkiWiki/Plugin/edittemplate.pm | 2 +- IkiWiki/Plugin/inline.pm | 7 ++++++- IkiWiki/Plugin/linkmap.pm | 2 +- IkiWiki/Plugin/listdirectives.pm | 2 +- IkiWiki/Plugin/map.pm | 3 ++- IkiWiki/Plugin/meta.pm | 2 +- IkiWiki/Plugin/orphans.pm | 4 ++-- IkiWiki/Plugin/pagecount.pm | 2 +- IkiWiki/Plugin/pagestats.pm | 4 ++-- IkiWiki/Plugin/postsparkline.pm | 2 +- IkiWiki/Plugin/progress.pm | 4 ++-- 13 files changed, 30 insertions(+), 23 deletions(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki/Plugin/brokenlinks.pm b/IkiWiki/Plugin/brokenlinks.pm index 9e65f52c6..62a0a42f4 100644 --- a/IkiWiki/Plugin/brokenlinks.pm +++ b/IkiWiki/Plugin/brokenlinks.pm @@ -24,7 +24,7 @@ sub preprocess (@) { $params{pages}="*" unless defined $params{pages}; # Needs to update whenever the links on a page change. - add_depends($params{page}, $params{pages}, links => 1); + add_depends($params{page}, $params{pages}, deptype("links")); my @broken; foreach my $link (keys %IkiWiki::brokenlinks) { diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index ec8e232e1..c99170f92 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -105,21 +105,21 @@ sub format_month (@) { linktext => " $monthname "); } add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month), - presence => 1); + deptype("presence")); if (exists $cache{$pagespec}{"$pyear/$pmonth"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear/" . sprintf("%02d", $pmonth), linktext => " $pmonthname "); } add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth), - presence => 1); + deptype("presence")); if (exists $cache{$pagespec}{"$nyear/$nmonth"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear/" . sprintf("%02d", $nmonth), linktext => " $nmonthname "); } add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth), - presence => 1); + deptype("presence")); # Start producing the month calendar $calendar=< 1); + add_depends($params{page}, $params{pages}, deptype("presence")); return $calendar; } @@ -244,19 +244,19 @@ sub format_year (@) { "$archivebase/$year", linktext => "$year"); } - add_depends($params{page}, "$archivebase/$year", presence => 1); + add_depends($params{page}, "$archivebase/$year", deptype("presence"); if (exists $cache{$pagespec}{"$pyear"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear", linktext => "\←"); } - add_depends($params{page}, "$archivebase/$pyear", presence => 1); + add_depends($params{page}, "$archivebase/$pyear", deptype("presence")); if (exists $cache{$pagespec}{"$nyear"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear", linktext => "\→"); } - add_depends($params{page}, "$archivebase/$nyear", presence => 1); + add_depends($params{page}, "$archivebase/$nyear", deptype("presence")); # Start producing the year calendar $calendar=<$monthabbr\n}; } - add_depends($params{page}, "$archivebase/$year/$mtag", presence => 1); + add_depends($params{page}, "$archivebase/$year/$mtag", + deptype("presence")); $calendar.=qq{\t\n} if ($month % $params{months_per_row} == 0); } diff --git a/IkiWiki/Plugin/edittemplate.pm b/IkiWiki/Plugin/edittemplate.pm index 2dd1dbe68..7d2eba194 100644 --- a/IkiWiki/Plugin/edittemplate.pm +++ b/IkiWiki/Plugin/edittemplate.pm @@ -58,7 +58,7 @@ sub preprocess (@) { $pagestate{$params{page}}{edittemplate}{$params{match}}=$link; return "" if ($params{silent} && IkiWiki::yesno($params{silent})); - add_depends($params{page}, $link, presence => 1); + add_depends($params{page}, $link, deptype("presence")); return sprintf(gettext("edittemplate %s registered for %s"), htmllink($params{page}, $params{destpage}, $link), $params{match}); diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index fc4e00a83..be1781520 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -195,9 +195,14 @@ sub preprocess_inline (@) { @list = map { bestlink($params{page}, $_) } split ' ', $params{pagenames}; + + foreach my $p (@list) { + add_depends($params{page}, $p, deptype($quick ? "presence" : "content")); + } } else { - add_depends($params{page}, $params{pages}, presence => $quick); + add_depends($params{page}, $params{pages}, + deptype($quick ? "presence" : "content")); @list = pagespec_match_list( [ grep { $_ ne $params{page} } keys %pagesources ], diff --git a/IkiWiki/Plugin/linkmap.pm b/IkiWiki/Plugin/linkmap.pm index 3d20a6521..28e4cfa13 100644 --- a/IkiWiki/Plugin/linkmap.pm +++ b/IkiWiki/Plugin/linkmap.pm @@ -30,7 +30,7 @@ sub preprocess (@) { # Needs to update whenever a relevant page is added, or removed, or # its links change. - add_depends($params{page}, $params{pages}, presence => 1, links => 1); + add_depends($params{page}, $params{pages}, deptype("presence", "links")); # Can't just return the linkmap here, since the htmlscrubber # scrubs out all tags (with good reason!) diff --git a/IkiWiki/Plugin/listdirectives.pm b/IkiWiki/Plugin/listdirectives.pm index 4023ed7d7..09f08c567 100644 --- a/IkiWiki/Plugin/listdirectives.pm +++ b/IkiWiki/Plugin/listdirectives.pm @@ -84,7 +84,7 @@ sub preprocess (@) { foreach my $plugin (@pluginlist) { $result .= '
  • '; my $link=linkpage($config{directive_description_dir}."/".$plugin); - add_depends($params{page}, $link, presence => 1); + add_depends($params{page}, $link, deptype("presence")); $result .= htmllink($params{page}, $params{destpage}, $link); $result .= '
  • '; } diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm index 46f11dc89..19872e51c 100644 --- a/IkiWiki/Plugin/map.pm +++ b/IkiWiki/Plugin/map.pm @@ -70,7 +70,8 @@ sub preprocess (@) { # Needs to update whenever a page is added or removed (or in some # cases, when its content changes, if show= is specified), so # register a dependency. - add_depends($params{page}, $params{pages}, presence => ! exists $params{show}); + add_depends($params{page}, $params{pages}, + deptype(exists $params{show} ? "content" : "presence"); # Create the map. my $parent=""; diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index da3e62233..c675880b3 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -195,7 +195,7 @@ sub preprocess (@) { if (! length $link) { error gettext("redir page not found") } - add_depends($page, $link, presence => 1); + add_depends($page, $link, deptype("presence")); $value=urlto($link, $page); $value.='#'.$redir_anchor if defined $redir_anchor; diff --git a/IkiWiki/Plugin/orphans.pm b/IkiWiki/Plugin/orphans.pm index ae330b23b..93b8ec440 100644 --- a/IkiWiki/Plugin/orphans.pm +++ b/IkiWiki/Plugin/orphans.pm @@ -26,10 +26,10 @@ sub preprocess (@) { # Needs to update whenever a link changes, on any page # since any page could link to one of the pages we're # considering as orphans. - add_depends($params{page}, "*", links => 1); + add_depends($params{page}, "*", deptype("links")); # Also needs to update whenever potential orphans are added or # removed. - add_depends($params{page}, $params{pages}, presence => 1); + add_depends($params{page}, $params{pages}, deptype("presence")); my @orphans; foreach my $page (pagespec_match_list( diff --git a/IkiWiki/Plugin/pagecount.pm b/IkiWiki/Plugin/pagecount.pm index 80561350b..419f2d535 100644 --- a/IkiWiki/Plugin/pagecount.pm +++ b/IkiWiki/Plugin/pagecount.pm @@ -24,7 +24,7 @@ sub preprocess (@) { # Needs to update count whenever a page is added or removed, so # register a presence dependency. - add_depends($params{page}, $params{pages}, presence => 1); + add_depends($params{page}, $params{pages}, deptype("presence")); my @pages; if ($params{pages} eq "*") { diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm index afe4eeaf2..cd0bdb085 100644 --- a/IkiWiki/Plugin/pagestats.pm +++ b/IkiWiki/Plugin/pagestats.pm @@ -36,12 +36,12 @@ sub preprocess (@) { my $style = ($params{style} or 'cloud'); # Needs to update whenever a page is added or removed. - add_depends($params{page}, $params{pages}, exists => 1); + add_depends($params{page}, $params{pages}, deptype("presence")); # Also needs to update when any page with links changes, # in case the links point to our displayed pages. # (Among limits this further.) add_depends($params{page}, exists $params{among} ? $params{among} : "*", - links => 1); + deptype("links")); my %counts; my $max = 0; diff --git a/IkiWiki/Plugin/postsparkline.pm b/IkiWiki/Plugin/postsparkline.pm index 3205958d4..ea73e9180 100644 --- a/IkiWiki/Plugin/postsparkline.pm +++ b/IkiWiki/Plugin/postsparkline.pm @@ -48,7 +48,7 @@ sub preprocess (@) { error gettext("unknown formula"); } - add_depends($params{page}, $params{pages}, presence => 1); + add_depends($params{page}, $params{pages}, deptype("presence")); my @list=sort { $params{timehash}->{$b} <=> $params{timehash}->{$a} } pagespec_match_list( diff --git a/IkiWiki/Plugin/progress.pm b/IkiWiki/Plugin/progress.pm index 26c537a84..6da3e4f71 100644 --- a/IkiWiki/Plugin/progress.pm +++ b/IkiWiki/Plugin/progress.pm @@ -36,8 +36,8 @@ sub preprocess (@) { $fill.="%"; } elsif (defined $params{totalpages} and defined $params{donepages}) { - add_depends($params{page}, $params{totalpages}, presence => 1); - add_depends($params{page}, $params{donepages}, presence => 1); + add_depends($params{page}, $params{totalpages}, deptype("presence")); + add_depends($params{page}, $params{donepages}, deptype("presence")); my @pages=keys %pagesources; my $totalcount=0; -- cgit v1.2.3 From 332821144b33f42b3674240d28159124ee1a5334 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Oct 2009 23:24:03 -0400 Subject: calendar: rework so it can use use_pagespec This was tricky because of the caching, and because use_pagespec always adds a dependency. That would have made year calendars depend on the whole pagespec, which is overly broad. So I removed the caching, format_month, and in format_year just look at %pagesources to see if month pages are available. In format_month, I make it always call use_pagespec, so each month calendar gets the right dependency and any influcences added. This means a bit more work, but the added work is fairly minimal, and presence dependencies remove a *lot* of work it used to do. (100% untested!) --- IkiWiki/Plugin/calendar.pm | 65 ++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 37 deletions(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index c99170f92..a89175cfb 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -24,8 +24,6 @@ use IkiWiki 3.00; use Time::Local; use POSIX; -my %cache; -my %linkcache; my $time=time; my @now=localtime($time); @@ -75,6 +73,23 @@ sub format_month (@) { my $pyear = $params{pyear}; my $nyear = $params{nyear}; + my %linkcache; + foreach my $p (use_pagespec($params{page}, $params{pagespec}, + # add presence dependencies to update + # month calendar when pages are added/removed + deptype => deptype("presence"))) { + my $mtime = $IkiWiki::pagectime{$p}; + my $src = $pagesources{$p}; + my @date = localtime($mtime); + my $mday = $date[3]; + my $month = $date[4] + 1; + my $year = $date[5] + 1900; + my $mtag = sprintf("%02d", $month); + + # Only one posting per day is being linked to. + $linkcache{"$year/$mtag/$mday"} = "$src"; + } + my @list; my $calendar="\n"; @@ -99,21 +114,21 @@ sub format_month (@) { # Calculate URL's for monthly archives. my ($url, $purl, $nurl)=("$monthname",'',''); - if (exists $cache{$pagespec}{"$year/$month"}) { + if (exists $pagesources{"$archivebase/$year/$month"}) { $url = htmllink($params{page}, $params{destpage}, "$archivebase/$year/".sprintf("%02d", $month), linktext => " $monthname "); } add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month), deptype("presence")); - if (exists $cache{$pagespec}{"$pyear/$pmonth"}) { + if (exists $pagesources{"$archivebase/$pyear/$pmonth"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear/" . sprintf("%02d", $pmonth), linktext => " $pmonthname "); } add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth), deptype("presence")); - if (exists $cache{$pagespec}{"$nyear/$nmonth"}) { + if (exists $pagesources{"$archivebase/$nyear/$nmonth"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear/" . sprintf("%02d", $nmonth), linktext => " $nmonthname "); @@ -173,7 +188,7 @@ EOF my $tag; my $mtag = sprintf("%02d", $month); - if (defined $cache{$pagespec}{"$year/$mtag/$day"}) { + if (defined $pagesources{"$archivebase/$year/$mtag/$day"}) { if ($day == $today) { $tag='month-calendar-day-this-day'; } @@ -210,10 +225,6 @@ EOF EOF - # Add dependencies to update the calendar whenever pages - # matching the pagespec are added or removed. - add_depends($params{page}, $params{pages}, deptype("presence")); - return $calendar; } @@ -239,19 +250,19 @@ sub format_year (@) { # calculate URL's for previous and next years my ($url, $purl, $nurl)=("$year",'',''); - if (exists $cache{$pagespec}{"$year"}) { + if (exists $pagesources{"$archivebase/$year"}) { $url = htmllink($params{page}, $params{destpage}, "$archivebase/$year", linktext => "$year"); } - add_depends($params{page}, "$archivebase/$year", deptype("presence"); - if (exists $cache{$pagespec}{"$pyear"}) { + add_depends($params{page}, "$archivebase/$year", deptype("presence")); + if (exists $pagesources{"$archivebase/$pyear"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear", linktext => "\←"); } add_depends($params{page}, "$archivebase/$pyear", deptype("presence")); - if (exists $cache{$pagespec}{"$nyear"}) { + if (exists $pagesources{"$archivebase/$nyear"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear", linktext => "\→"); @@ -280,14 +291,14 @@ EOF my $tag; my $mtag=sprintf("%02d", $month); if ($month == $params{month}) { - if ($cache{$pagespec}{"$year/$mtag"}) { + if ($pagesources{"$archivebase/$year/$mtag"}) { $tag = 'this_month_link'; } else { $tag = 'this_month_nolink'; } } - elsif ($cache{$pagespec}{"$year/$mtag"}) { + elsif ($pagesources{"$archivebase/$year/$mtag"}) { $tag = 'month_link'; } elsif ($future_month && $month >= $future_month) { @@ -297,7 +308,7 @@ EOF $tag = 'month_nolink'; } - if ($cache{$pagespec}{"$year/$mtag"}) { + if ($pagesources{"$archivebase/$year/$mtag"}) { $murl = htmllink($params{page}, $params{destpage}, "$archivebase/$year/$mtag", linktext => "$monthabbr"); @@ -366,26 +377,6 @@ sub preprocess (@) { $params{nyear} =$nyear; my $calendar="\n"; - my $pagespec=$params{pages}; - my $page =$params{page}; - - if (! defined $cache{$pagespec}) { - foreach my $p (pagespec_match_list([keys %pagesources], $pagespec)) { - my $mtime = $IkiWiki::pagectime{$p}; - my $src = $pagesources{$p}; - my @date = localtime($mtime); - my $mday = $date[3]; - my $month = $date[4] + 1; - my $year = $date[5] + 1900; - my $mtag = sprintf("%02d", $month); - - # Only one posting per day is being linked to. - $linkcache{"$year/$mtag/$mday"} = "$src"; - $cache{$pagespec}{"$year"}++; - $cache{$pagespec}{"$year/$mtag"}++; - $cache{$pagespec}{"$year/$mtag/$mday"}++; - } - } if ($params{type} =~ /month/i) { $calendar=format_month(%params); -- cgit v1.2.3 From 5e7b2dea84a35163b599b88efc02cd7ef3e0ad46 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 8 Oct 2009 23:51:06 -0400 Subject: rename use_pagespec to pagespec_match_list To avoid breaking plugins, also support the old pagespec_match_list calling convention, with a deprecation warning. --- IkiWiki.pm | 183 ++++++++++++++++++---------------------- IkiWiki/Plugin/calendar.pm | 2 +- IkiWiki/Plugin/inline.pm | 8 +- IkiWiki/Plugin/map.pm | 3 +- IkiWiki/Plugin/orphans.pm | 2 +- IkiWiki/Plugin/pagecount.pm | 2 +- IkiWiki/Plugin/pagestats.pm | 9 +- IkiWiki/Plugin/postsparkline.pm | 2 +- debian/changelog | 6 +- doc/plugins/write.mdwn | 24 ++---- t/pagespec_match_list.t | 31 +++++++ t/use_pagespec.t | 31 ------- 12 files changed, 140 insertions(+), 163 deletions(-) create mode 100755 t/pagespec_match_list.t delete mode 100755 t/use_pagespec.t (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki.pm b/IkiWiki.pm index daa71059b..fd7e23524 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -17,7 +17,7 @@ use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase %forcerebuild %loaded_plugins}; use Exporter q{import}; -our @EXPORT = qw(hook debug error template htmlpage deptype use_pagespec +our @EXPORT = qw(hook debug error template htmlpage deptype add_depends pagespec_match pagespec_match_list bestlink htmllink readfile writefile pagetype srcfile pagename displaytime will_render gettext urlto targetpage @@ -1798,91 +1798,6 @@ sub add_depends ($$;$) { return 1; } -sub use_pagespec ($$;@) { - my $page=shift; - my $pagespec=shift; - my %params=@_; - - my $sub=pagespec_translate($pagespec); - error "syntax error in pagespec \"$pagespec\"" - if $@ || ! defined $sub; - - my @candidates; - if (exists $params{limit}) { - @candidates=grep { $params{limit}->($_) } keys %pagesources; - } - else { - @candidates=keys %pagesources; - } - - if (defined $params{sort}) { - my $f; - if ($params{sort} eq 'title') { - $f=sub { pagetitle(basename($a)) cmp pagetitle(basename($b)) }; - } - elsif ($params{sort} eq 'title_natural') { - eval q{use Sort::Naturally}; - if ($@) { - error(gettext("Sort::Naturally needed for title_natural sort")); - } - $f=sub { Sort::Naturally::ncmp(pagetitle(basename($a)), pagetitle(basename($b))) }; - } - elsif ($params{sort} eq 'mtime') { - $f=sub { $pagemtime{$b} <=> $pagemtime{$a} }; - } - elsif ($params{sort} eq 'age') { - $f=sub { $pagectime{$b} <=> $pagectime{$a} }; - } - else { - error sprintf(gettext("unknown sort type %s"), $params{sort}); - } - @candidates = sort { &$f } @candidates; - } - - @candidates=reverse(@candidates) if $params{reverse}; - - my @matches; - my $firstfail; - my $count=0; - foreach my $p (@candidates) { - my $r=$sub->($p, location => $page); - if ($r) { - push @matches, [$p, $r]; - last if defined $params{num} && ++$count == $params{num}; - } - elsif (! defined $firstfail) { - $firstfail=$r; - } - } - - $depends{$page}{$pagespec} |= ($params{deptype} || $DEPEND_CONTENT); - - my @ret; - if (@matches) { - # Add all influences from successful matches. - foreach my $m (@matches) { - push @ret, $m->[0]; - my %i=$m->[1]->influences; - foreach my $i (keys %i) { - $depends_simple{$page}{lc $i} |= $i{$i}; - } - } - } - elsif (defined $firstfail) { - # Add influences from one failure. (Which one should not - # matter; all should have the same influences.) - my %i=$firstfail->influences; - foreach my $i (keys %i) { - $depends_simple{$page}{lc $i} |= $i{$i}; - } - - error(sprintf(gettext("cannot match pages: %s"), $firstfail)) - if $firstfail->isa("IkiWiki::ErrorReason"); - } - - return @ret; -} - sub deptype (@) { my $deptype=0; foreach my $type (@_) { @@ -2055,27 +1970,95 @@ sub pagespec_match ($$;@) { } sub pagespec_match_list ($$;@) { - my $pages=shift; - my $spec=shift; - my @params=@_; + my $page=shift; + my $pagespec=shift; + my %params=@_; - my $sub=pagespec_translate($spec); - error "syntax error in pagespec \"$spec\"" + # Backwards compatability with old calling convention. + if (ref $page) { + print STDERR "warning: a plugin (".caller().") is using pagespec_match_list in an obsolete way, and needs to be updated\n"; + $params{list}=$page; + $page=$params{location}; # ugh! + } + + my $sub=pagespec_translate($pagespec); + error "syntax error in pagespec \"$pagespec\"" if $@ || ! defined $sub; + + my @candidates; + if (exists $params{limit}) { + @candidates=grep { $params{limit}->($_) } keys %pagesources; + } + else { + @candidates=keys %pagesources; + } + + if (defined $params{sort}) { + my $f; + if ($params{sort} eq 'title') { + $f=sub { pagetitle(basename($a)) cmp pagetitle(basename($b)) }; + } + elsif ($params{sort} eq 'title_natural') { + eval q{use Sort::Naturally}; + if ($@) { + error(gettext("Sort::Naturally needed for title_natural sort")); + } + $f=sub { Sort::Naturally::ncmp(pagetitle(basename($a)), pagetitle(basename($b))) }; + } + elsif ($params{sort} eq 'mtime') { + $f=sub { $pagemtime{$b} <=> $pagemtime{$a} }; + } + elsif ($params{sort} eq 'age') { + $f=sub { $pagectime{$b} <=> $pagectime{$a} }; + } + else { + error sprintf(gettext("unknown sort type %s"), $params{sort}); + } + @candidates = sort { &$f } @candidates; + } + + @candidates=reverse(@candidates) if $params{reverse}; - my @ret; - my $r; - foreach my $page (@$pages) { - $r=$sub->($page, @params); - push @ret, $page if $r; + my @matches; + my $firstfail; + my $count=0; + foreach my $p (@candidates) { + my $r=$sub->($p, location => $page); + if ($r) { + push @matches, [$p, $r]; + last if defined $params{num} && ++$count == $params{num}; + } + elsif (! defined $firstfail) { + $firstfail=$r; + } } + + $depends{$page}{$pagespec} |= ($params{deptype} || $DEPEND_CONTENT); - if (! @ret && defined $r && $r->isa("IkiWiki::ErrorReason")) { - error(sprintf(gettext("cannot match pages: %s"), $r)); + my @ret; + if (@matches) { + # Add all influences from successful matches. + foreach my $m (@matches) { + push @ret, $m->[0]; + my %i=$m->[1]->influences; + foreach my $i (keys %i) { + $depends_simple{$page}{lc $i} |= $i{$i}; + } + } } - else { - return @ret; + elsif (defined $firstfail) { + # Add influences from one failure. (Which one should not + # matter; all should have the same influences.) + my %i=$firstfail->influences; + foreach my $i (keys %i) { + $depends_simple{$page}{lc $i} |= $i{$i}; + } + + error(sprintf(gettext("cannot match pages: %s"), $firstfail)) + if $firstfail->isa("IkiWiki::ErrorReason"); } + + return @ret; } sub pagespec_valid ($) { diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index a89175cfb..c50d038df 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -74,7 +74,7 @@ sub format_month (@) { my $nyear = $params{nyear}; my %linkcache; - foreach my $p (use_pagespec($params{page}, $params{pagespec}, + foreach my $p (pagespec_match_list($params{page}, $params{pagespec}, # add presence dependencies to update # month calendar when pages are added/removed deptype => deptype("presence"))) { diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index c02137aed..815a37838 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -216,7 +216,7 @@ sub preprocess_inline (@) { $num+=$params{skip}; } - @list = use_pagespec($params{page}, $params{pages}, + @list = pagespec_match_list($params{page}, $params{pages}, deptype => deptype($quick ? "presence" : "content"), limit => sub { $_[0] ne $params{page} }, sort => exists $params{sort} ? $params{sort} : "age", @@ -245,9 +245,11 @@ sub preprocess_inline (@) { } if ($feeds && exists $params{feedpages}) { - @feedlist = use_pagespec($params{page}, "($params{pages}) and ($params{feedpages})", + @feedlist = pagespec_match_list( + $params{page}, "($params{pages}) and ($params{feedpages})", deptype => deptype($quick ? "presence" : "content"), - list => \@feedlist); + list => \@feedlist, + ); } my ($feedbase, $feednum); diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm index 634b0e4d6..788b96827 100644 --- a/IkiWiki/Plugin/map.pm +++ b/IkiWiki/Plugin/map.pm @@ -36,7 +36,8 @@ sub preprocess (@) { # Get all the items to map. my %mapitems; - foreach my $page (use_pagespec($params{page}, $params{pages}, deptype => $deptype)) { + foreach my $page (pagespec_match_list($params{page}, $params{pages}, + deptype => $deptype)) { if (exists $params{show} && exists $pagestate{$page} && exists $pagestate{$page}{meta}{$params{show}}) { diff --git a/IkiWiki/Plugin/orphans.pm b/IkiWiki/Plugin/orphans.pm index 607239500..b1ebd1b9d 100644 --- a/IkiWiki/Plugin/orphans.pm +++ b/IkiWiki/Plugin/orphans.pm @@ -28,7 +28,7 @@ sub preprocess (@) { # considering as orphans. add_depends($params{page}, "*", deptype("links")); - my @orphans=use_pagespec($params{page}, $params{pages}, + my @orphans=pagespec_match_list($params{page}, $params{pages}, # update when orphans are added/removed deptype => deptype("presence"), limit => sub { diff --git a/IkiWiki/Plugin/pagecount.pm b/IkiWiki/Plugin/pagecount.pm index 40474b2a1..8d36f057e 100644 --- a/IkiWiki/Plugin/pagecount.pm +++ b/IkiWiki/Plugin/pagecount.pm @@ -32,7 +32,7 @@ sub preprocess (@) { return scalar keys %pagesources; } - return scalar use_pagespec($params{page}, $pages, + return scalar pagespec_match_list($params{page}, $pages, deptype => deptype("presence")); } diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm index e64f7d9c3..47638210a 100644 --- a/IkiWiki/Plugin/pagestats.pm +++ b/IkiWiki/Plugin/pagestats.pm @@ -37,16 +37,17 @@ sub preprocess (@) { my %counts; my $max = 0; - foreach my $page (use_pagespec($params{page}, $params{pages}, - # update when a displayed page is added or removed - deptype => deptype("presence"))) { + foreach my $page (pagespec_match_list($params{page}, $params{pages}, + # update when a displayed page is added/removed + deptype => deptype("presence"))) { use IkiWiki::Render; my @backlinks = IkiWiki::backlink_pages($page); if (exists $params{among}) { # only consider backlinks from the amoung pages - @backlinks = use_pagespec($params{page}, $params{among}, + @backlinks = pagespec_match_list( + $params{page}, $params{among}, # update whenever links on those pages change deptype => deptype("links"), list => \@backlinks diff --git a/IkiWiki/Plugin/postsparkline.pm b/IkiWiki/Plugin/postsparkline.pm index f51e309c8..1d4532366 100644 --- a/IkiWiki/Plugin/postsparkline.pm +++ b/IkiWiki/Plugin/postsparkline.pm @@ -54,7 +54,7 @@ sub preprocess (@) { } my @list=sort { $params{timehash}->{$b} <=> $params{timehash}->{$a} } - use_pagespec($params{page}, $params{pages}, + pagespec_match_list($params{page}, $params{pages}, deptype => $deptype, limit => sub { $_[0] ne $params{page} }, ); diff --git a/debian/changelog b/debian/changelog index 3a6fdf77d..49809e6cf 100644 --- a/debian/changelog +++ b/debian/changelog @@ -33,9 +33,9 @@ ikiwiki (3.14159266) UNRELEASED; urgency=low info. * Plugins providing PageSpec `match_*` functions should pass additional influence information when creating result objects. - * Added `use_pagespec` function, that plugins can use to find a list - of matching pages and add dependencies and influences, all at once, - and efficiently. + * API change: `pagespec_match_list` has completly changed its interface. + The old interface will be removed soon, and a warning will be printed + if any plugins try to use it. * Optimize away most expensive file prune calls, when refreshing, by only checking new files. diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 62bebbeed..f6ea76c36 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -625,16 +625,16 @@ dependency type from one or more of these keywords: If multiple types are specified, they are combined. -#### `use_pagespec($$;@)` +#### `pagespec_match_list($$;@)` Passed a page name, and [[ikiwiki/PageSpec]], returns a list of pages in the wiki that match the [[ikiwiki/PageSpec]]. The page will automatically be made to depend on the specified [[ikiwiki/PageSpec]], so `add_depends` does not need to be called. This -is significantly more efficient than calling `add_depends` -followed by `pagespec_match_list`. You should use this anytime a plugin -needs to match a set of pages and generate something based on that list. +is significantly more efficient than calling `add_depends` and +`pagespec_match` in a loop. You should use this anytime a plugin +needs to match a set of pages and do something based on that list. Additional named parameters can be specified: @@ -650,6 +650,9 @@ Additional named parameters can be specified: * `list` makes it only match amoung the specified list of pages. Default is to match amoung all pages in the wiki. +Unlike pagespec_match, this may throw an error if there is an error in +the pagespec. + #### `add_depends($$;$)` Makes the specified page depend on the specified [[ikiwiki/PageSpec]]. @@ -672,19 +675,6 @@ The most often used is "location", which specifies the location the PageSpec should match against. If not passed, relative PageSpecs will match relative to the top of the wiki. -#### `pagespec_match_list($$;@)` - -Passed a reference to a list of page names, and [[ikiwiki/PageSpec]], -returns the set of pages that match the [[ikiwiki/PageSpec]]. - -Additional named parameters can be passed, to further limit the match. -The most often used is "location", which specifies the location the -PageSpec should match against. If not passed, relative PageSpecs will match -relative to the top of the wiki. - -Unlike pagespec_match, this may throw an error if there is an error in -the pagespec. - #### `bestlink($$)` Given a page and the text of a link on the page, determine which diff --git a/t/pagespec_match_list.t b/t/pagespec_match_list.t new file mode 100755 index 000000000..85a30b542 --- /dev/null +++ b/t/pagespec_match_list.t @@ -0,0 +1,31 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 10; + +BEGIN { use_ok("IkiWiki"); } + +%pagesources=( + foo => "foo.mdwn", + bar => "bar.mdwn", + "post/1" => "post/1.mdwn", + "post/2" => "post/2.mdwn", + "post/3" => "post/3.mdwn", +); + +is_deeply([pagespec_match_list("foo", "bar")], ["bar"]); +is_deeply([sort(pagespec_match_list("foo", "post/*"))], ["post/1", "post/2", "post/3"]); +is_deeply([pagespec_match_list("foo", "post/*", sort => "title", reverse => 1)], + ["post/3", "post/2", "post/1"]); +is_deeply([pagespec_match_list("foo", "post/*", sort => "title", num => 2)], + ["post/1", "post/2"]); +is_deeply([pagespec_match_list("foo", "post/*", sort => "title", num => 50)], + ["post/1", "post/2", "post/3"]); +is_deeply([pagespec_match_list("foo", "post/*", sort => "title", + limit => sub { $_[0] !~ /3/}) ], + ["post/1", "post/2"]); +my $r=eval { pagespec_match_list("foo", "beep") }; +ok(eval { pagespec_match_list("foo", "beep") } == 0); +ok(! $@, "does not fail with error when unable to match anything"); +eval { pagespec_match_list("foo", "this is not a legal pagespec!") }; +ok($@, "fails with error when pagespec bad"); diff --git a/t/use_pagespec.t b/t/use_pagespec.t deleted file mode 100755 index 92d7977cf..000000000 --- a/t/use_pagespec.t +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/perl -use warnings; -use strict; -use Test::More tests => 10; - -BEGIN { use_ok("IkiWiki"); } - -%pagesources=( - foo => "foo.mdwn", - bar => "bar.mdwn", - "post/1" => "post/1.mdwn", - "post/2" => "post/2.mdwn", - "post/3" => "post/3.mdwn", -); - -is_deeply([use_pagespec("foo", "bar")], ["bar"]); -is_deeply([sort(use_pagespec("foo", "post/*"))], ["post/1", "post/2", "post/3"]); -is_deeply([use_pagespec("foo", "post/*", sort => "title", reverse => 1)], - ["post/3", "post/2", "post/1"]); -is_deeply([use_pagespec("foo", "post/*", sort => "title", num => 2)], - ["post/1", "post/2"]); -is_deeply([use_pagespec("foo", "post/*", sort => "title", num => 50)], - ["post/1", "post/2", "post/3"]); -is_deeply([use_pagespec("foo", "post/*", sort => "title", - limit => sub { $_[0] !~ /3/}) ], - ["post/1", "post/2"]); -my $r=eval { use_pagespec("foo", "beep") }; -ok(eval { use_pagespec("foo", "beep") } == 0); -ok(! $@, "does not fail with error when unable to match anything"); -eval { use_pagespec("foo", "this is not a legal pagespec!") }; -ok($@, "fails with error when pagespec bad"); -- cgit v1.2.3 From 71e266b939d72871f7efbc9c498dc9b472bdf9eb Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 11 Oct 2009 20:15:54 -0400 Subject: avoid temporary variables and fix a bug in pagespec variable name --- IkiWiki/Plugin/calendar.pm | 118 ++++++++++++++++++--------------------------- 1 file changed, 48 insertions(+), 70 deletions(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index c50d038df..fe7ee0361 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -65,16 +65,8 @@ sub month_days { sub format_month (@) { my %params=@_; - my $pagespec = $params{pages}; - my $year = $params{year}; - my $month = $params{month}; - my $pmonth = $params{pmonth}; - my $nmonth = $params{nmonth}; - my $pyear = $params{pyear}; - my $nyear = $params{nyear}; - my %linkcache; - foreach my $p (pagespec_match_list($params{page}, $params{pagespec}, + foreach my $p (pagespec_match_list($params{page}, $params{pages}, # add presence dependencies to update # month calendar when pages are added/removed deptype => deptype("presence"))) { @@ -94,19 +86,19 @@ sub format_month (@) { my $calendar="\n"; # When did this month start? - my @monthstart = localtime(timelocal(0,0,0,1,$month-1,$year-1900)); + my @monthstart = localtime(timelocal(0,0,0,1,$params{month}-1,$params{year}-1900)); my $future_dom = 0; my $today = 0; - if ($year == $now[5]+1900 && $month == $now[4]+1) { + if ($params{year} == $now[5]+1900 && $params{month} == $now[4]+1) { $future_dom = $now[3]+1; $today = $now[3]; } # Find out month names for this, next, and previous months my $monthname=POSIX::strftime("%B", @monthstart); - my $pmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$pmonth-1,$pyear-1900))); - my $nmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$nmonth-1,$nyear-1900))); + my $pmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$params{pmonth}-1,$params{pyear}-1900))); + my $nmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$params{nmonth}-1,$params{nyear}-1900))); my $archivebase = 'archives'; $archivebase = $config{archivebase} if defined $config{archivebase}; @@ -114,26 +106,26 @@ sub format_month (@) { # Calculate URL's for monthly archives. my ($url, $purl, $nurl)=("$monthname",'',''); - if (exists $pagesources{"$archivebase/$year/$month"}) { + if (exists $pagesources{"$archivebase/$params{year}/$params{month}"}) { $url = htmllink($params{page}, $params{destpage}, - "$archivebase/$year/".sprintf("%02d", $month), + "$archivebase/$params{year}/".sprintf("%02d", $params{month}), linktext => " $monthname "); } - add_depends($params{page}, "$archivebase/$year/".sprintf("%02d", $month), + add_depends($params{page}, "$archivebase/$params{year}/".sprintf("%02d", $params{month}), deptype("presence")); - if (exists $pagesources{"$archivebase/$pyear/$pmonth"}) { + if (exists $pagesources{"$archivebase/$params{pyear}/$params{pmonth}"}) { $purl = htmllink($params{page}, $params{destpage}, - "$archivebase/$pyear/" . sprintf("%02d", $pmonth), + "$archivebase/$params{pyear}/" . sprintf("%02d", $params{pmonth}), linktext => " $pmonthname "); } - add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth), + add_depends($params{page}, "$archivebase/$params{pyear}/".sprintf("%02d", $params{pmonth}), deptype("presence")); - if (exists $pagesources{"$archivebase/$nyear/$nmonth"}) { + if (exists $pagesources{"$archivebase/$params{nyear}/$params{nmonth}"}) { $nurl = htmllink($params{page}, $params{destpage}, - "$archivebase/$nyear/" . sprintf("%02d", $nmonth), + "$archivebase/$params{nyear}/" . sprintf("%02d", $params{nmonth}), linktext => " $nmonthname "); } - add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth), + add_depends($params{page}, "$archivebase/$params{nyear}/".sprintf("%02d", $params{nmonth}), deptype("presence")); # Start producing the month calendar @@ -155,7 +147,7 @@ EOF my %downame; my %dowabbr; for my $dow ($week_start_day..$week_start_day+6) { - my @day=localtime(timelocal(0,0,0,$start_day++,$month-1,$year-1900)); + my @day=localtime(timelocal(0,0,0,$start_day++,$params{month}-1,$params{year}-1900)); my $downame = POSIX::strftime("%A", @day); my $dowabbr = POSIX::strftime("%a", @day); $downame{$dow % 7}=$downame; @@ -176,7 +168,7 @@ EOF # At this point, either the first is a week_start_day, in which case # nothing has been printed, or else we are in the middle of a row. - for (my $day = 1; $day <= month_days(year => $year, month => $month); + for (my $day = 1; $day <= month_days(year => $params{year}, month => $params{month}); $day++, $wday++, $wday %= 7) { # At tihs point, on a week_start_day, we close out a row, # and start a new one -- unless it is week_start_day on the @@ -187,8 +179,8 @@ EOF } my $tag; - my $mtag = sprintf("%02d", $month); - if (defined $pagesources{"$archivebase/$year/$mtag/$day"}) { + my $mtag = sprintf("%02d", $params{month}); + if (defined $pagesources{"$archivebase/$params{year}/$mtag/$day"}) { if ($day == $today) { $tag='month-calendar-day-this-day'; } @@ -197,9 +189,9 @@ EOF } $calendar.=qq{\t\t}; $calendar.=htmllink($params{page}, $params{destpage}, - pagename($linkcache{"$year/$mtag/$day"}), + pagename($linkcache{"$params{year}/$mtag/$day"}), "linktext" => "$day"); - push @list, pagename($linkcache{"$year/$mtag/$day"}); + push @list, pagename($linkcache{"$params{year}/$mtag/$day"}); $calendar.=qq{\n}; } else { @@ -231,43 +223,35 @@ EOF sub format_year (@) { my %params=@_; - my $pagespec = $params{pages}; - my $year = $params{year}; - my $month = $params{month}; - my $pmonth = $params{pmonth}; - my $nmonth = $params{nmonth}; - my $pyear = $params{pyear}; - my $nyear = $params{nyear}; - my $calendar="\n"; my $future_month = 0; - $future_month = $now[4]+1 if ($year == $now[5]+1900); + $future_month = $now[4]+1 if ($params{year} == $now[5]+1900); my $archivebase = 'archives'; $archivebase = $config{archivebase} if defined $config{archivebase}; $archivebase = $params{archivebase} if defined $params{archivebase}; # calculate URL's for previous and next years - my ($url, $purl, $nurl)=("$year",'',''); - if (exists $pagesources{"$archivebase/$year"}) { + my ($url, $purl, $nurl)=("$params{year}",'',''); + if (exists $pagesources{"$archivebase/$params{year}"}) { $url = htmllink($params{page}, $params{destpage}, - "$archivebase/$year", - linktext => "$year"); + "$archivebase/$params{year}", + linktext => "$params{year}"); } - add_depends($params{page}, "$archivebase/$year", deptype("presence")); - if (exists $pagesources{"$archivebase/$pyear"}) { + add_depends($params{page}, "$archivebase/$params{year}", deptype("presence")); + if (exists $pagesources{"$archivebase/$params{pyear}"}) { $purl = htmllink($params{page}, $params{destpage}, - "$archivebase/$pyear", + "$archivebase/$params{pyear}", linktext => "\←"); } - add_depends($params{page}, "$archivebase/$pyear", deptype("presence")); - if (exists $pagesources{"$archivebase/$nyear"}) { + add_depends($params{page}, "$archivebase/$params{pyear}", deptype("presence")); + if (exists $pagesources{"$archivebase/$params{nyear}"}) { $nurl = htmllink($params{page}, $params{destpage}, - "$archivebase/$nyear", + "$archivebase/$params{nyear}", linktext => "\→"); } - add_depends($params{page}, "$archivebase/$nyear", deptype("presence")); + add_depends($params{page}, "$archivebase/$params{nyear}", deptype("presence")); # Start producing the year calendar $calendar=< EOF - for ($month = 1; $month <= 12; $month++) { - my @day=localtime(timelocal(0,0,0,15,$month-1,$year-1900)); + for (my $month = 1; $month <= 12; $month++) { + my @day=localtime(timelocal(0,0,0,15,$month-1,$params{year}-1900)); my $murl; my $monthname = POSIX::strftime("%B", @day); my $monthabbr = POSIX::strftime("%b", @day); @@ -291,14 +275,14 @@ EOF my $tag; my $mtag=sprintf("%02d", $month); if ($month == $params{month}) { - if ($pagesources{"$archivebase/$year/$mtag"}) { + if ($pagesources{"$archivebase/$params{year}/$mtag"}) { $tag = 'this_month_link'; } else { $tag = 'this_month_nolink'; } } - elsif ($pagesources{"$archivebase/$year/$mtag"}) { + elsif ($pagesources{"$archivebase/$params{year}/$mtag"}) { $tag = 'month_link'; } elsif ($future_month && $month >= $future_month) { @@ -308,9 +292,9 @@ EOF $tag = 'month_nolink'; } - if ($pagesources{"$archivebase/$year/$mtag"}) { + if ($pagesources{"$archivebase/$params{year}/$mtag"}) { $murl = htmllink($params{page}, $params{destpage}, - "$archivebase/$year/$mtag", + "$archivebase/$params{year}/$mtag", linktext => "$monthabbr"); $calendar.=qq{\t}; $calendar.=$murl; @@ -319,7 +303,7 @@ EOF else { $calendar.=qq{\t$monthabbr\n}; } - add_depends($params{page}, "$archivebase/$year/$mtag", + add_depends($params{page}, "$archivebase/$params{year}/$mtag", deptype("presence")); $calendar.=qq{\t\n} if ($month % $params{months_per_row} == 0); @@ -356,28 +340,22 @@ sub preprocess (@) { } # Calculate month names for next month, and previous months - my $pmonth = $params{month} - 1; - my $nmonth = $params{month} + 1; - my $pyear = $params{year} - 1; - my $nyear = $params{year} + 1; + $params{pmonth} = $params{month} - 1; + $params{nmonth} = $params{month} + 1; + $params{pyear} = $params{year} - 1; + $params{nyear} = $params{year} + 1; # Adjust for January and December if ($params{month} == 1) { - $pmonth = 12; - $pyear--; + $params{pmonth} = 12; + $params{pyear}--; } if ($params{month} == 12) { - $nmonth = 1; - $nyear++; + $params{nmonth} = 1; + $params{nyear}++; } - $params{pmonth}=$pmonth; - $params{nmonth}=$nmonth; - $params{pyear} =$pyear; - $params{nyear} =$nyear; - - my $calendar="\n"; - + my $calendar=""; if ($params{type} =~ /month/i) { $calendar=format_month(%params); } -- cgit v1.2.3 From dd80be66ee7d9a28e788efcc1b3eb62bbe8611dd Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 11 Oct 2009 21:06:10 -0400 Subject: calendar: Fix midnight rebuild trigger of calendars with explicit month/year. It was just broken for calendars with an explicit month or year, not triggering at all. Now it will update those at appropriate times. --- IkiWiki/Plugin/calendar.pm | 42 +++++++++++++++++++++++++++++++++--------- debian/changelog | 2 ++ 2 files changed, 35 insertions(+), 9 deletions(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index fe7ee0361..9cbfd769d 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -318,24 +318,48 @@ EOF sub preprocess (@) { my %params=@_; + + my $thisyear=1900 + $now[5]; + my $thismonth=1 + $now[4]; + $params{pages} = "*" unless defined $params{pages}; $params{type} = "month" unless defined $params{type}; - $params{month} = sprintf("%02d", $params{month}) if defined $params{month}; $params{week_start_day} = 0 unless defined $params{week_start_day}; $params{months_per_row} = 3 unless defined $params{months_per_row}; - - if (! defined $params{year} || ! defined $params{month}) { - # Record that the calendar next changes at midnight. + $params{year} = $thisyear unless defined $params{year}; + $params{month} = $thismonth unless defined $params{month}; + + $params{month} = sprintf("%02d", $params{month}); + + if ($params{type} eq 'month' && $params{year} == $thisyear + && $params{month} == $thismonth) { + # calendar for current month, updates next midnight $pagestate{$params{destpage}}{calendar}{nextchange}=($time + (60 - $now[0]) # seconds + (59 - $now[1]) * 60 # minutes + (23 - $now[2]) * 60 * 60 # hours ); - - $params{year} = 1900 + $now[5] unless defined $params{year}; - $params{month} = 1 + $now[4] unless defined $params{month}; + } + elsif ($params{type} eq 'month' && + (($params{year} == $thisyear && $params{month} > $thismonth) || + $params{year} > $thisyear)) { + # calendar for upcoming month, updates 1st of that month + $pagestate{$params{destpage}}{calendar}{nextchange}= + timelocal(0, 0, 0, 1, $params{month}-1, $params{year}); + } + elsif ($params{type} eq 'year' && $params{year} == $thisyear) { + # calendar for current year, updates 1st of next month + $pagestate{$params{destpage}}{calendar}{nextchange}= + timelocal(0, 0, 0, 1, $thismonth+1-1, $params{year}); + } + elsif ($params{type} eq 'year' && $params{year} > $thisyear) { + # calendar for upcoming year, updates 1st of that year + $pagestate{$params{destpage}}{calendar}{nextchange}= + timelocal(0, 0, 0, 1, 1-1, $params{year}); } else { + # calendar for past month or year, does not need + # to update any more delete $pagestate{$params{destpage}}{calendar}; } @@ -356,10 +380,10 @@ sub preprocess (@) { } my $calendar=""; - if ($params{type} =~ /month/i) { + if ($params{type} eq 'month') { $calendar=format_month(%params); } - elsif ($params{type} =~ /year/i) { + elsif ($params{type} eq 'year') { $calendar=format_year(%params); } diff --git a/debian/changelog b/debian/changelog index 0e288dd08..c64758a77 100644 --- a/debian/changelog +++ b/debian/changelog @@ -28,6 +28,8 @@ ikiwiki (3.2009XXXX) UNRELEASED; urgency=low * Transitive dependencies are now correctly supported. * ikiwiki-calendar: New command automates creation of archive pages using the calendar plugin. + * calendar: Fix midnight rebuild trigger of calendars with explicit + month/year. -- Joey Hess Fri, 09 Oct 2009 19:53:50 -0400 -- cgit v1.2.3 From f3342773d3a6c9da11c248c4cc385dca284add06 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 11 Oct 2009 21:42:59 -0400 Subject: calendar: Fix bug in next/previous year/month links, which sometimes linked to an archive page from the wrong year. --- IkiWiki/Plugin/calendar.pm | 63 ++++++++++++++++++++++++---------------------- debian/changelog | 2 ++ 2 files changed, 35 insertions(+), 30 deletions(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index 9cbfd769d..5b4bfac89 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -81,6 +81,21 @@ sub format_month (@) { # Only one posting per day is being linked to. $linkcache{"$year/$mtag/$mday"} = "$src"; } + + my $pmonth = $params{month} - 1; + my $nmonth = $params{month} + 1; + my $pyear = $params{year}; + my $nyear = $params{year}; + + # Adjust for January and December + if ($params{month} == 1) { + $pmonth = 12; + $pyear--; + } + if ($params{month} == 12) { + $nmonth = 1; + $nyear++; + } my @list; my $calendar="\n"; @@ -97,8 +112,8 @@ sub format_month (@) { # Find out month names for this, next, and previous months my $monthname=POSIX::strftime("%B", @monthstart); - my $pmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$params{pmonth}-1,$params{pyear}-1900))); - my $nmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$params{nmonth}-1,$params{nyear}-1900))); + my $pmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$pmonth-1,$pyear-1900))); + my $nmonthname=POSIX::strftime("%B", localtime(timelocal(0,0,0,1,$nmonth-1,$nyear-1900))); my $archivebase = 'archives'; $archivebase = $config{archivebase} if defined $config{archivebase}; @@ -113,19 +128,19 @@ sub format_month (@) { } add_depends($params{page}, "$archivebase/$params{year}/".sprintf("%02d", $params{month}), deptype("presence")); - if (exists $pagesources{"$archivebase/$params{pyear}/$params{pmonth}"}) { + if (exists $pagesources{"$archivebase/$pyear/$pmonth"}) { $purl = htmllink($params{page}, $params{destpage}, - "$archivebase/$params{pyear}/" . sprintf("%02d", $params{pmonth}), + "$archivebase/$pyear/" . sprintf("%02d", $pmonth), linktext => " $pmonthname "); } - add_depends($params{page}, "$archivebase/$params{pyear}/".sprintf("%02d", $params{pmonth}), + add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth), deptype("presence")); - if (exists $pagesources{"$archivebase/$params{nyear}/$params{nmonth}"}) { + if (exists $pagesources{"$archivebase/$nyear/$nmonth"}) { $nurl = htmllink($params{page}, $params{destpage}, - "$archivebase/$params{nyear}/" . sprintf("%02d", $params{nmonth}), + "$archivebase/$nyear/" . sprintf("%02d", $nmonth), linktext => " $nmonthname "); } - add_depends($params{page}, "$archivebase/$params{nyear}/".sprintf("%02d", $params{nmonth}), + add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth), deptype("presence")); # Start producing the month calendar @@ -222,8 +237,11 @@ EOF sub format_year (@) { my %params=@_; - + my $calendar="\n"; + + my $pyear = $params{year} - 1; + my $nyear = $params{year} + 1; my $future_month = 0; $future_month = $now[4]+1 if ($params{year} == $now[5]+1900); @@ -240,18 +258,18 @@ sub format_year (@) { linktext => "$params{year}"); } add_depends($params{page}, "$archivebase/$params{year}", deptype("presence")); - if (exists $pagesources{"$archivebase/$params{pyear}"}) { + if (exists $pagesources{"$archivebase/$pyear"}) { $purl = htmllink($params{page}, $params{destpage}, - "$archivebase/$params{pyear}", + "$archivebase/$pyear", linktext => "\←"); } - add_depends($params{page}, "$archivebase/$params{pyear}", deptype("presence")); - if (exists $pagesources{"$archivebase/$params{nyear}"}) { + add_depends($params{page}, "$archivebase/$pyear", deptype("presence")); + if (exists $pagesources{"$archivebase/$nyear"}) { $nurl = htmllink($params{page}, $params{destpage}, - "$archivebase/$params{nyear}", + "$archivebase/$nyear", linktext => "\→"); } - add_depends($params{page}, "$archivebase/$params{nyear}", deptype("presence")); + add_depends($params{page}, "$archivebase/$nyear", deptype("presence")); # Start producing the year calendar $calendar=< Fri, 09 Oct 2009 19:53:50 -0400 -- cgit v1.2.3 From 8a37be35acb2c2c37d272489d2f2678e47c61834 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 11 Oct 2009 21:43:16 -0400 Subject: fix day links I broke this recently. --- IkiWiki/Plugin/calendar.pm | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index 5b4bfac89..0266612ae 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -71,7 +71,6 @@ sub format_month (@) { # month calendar when pages are added/removed deptype => deptype("presence"))) { my $mtime = $IkiWiki::pagectime{$p}; - my $src = $pagesources{$p}; my @date = localtime($mtime); my $mday = $date[3]; my $month = $date[4] + 1; @@ -79,7 +78,7 @@ sub format_month (@) { my $mtag = sprintf("%02d", $month); # Only one posting per day is being linked to. - $linkcache{"$year/$mtag/$mday"} = "$src"; + $linkcache{"$year/$mtag/$mday"} = $p; } my $pmonth = $params{month} - 1; @@ -97,7 +96,6 @@ sub format_month (@) { $nyear++; } - my @list; my $calendar="\n"; # When did this month start? @@ -195,7 +193,7 @@ EOF my $tag; my $mtag = sprintf("%02d", $params{month}); - if (defined $pagesources{"$archivebase/$params{year}/$mtag/$day"}) { + if (defined $linkcache{"$params{year}/$mtag/$day"}) { if ($day == $today) { $tag='month-calendar-day-this-day'; } @@ -204,9 +202,8 @@ EOF } $calendar.=qq{\t\t}; $calendar.=htmllink($params{page}, $params{destpage}, - pagename($linkcache{"$params{year}/$mtag/$day"}), + $linkcache{"$params{year}/$mtag/$day"}, "linktext" => "$day"); - push @list, pagename($linkcache{"$params{year}/$mtag/$day"}); $calendar.=qq{\n}; } else { -- cgit v1.2.3 From 23a21850faf1cbb4bd8547b11563c5806617cf7e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 11 Oct 2009 21:52:50 -0400 Subject: fix next/prev month padding bug --- IkiWiki/Plugin/calendar.pm | 21 ++++++++++++--------- debian/changelog | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index 0266612ae..cf133e8dc 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -96,6 +96,10 @@ sub format_month (@) { $nyear++; } + # Add padding. + $pmonth=sprintf("%02d", $pmonth); + $nmonth=sprintf("%02d", $nmonth); + my $calendar="\n"; # When did this month start? @@ -121,24 +125,24 @@ sub format_month (@) { my ($url, $purl, $nurl)=("$monthname",'',''); if (exists $pagesources{"$archivebase/$params{year}/$params{month}"}) { $url = htmllink($params{page}, $params{destpage}, - "$archivebase/$params{year}/".sprintf("%02d", $params{month}), + "$archivebase/$params{year}/".$params{month}, linktext => " $monthname "); } - add_depends($params{page}, "$archivebase/$params{year}/".sprintf("%02d", $params{month}), + add_depends($params{page}, "$archivebase/$params{year}/$params{month}", deptype("presence")); if (exists $pagesources{"$archivebase/$pyear/$pmonth"}) { $purl = htmllink($params{page}, $params{destpage}, - "$archivebase/$pyear/" . sprintf("%02d", $pmonth), + "$archivebase/$pyear/$pmonth", linktext => " $pmonthname "); } - add_depends($params{page}, "$archivebase/$pyear/".sprintf("%02d", $pmonth), + add_depends($params{page}, "$archivebase/$pyear/$pmonth", deptype("presence")); if (exists $pagesources{"$archivebase/$nyear/$nmonth"}) { $nurl = htmllink($params{page}, $params{destpage}, - "$archivebase/$nyear/" . sprintf("%02d", $nmonth), + "$archivebase/$nyear/$nmonth", linktext => " $nmonthname "); } - add_depends($params{page}, "$archivebase/$nyear/".sprintf("%02d", $nmonth), + add_depends($params{page}, "$archivebase/$nyear/$nmonth", deptype("presence")); # Start producing the month calendar @@ -192,8 +196,7 @@ EOF } my $tag; - my $mtag = sprintf("%02d", $params{month}); - if (defined $linkcache{"$params{year}/$mtag/$day"}) { + if (defined $linkcache{"$params{year}/$params{month}/$day"}) { if ($day == $today) { $tag='month-calendar-day-this-day'; } @@ -202,7 +205,7 @@ EOF } $calendar.=qq{\t\t}; $calendar.=htmllink($params{page}, $params{destpage}, - $linkcache{"$params{year}/$mtag/$day"}, + $linkcache{"$params{year}/$params{month}/$day"}, "linktext" => "$day"); $calendar.=qq{\n}; } diff --git a/debian/changelog b/debian/changelog index 8881c48aa..5c47b2524 100644 --- a/debian/changelog +++ b/debian/changelog @@ -31,7 +31,7 @@ ikiwiki (3.2009XXXX) UNRELEASED; urgency=low * calendar: Fix midnight rebuild trigger of calendars with explicit month/year. * calendar: Fix bug in next/previous year/month links, which sometimes - linked to an archive page from the wrong year. + linked to an archive page from the wrong year, or were missing. -- Joey Hess Fri, 09 Oct 2009 19:53:50 -0400 -- cgit v1.2.3 From cf74cf7a37a1fa4e02dffc6f3ac580626d183433 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 11 Oct 2009 21:55:06 -0400 Subject: calendar: use left and right arrows for next/prev months This is consistent with the year display, and I think it is less visually confusing than using the full month names. --- IkiWiki/Plugin/calendar.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index cf133e8dc..dcf2b6d64 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -133,14 +133,14 @@ sub format_month (@) { if (exists $pagesources{"$archivebase/$pyear/$pmonth"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear/$pmonth", - linktext => " $pmonthname "); + linktext => " \&larr "); } add_depends($params{page}, "$archivebase/$pyear/$pmonth", deptype("presence")); if (exists $pagesources{"$archivebase/$nyear/$nmonth"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear/$nmonth", - linktext => " $nmonthname "); + linktext => " \&rarr "); } add_depends($params{page}, "$archivebase/$nyear/$nmonth", deptype("presence")); -- cgit v1.2.3 From e4c765c64fc31ab13c911b716e80b07b4d1a0037 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 11 Oct 2009 22:11:11 -0400 Subject: calendar: avoid inline images in links --- IkiWiki/Plugin/calendar.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index dcf2b6d64..e3c5e2f2d 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -126,6 +126,7 @@ sub format_month (@) { if (exists $pagesources{"$archivebase/$params{year}/$params{month}"}) { $url = htmllink($params{page}, $params{destpage}, "$archivebase/$params{year}/".$params{month}, + noimageinline => 1, linktext => " $monthname "); } add_depends($params{page}, "$archivebase/$params{year}/$params{month}", @@ -133,6 +134,7 @@ sub format_month (@) { if (exists $pagesources{"$archivebase/$pyear/$pmonth"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear/$pmonth", + noimageinline => 1, linktext => " \&larr "); } add_depends($params{page}, "$archivebase/$pyear/$pmonth", @@ -140,6 +142,7 @@ sub format_month (@) { if (exists $pagesources{"$archivebase/$nyear/$nmonth"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear/$nmonth", + noimageinline => 1, linktext => " \&rarr "); } add_depends($params{page}, "$archivebase/$nyear/$nmonth", @@ -205,8 +208,9 @@ EOF } $calendar.=qq{\t\t}; $calendar.=htmllink($params{page}, $params{destpage}, - $linkcache{"$params{year}/$params{month}/$day"}, - "linktext" => "$day"); + $linkcache{"$params{year}/$params{month}/$day"}, + noimageinline => 1, + "linktext" => "$day"); $calendar.=qq{\n}; } else { @@ -255,18 +259,21 @@ sub format_year (@) { if (exists $pagesources{"$archivebase/$params{year}"}) { $url = htmllink($params{page}, $params{destpage}, "$archivebase/$params{year}", + noimageinline => 1, linktext => "$params{year}"); } add_depends($params{page}, "$archivebase/$params{year}", deptype("presence")); if (exists $pagesources{"$archivebase/$pyear"}) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear", + noimageinline => 1, linktext => "\←"); } add_depends($params{page}, "$archivebase/$pyear", deptype("presence")); if (exists $pagesources{"$archivebase/$nyear"}) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear", + noimageinline => 1, linktext => "\→"); } add_depends($params{page}, "$archivebase/$nyear", deptype("presence")); @@ -313,6 +320,7 @@ EOF if ($pagesources{"$archivebase/$params{year}/$mtag"}) { $murl = htmllink($params{page}, $params{destpage}, "$archivebase/$params{year}/$mtag", + noimageinline => 1, linktext => "$monthabbr"); $calendar.=qq{\t}; $calendar.=$murl; -- cgit v1.2.3 From 11e6d650eae4377485cb83f61a0ce9519ceb4c57 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 12 Oct 2009 12:19:42 -0400 Subject: calendar: Fix CSS for year calendar to match the plugin documentation. The names in the documentation were completly different, but also seemed better chosen than the names in the code. --- IkiWiki/Plugin/calendar.pm | 13 ++++--------- debian/changelog | 1 + 2 files changed, 5 insertions(+), 9 deletions(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index e3c5e2f2d..71c671d67 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -300,21 +300,16 @@ EOF my $tag; my $mtag=sprintf("%02d", $month); if ($month == $params{month}) { - if ($pagesources{"$archivebase/$params{year}/$mtag"}) { - $tag = 'this_month_link'; - } - else { - $tag = 'this_month_nolink'; - } + $tag = 'year-calendar-this-month'; } elsif ($pagesources{"$archivebase/$params{year}/$mtag"}) { - $tag = 'month_link'; + $tag = 'year-calendar-month-link'; } elsif ($future_month && $month >= $future_month) { - $tag = 'month_future'; + $tag = 'year-calendar-month-future'; } else { - $tag = 'month_nolink'; + $tag = 'year-calendar-month-nolink'; } if ($pagesources{"$archivebase/$params{year}/$mtag"}) { diff --git a/debian/changelog b/debian/changelog index e9f09a8c6..b9d1923cd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -34,6 +34,7 @@ ikiwiki (3.2009XXXX) UNRELEASED; urgency=low linked to an archive page from the wrong year, or were missing. * git: --getctime will now follow renames back to the original creation of a file. + * calendar: Fix CSS for year calendar to match the plugin documentation. -- Joey Hess Fri, 09 Oct 2009 19:53:50 -0400 -- cgit v1.2.3 From 227540fd875bfaa6b810c0d7caa346f32d5bd7ce Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 12 Oct 2009 12:30:10 -0400 Subject: calendar: Add creation time limits to user's pagespec This avoids all calendars rebuilding when a new page is added that will only show in one of them. --- IkiWiki/Plugin/calendar.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index 71c671d67..5aac95884 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -66,7 +66,8 @@ sub format_month (@) { my %params=@_; my %linkcache; - foreach my $p (pagespec_match_list($params{page}, $params{pages}, + foreach my $p (pagespec_match_list($params{page}, + "creation_year($params{year}) and creation_month($params{month}) and ($params{pages})", # add presence dependencies to update # month calendar when pages are added/removed deptype => deptype("presence"))) { -- cgit v1.2.3 From 22737e53f1b0367bc9bfb8d7bcbfc4dcc08a81ae Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 12 Oct 2009 14:05:56 -0400 Subject: remove whitespace from within arrow links --- IkiWiki/Plugin/calendar.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index 5aac95884..d5a80795a 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -136,7 +136,7 @@ sub format_month (@) { $purl = htmllink($params{page}, $params{destpage}, "$archivebase/$pyear/$pmonth", noimageinline => 1, - linktext => " \&larr "); + linktext => "\&larr"); } add_depends($params{page}, "$archivebase/$pyear/$pmonth", deptype("presence")); @@ -144,7 +144,7 @@ sub format_month (@) { $nurl = htmllink($params{page}, $params{destpage}, "$archivebase/$nyear/$nmonth", noimageinline => 1, - linktext => " \&rarr "); + linktext => "\&rarr"); } add_depends($params{page}, "$archivebase/$nyear/$nmonth", deptype("presence")); -- cgit v1.2.3 From 5c78192435210cdb7792ed56b04c2ef24a2d2127 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 12 Oct 2009 14:19:04 -0400 Subject: year calendar: only link to months that have posts 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 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index d5a80795a..ddcd1a823 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -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, -- cgit v1.2.3 From 28c4caea59543b6d8fd0c62ff5a60aff67a9bba7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 12 Oct 2009 14:22:48 -0400 Subject: year calendar: Avoid highlighting the current month in a different year --- IkiWiki/Plugin/calendar.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'IkiWiki/Plugin/calendar.pm') diff --git a/IkiWiki/Plugin/calendar.pm b/IkiWiki/Plugin/calendar.pm index ddcd1a823..c9bdf4a17 100644 --- a/IkiWiki/Plugin/calendar.pm +++ b/IkiWiki/Plugin/calendar.pm @@ -262,8 +262,9 @@ sub format_year (@) { my $pyear = $params{year} - 1; my $nyear = $params{year} + 1; + my $thisyear = $now[5]+1900; my $future_month = 0; - $future_month = $now[4]+1 if ($params{year} == $now[5]+1900); + $future_month = $now[4]+1 if $params{year} == $thisyear; my $archivebase = 'archives'; $archivebase = $config{archivebase} if defined $config{archivebase}; @@ -314,7 +315,7 @@ EOF $calendar.=qq{\t\n} if ($month % $params{months_per_row} == 1); my $tag; my $mtag=sprintf("%02d", $month); - if ($month == $params{month}) { + if ($month == $params{month} && $thisyear == $params{year}) { $tag = 'year-calendar-this-month'; } elsif ($pagesources{"$archivebase/$params{year}/$mtag"}) { -- cgit v1.2.3