* Added created_before and created_after PageSpec limits.

master
joey 2006-08-03 16:55:52 +00:00
parent 14d107ee6b
commit 1253db7de2
4 changed files with 47 additions and 10 deletions

View File

@ -553,7 +553,7 @@ sub pagespec_translate ($) { #{{{
elsif ($word eq "(" || $word eq ")" || $word eq "!") { elsif ($word eq "(" || $word eq ")" || $word eq "!") {
$code.=" ".$word; $code.=" ".$word;
} }
elsif ($word =~ /^(link|backlink|creation_month|creation_year|creation_day)\((.+)\)$/) { elsif ($word =~ /^(link|backlink|created_before|created_after|creation_month|creation_year|creation_day)\((.+)\)$/) {
$code.=" match_$1(\$page, ".safequote($2).")"; $code.=" match_$1(\$page, ".safequote($2).")";
} }
else { else {
@ -598,6 +598,30 @@ sub match_backlink ($$) { #{{{
match_link(pop, pop); match_link(pop, pop);
} #}}} } #}}}
sub match_created_before ($$) { #{{{
my $page=shift;
my $testpage=shift;
if (exists $pagectime{$testpage}) {
return $pagectime{$page} < $pagectime{$testpage};
}
else {
return 0;
}
} #}}}
sub match_created_after ($$) { #{{{
my $page=shift;
my $testpage=shift;
if (exists $pagectime{$testpage}) {
return $pagectime{$page} > $pagectime{$testpage};
}
else {
return 0;
}
} #}}}
sub match_creation_day ($$) { #{{{ sub match_creation_day ($$) { #{{{
return ((gmtime($pagectime{shift()}))[3] == shift); return ((gmtime($pagectime{shift()}))[3] == shift);
} #}}} } #}}}

View File

@ -21,16 +21,23 @@ match all pages except for Discussion pages and the SandBox:
* and !SandBox and !*/Discussion * and !SandBox and !*/Discussion
It's also possible to match pages that link to a given page, by writing Some more elaborate limits can be added to what matches using any of these
"`link(page)`". Or, match pages that a given page links to, by functions:
writing "`backlink(page)`". Or match pages created in a given month, year,
or day of the month by writing "`creation_month(month)`", * "`link(page)`" - match only pages that link to a given page
"`creation_year(year)`" or "`creation_day(mday)`". * "`backlink(page)`" - match only pages that a given page links to
* "`creation_month(month)`" - match only pages created on the given month
* "`creation_day(mday)`" - or day of the month
* "`creation_year(year)`" - or year
* "`created_after(page)`" - match only pages created after the given page
was created
* "`created_before(page)`" - match only pages created before the given page
was created
For example, to match all pages in a blog that link to the page about music For example, to match all pages in a blog that link to the page about music
and were written on Mondays in 2005: and were written in 2005:
blog/* and link(music) and creation_year(2005) and creation_day(0) blog/* and link(music) and creation_year(2005)
More complex expressions can also be created, by using parentheses for More complex expressions can also be created, by using parentheses for
grouping. For example, to match pages in a blog that are tagged with either grouping. For example, to match pages in a blog that are tagged with either

3
debian/changelog vendored
View File

@ -2,8 +2,9 @@ ikiwiki (1.15) UNRELEASED; urgency=low
* Remove CDPATH and other env vars perl taint checking doesn't like. * Remove CDPATH and other env vars perl taint checking doesn't like.
Closes: #381279 Closes: #381279
* Added created_before and created_after PageSpec limits.
-- Joey Hess <joeyh@debian.org> Thu, 3 Aug 2006 12:12:53 -0400 -- Joey Hess <joeyh@debian.org> Thu, 3 Aug 2006 12:52:51 -0400
ikiwiki (1.14) unstable; urgency=low ikiwiki (1.14) unstable; urgency=low

View File

@ -1,7 +1,7 @@
#!/usr/bin/perl #!/usr/bin/perl
use warnings; use warnings;
use strict; use strict;
use Test::More tests => 31; use Test::More tests => 35;
BEGIN { use_ok("IkiWiki"); } BEGIN { use_ok("IkiWiki"); }
@ -26,6 +26,11 @@ ok(IkiWiki::pagespec_match("bar", "backlink(foo)"));
ok(! IkiWiki::pagespec_match("quux", "backlink(foo)")); ok(! IkiWiki::pagespec_match("quux", "backlink(foo)"));
$IkiWiki::pagectime{foo}=1154532692; # Wed Aug 2 11:26 EDT 2006 $IkiWiki::pagectime{foo}=1154532692; # Wed Aug 2 11:26 EDT 2006
$IkiWiki::pagectime{bar}=1154532695; # after
ok(IkiWiki::pagespec_match("foo", "created_before(bar)"));
ok(! IkiWiki::pagespec_match("foo", "created_after(bar)"));
ok(! IkiWiki::pagespec_match("bar", "created_before(foo)"));
ok(IkiWiki::pagespec_match("bar", "created_after(foo)"));
ok(IkiWiki::pagespec_match("foo", "creation_year(2006)"), "year"); ok(IkiWiki::pagespec_match("foo", "creation_year(2006)"), "year");
ok(! IkiWiki::pagespec_match("foo", "creation_year(2005)"), "other year"); ok(! IkiWiki::pagespec_match("foo", "creation_year(2005)"), "other year");
ok(IkiWiki::pagespec_match("foo", "creation_month(8)"), "month"); ok(IkiWiki::pagespec_match("foo", "creation_month(8)"), "month");