From: Simon McVittie Date: Sun, 18 Mar 2012 17:11:05 +0000 (+0000) Subject: Replace [[!trailinline]] directive with [[!inline trail=yes]] X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=63bb8b42f76e350cdf7a1256ad0fe7ad63199f63;p=ikiwiki.git Replace [[!trailinline]] directive with [[!inline trail=yes]] --- diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 159cc5def..3dc410c27 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -19,7 +19,7 @@ sub import { hook(type => "checkconfig", id => "inline", call => \&checkconfig); hook(type => "sessioncgi", id => "inline", call => \&sessioncgi); hook(type => "preprocess", id => "inline", - call => \&IkiWiki::preprocess_inline); + call => \&IkiWiki::preprocess_inline, scan => 1); hook(type => "pagetemplate", id => "inline", call => \&IkiWiki::pagetemplate_inline); hook(type => "format", id => "inline", call => \&format, first => 1); @@ -155,6 +155,23 @@ sub preprocess_inline (@) { if (! exists $params{pages} && ! exists $params{pagenames}) { error gettext("missing pages parameter"); } + + if (! defined wantarray) { + # Running in scan mode: only do the essentials + + if (yesno($params{trail}) && IkiWiki::Plugin::trail->can("preprocess_trailitems")) { + # default to sorting age, the same as inline itself, + # but let the params override that + IkiWiki::Plugin::trail::preprocess_trailitems(sort => 'age', %params); + } + + return; + } + + if (yesno($params{trail}) && IkiWiki::Plugin::trail->can("preprocess_trailitems")) { + scalar IkiWiki::Plugin::trail::preprocess_trailitems(sort => 'age', %params); + } + my $raw=yesno($params{raw}); my $archive=yesno($params{archive}); my $rss=(($config{rss} || $config{allowrss}) && exists $params{rss}) ? yesno($params{rss}) : $config{rss}; diff --git a/IkiWiki/Plugin/trail.pm b/IkiWiki/Plugin/trail.pm index 5ee152155..4f309ea2e 100644 --- a/IkiWiki/Plugin/trail.pm +++ b/IkiWiki/Plugin/trail.pm @@ -1,6 +1,6 @@ #!/usr/bin/perl # Copyright © 2008-2011 Joey Hess -# Copyright © 2009-2011 Simon McVittie +# Copyright © 2009-2012 Simon McVittie # Licensed under the GNU GPL, version 2, or any later version published by the # Free Software Foundation package IkiWiki::Plugin::trail; @@ -13,7 +13,6 @@ sub import { hook(type => "getsetup", id => "trail", call => \&getsetup); hook(type => "needsbuild", id => "trail", call => \&needsbuild); hook(type => "preprocess", id => "trailoptions", call => \&preprocess_trailoptions, scan => 1); - hook(type => "preprocess", id => "trailinline", call => \&preprocess_trailinline, scan => 1); hook(type => "preprocess", id => "trailitem", call => \&preprocess_trailitem, scan => 1); hook(type => "preprocess", id => "trailitems", call => \&preprocess_trailitems, scan => 1); hook(type => "preprocess", id => "traillink", call => \&preprocess_traillink, scan => 1); @@ -123,29 +122,6 @@ sub preprocess_trailoptions (@) { return ""; } -sub preprocess_trailinline (@) { - my %params = @_; - - if (! exists $params{sort}) { - # sort in the same order as [[plugins/inline]]'s default - $params{sort} = 'age'; - } - - if (defined wantarray) { - scalar preprocess_trailitems(%params); - - if (IkiWiki->can("preprocess_inline")) { - return IkiWiki::preprocess_inline(@_); - } - else { - error("trailinline directive requires the inline plugin"); - } - } - else { - preprocess_trailitems(%params); - } -} - sub preprocess_trailitem (@) { my $link = shift; shift; diff --git a/doc/examples/blog/posts.mdwn b/doc/examples/blog/posts.mdwn index 6e9a3f001..2bd0f1d6f 100644 --- a/doc/examples/blog/posts.mdwn +++ b/doc/examples/blog/posts.mdwn @@ -1,3 +1,3 @@ Here is a full list of posts to the [[blog|index]]. -[[!trailinline pages="page(./posts/*) and !*/Discussion" archive=yes feedshow=10 quick=yes]] +[[!inline pages="page(./posts/*) and !*/Discussion" archive=yes feedshow=10 quick=yes trail=yes]] diff --git a/doc/ikiwiki/directive/inline.mdwn b/doc/ikiwiki/directive/inline.mdwn index 22c18d9a1..4b11e5997 100644 --- a/doc/ikiwiki/directive/inline.mdwn +++ b/doc/ikiwiki/directive/inline.mdwn @@ -117,5 +117,10 @@ Here are some less often needed parameters: [[SubPage/LinkingRules]] as in a [[ikiwiki/WikiLink]]), and they are inlined in exactly the order given: the `sort` and `pages` parameters cannot be used in conjunction with this one. +* `trail` - If the [[!iki plugins/trail desc=trail]] plugin is enabled, turn + the inlined pages into a trail with next/previous links, by passing the same + options to [[ikiwiki/directive/trailitems]]. The `skip` and `show` options + are ignored by the trail, so the next/previous links traverse through + all matching pages. [[!meta robots="noindex, follow"]] diff --git a/doc/ikiwiki/directive/trailinline.mdwn b/doc/ikiwiki/directive/trailinline.mdwn deleted file mode 100644 index e32fb34d0..000000000 --- a/doc/ikiwiki/directive/trailinline.mdwn +++ /dev/null @@ -1,11 +0,0 @@ -The `trailinline` directive is provided by the -[[!iki plugins/trail desc=trail]] -plugin. It is equivalent to combining [[ikiwiki/directive/trailitems]] and -[[ikiwiki/directive/inline]] directives with the same options. - -A typical use is to navigate through all posts in a blog: - - \[[!trailinline pages="page(./posts/*) and !*/Discussion" archive=yes - feedshow=10 quick=yes]] - -[[!meta robots="noindex, follow"]] diff --git a/doc/plugins/trail.mdwn b/doc/plugins/trail.mdwn index 406d40246..14b97e35a 100644 --- a/doc/plugins/trail.mdwn +++ b/doc/plugins/trail.mdwn @@ -3,8 +3,7 @@ This plugin provides the [[ikiwiki/directive/trailoptions]], [[ikiwiki/directive/traillink]], [[ikiwiki/directive/trailitem]], -[[ikiwiki/directive/trailitems]] -and [[ikiwiki/directive/trailinline]] [[directives|ikiwiki/directive]]. +and [[ikiwiki/directive/trailitems]] [[directives|ikiwiki/directive]]. It's sometimes useful to have "trails" of pages in a wiki where each page links to the next and/or previous page. For instance, you could use @@ -24,15 +23,16 @@ entire trail. Pages can be included in a trail in various ways: -* The [[ikiwiki/directive/trailinline]] directive sets up an [[inline]], - and at the same time adds the matching pages (from `pages` or `pagenames`) - to the trail. One use is to navigate through all posts in a blog: +* The [[ikiwiki/directive/inline]] directive with `trail="yes"` sets up an + [[inline]], and at the same time adds the matching pages (from `pages` or + `pagenames`) to the trail. One use is to navigate through all posts in + a blog: - \[[!trailinline pages="page(./posts/*) and !*/Discussion" archive=yes - feedshow=10 quick=yes]] + \[[!inline pages="page(./posts/*) and !*/Discussion" archive=yes + feedshow=10 quick=yes trail=yes]] - This directive only works if the [[!iki plugins/inline desc=inline]] - plugin is also enabled. + This only works if the trail and [[!iki plugins/inline desc=inline]] + plugins are both enabled. * The [[ikiwiki/directive/trailitems]] directive has optional `pages` and `pagenames` options which behave the same as in [[inline]], but don't diff --git a/t/trail.t b/t/trail.t index 0cf50ddc1..17fe54310 100755 --- a/t/trail.t +++ b/t/trail.t @@ -60,13 +60,13 @@ ok(utime(333333333, 333333333, "t/tmp/in/sorting/new.mdwn")); ok(utime(222222222, 222222222, "t/tmp/in/sorting/old.mdwn")); ok(utime(111111111, 111111111, "t/tmp/in/sorting/ancient.mdwn")); writefile("sorting/linked2.mdwn", "t/tmp/in", "linked2"); -# This initially uses the default sort order: age for trailinline, and path -# for trail. We change it later. +# This initially uses the default sort order: age for the inline, and path +# for trailitems. We change it later. writefile("sorting.mdwn", "t/tmp/in", '[[!traillink linked]] ' . '[[!trailitems pages="sorting/z/a or sorting/a/b or sorting/a/c"]] ' . '[[!trailitems pagenames="beginning middle end"]] ' . - '[[!trailinline pages="sorting/old or sorting/ancient or sorting/new"]] ' . + '[[!inline pages="sorting/old or sorting/ancient or sorting/new" trail="yes"]] ' . '[[!traillink linked2]]'); writefile("meme.mdwn", "t/tmp/in", <