]> sipb.mit.edu Git - ikiwiki.git/commitdiff
Add page() PageSpec, which is like glob() but matches only pages, not other files.
authorJoey Hess <joey@kitenet.net>
Mon, 26 Apr 2010 22:47:17 +0000 (18:47 -0400)
committerJoey Hess <joey@kitenet.net>
Mon, 26 Apr 2010 22:47:17 +0000 (18:47 -0400)
IkiWiki.pm
debian/changelog
doc/ikiwiki/pagespec.mdwn
t/pagespec_match.t

index 944001d9b43fd64e436a5e23d6668fa79220f7ec..623396c9c4180929613a3b9ccbcdb139e923ebf6 100644 (file)
@@ -2299,7 +2299,11 @@ sub match_glob ($$;@) {
 
        my $regexp=IkiWiki::glob2re($glob);
        if ($page=~/^$regexp$/i) {
-               if (! IkiWiki::isinternal($page) || $params{internal}) {
+               if ($params{onlypage} &&
+                   ! defined IkiWiki::pagetype($IkiWiki::pagesources{$page})) {
+                       return IkiWiki::FailReason->new("$page is not a page");
+               }
+               elsif (! IkiWiki::isinternal($page) || $params{internal}) {
                        return IkiWiki::SuccessReason->new("$glob matches $page");
                }
                else {
@@ -2315,6 +2319,10 @@ sub match_internal ($$;@) {
        return match_glob($_[0], $_[1], @_, internal => 1)
 }
 
+sub match_page ($$;@) {
+       return match_glob($_[0], $_[1], @_, onlypage => 1)
+}
+
 sub match_link ($$;@) {
        my $page=shift;
        my $link=lc(shift);
index 1229b119845e9c832c240b888da3657afd315515..610d0c9cbe8e38827f76d9773c14092454b20d2c 100644 (file)
@@ -75,6 +75,8 @@ ikiwiki (3.20100424) UNRELEASED; urgency=low
     the top of the web root. This is another things that requires a wiki
     rebuild on upgrade to this version.
   * Fix removal of rendered files in rebuild mode.
+  * Add page() PageSpec, which is like glob() but matches only pages, 
+    not other files.
 
  -- Joey Hess <joeyh@debian.org>  Sun, 04 Apr 2010 12:17:11 -0400
 
index 7810e790b4eb37bd1462f97ba39cf3e8a90b9f3d..1c99aefac9f1230bb5ca0707201d7ac049ac21a9 100644 (file)
@@ -24,19 +24,20 @@ match all pages except for Discussion pages and the SandBox:
 
 Some more elaborate limits can be added to what matches using these functions:
 
+* "`glob(someglob)`" - matches pages and other files that match the given glob.
+  Just writing the glob by itself is actually a shorthand for this function.
+* "`page(glob)`" - like `glob()`, but only matches pages, not other files
 * "`link(page)`" - matches only pages that link to a given page (or glob)
 * "`tagged(tag)`" - matches pages that are tagged or link to the given tag (or
   tags matched by a glob)
 * "`backlink(page)`" - matches only pages that a given page links to
-* "`creation_month(month)`" - matches only pages created on the given month
+* "`creation_month(month)`" - matches only files created on the given month
 * "`creation_day(mday)`" - or day of the month
 * "`creation_year(year)`" - or year
-* "`created_after(page)`" - matches only pages created after the given page
+* "`created_after(page)`" - matches only files created after the given page
   was created
-* "`created_before(page)`" - matches only pages created before the given page
+* "`created_before(page)`" - matches only files created before the given page
   was created
-* "`glob(someglob)`" - matches pages that match the given glob. Just writing
-  the glob by itself is actually a shorthand for this function.
 * "`internal(glob)`" - like `glob()`, but matches even internal-use 
   pages that globs do not usually match.
 * "`title(glob)`", "`author(glob)`", "`authorurl(glob)`",
index ade9bca5ac113b6a29f7b5c9ef458f61823729d3..97bcc969c4068a958024658dc90f1801304dd2fd 100755 (executable)
@@ -1,7 +1,7 @@
 #!/usr/bin/perl
 use warnings;
 use strict;
-use Test::More tests => 75;
+use Test::More tests => 85;
 
 BEGIN { use_ok("IkiWiki"); }
 
@@ -66,7 +66,21 @@ $links{"ook"}=[qw{/blog/tags/foo}];
 foreach my $p (keys %links) {
        $pagesources{$p}="$p.mdwn";
 }
+$pagesources{"foo.png"}="foo.png";
+$pagesources{"foo"}="foo.mdwn";
+$IkiWiki::hooks{htmlize}{mdwn}={};
 
+ok(pagespec_match("foo", "foo"), "simple");
+ok(! pagespec_match("foo", "bar"), "simple fail");
+ok(pagespec_match("foo", "foo"), "simple glob");
+ok(pagespec_match("foo", "f*"), "simple glob fail");
+ok(pagespec_match("foo", "page(foo)"), "page()");
+print pagespec_match("foo", "page(foo)")."\n";
+ok(! pagespec_match("foo", "page(bar)"), "page() fail");
+ok(! pagespec_match("foo.png", "page(foo.png)"), "page() fails on non-page");
+ok(! pagespec_match("foo.png", "page(foo*)"), "page() fails on non-page glob");
+ok(pagespec_match("foo", "page(foo)"), "page() glob");
+ok(pagespec_match("foo", "page(f*)"), "page() glob fail");
 ok(pagespec_match("foo", "link(bar)"), "link");
 ok(pagespec_match("foo", "link(ba?)"), "glob link");
 ok(! pagespec_match("foo", "link(quux)"), "failed link");