inline: switch to use_pagespec
authorJoey Hess <joey@gnu.kitenet.net>
Thu, 8 Oct 2009 22:26:36 +0000 (18:26 -0400)
committerJoey Hess <joey@gnu.kitenet.net>
Thu, 8 Oct 2009 22:30:50 +0000 (18:30 -0400)
Taking advantage of every single one of its features, of course.
Even had to add one more..

IkiWiki/Plugin/inline.pm
doc/plugins/write.mdwn

index be1781520d63029972d05961230f4f230db17634..748e02df418370e10200e32428b649c5d86e75e6 100644 (file)
@@ -196,45 +196,37 @@ sub preprocess_inline (@) {
                @list = map { bestlink($params{page}, $_) }
                        split ' ', $params{pagenames};
 
+               if (yesno($params{reverse})) {
+                       @list=reverse(@list);
+               }
+
                foreach my $p (@list) {
                        add_depends($params{page}, $p, deptype($quick ? "presence" : "content"));
                }
        }
        else {
-               add_depends($params{page}, $params{pages},
-                       deptype($quick ? "presence" : "content"));
-
-               @list = pagespec_match_list(
-                       [ grep { $_ ne $params{page} } keys %pagesources ],
-                       $params{pages}, location => $params{page});
-
-               if (exists $params{sort} && $params{sort} eq 'title') {
-                       @list=sort { pagetitle(basename($a)) cmp pagetitle(basename($b)) } @list;
+               my $num=0;
+               if ($params{show}) {
+                       $num=$params{show};
                }
-               elsif (exists $params{sort} && $params{sort} eq 'title_natural') {
-                       eval q{use Sort::Naturally};
-                       if ($@) {
-                               error(gettext("Sort::Naturally needed for title_natural sort"));
-                       }
-                       @list=sort { Sort::Naturally::ncmp(pagetitle(basename($a)), pagetitle(basename($b))) } @list;
+               if ($params{feedshow} && $num < $params{feedshow}) {
+                       $num=$params{feedshow};
                }
-               elsif (exists $params{sort} && $params{sort} eq 'mtime') {
-                       @list=sort { $pagemtime{$b} <=> $pagemtime{$a} } @list;
+               if ($params{skip}) {
+                       $num+=$params{skip};
                }
-               elsif (! exists $params{sort} || $params{sort} eq 'age') {
-                       @list=sort { $pagectime{$b} <=> $pagectime{$a} } @list;
-               }
-               else {
-                       error sprintf(gettext("unknown sort type %s"), $params{sort});
-               }
-       }
 
-       if (yesno($params{reverse})) {
-               @list=reverse(@list);
+               @list = use_pagespec($params{page}, $params{pages},
+                       deptype => deptype($quick ? "presence" : "content"),
+                       limit => sub { $_[0] ne $params{page} },
+                       sort => exists $params{sort} ? $params{sort} : "age",
+                       reverse => yesno($params{reverse}),
+                       num => $num,
+               );
        }
 
        if (exists $params{skip}) {
-               @list=@list[$params{skip} .. scalar @list - 1];
+               @list=@list[$params{skip} .. $#list];
        }
        
        my @feedlist;
@@ -253,7 +245,8 @@ sub preprocess_inline (@) {
        }
 
        if ($feeds && exists $params{feedpages}) {
-               @feedlist=pagespec_match_list(\@feedlist, $params{feedpages}, location => $params{page});
+               @feedlist = use_pagespec($params{page}, $params{feedpages},
+                       list => \@feedlist);
        }
 
        my ($feedbase, $feednum);
index 3d56507582cdc42c2f4780c6dc244d3a2a94941f..62bebbeedf28bfe5124c6ff67b0b399cc4094ede 100644 (file)
@@ -647,6 +647,8 @@ Additional named parameters can be specified:
 * `reverse` if true, sorts in reverse.
 * `num` if nonzero, specifies the maximum number of matching pages that
   will be returned.
+* `list` makes it only match amoung the specified list of pages.
+  Default is to match amoung all pages in the wiki.
 
 #### `add_depends($$;$)`