]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - doc/todo/allow_plugins_to_add_sorting_methods.mdwn
3aa1d94a61e382be4689b1ba80805cc98657e431
[git.ikiwiki.info.git] / doc / todo / allow_plugins_to_add_sorting_methods.mdwn
1 [[!template id=gitbranch branch=smcv/sort-hooks author="[[Simon_McVittie|smcv]]"]]
2 [[!tag patch]]
4 The available [[ikiwiki/pagespec/sorting]] methods are currently hard-coded in
5 IkiWiki.pm, making it difficult to add any extra sorting mechanisms. I've
6 prepared a branch which adds 'sort' as a hook type and uses it to implement a
7 new `meta_title` sort type.
9 Someone could use this hook to make `\[[!inline sort=title]]` prefer the meta
10 title over the page name, but for compatibility, I'm not going to (I do wonder
11 whether it would be worth making sort=name an alias for the current sort=title,
12 and changing the meaning of sort=title in 4.0, though).
14 Gitweb:
15 <http://git.pseudorandom.co.uk/smcv/ikiwiki.git?a=shortlog;h=refs/heads/sort-hooks>
17 ## Documentation extracted from the branch
19 ### sort hook (added to [[plugins/write]])
21        hook(type => "sort", id => "foo", call => \&sort_by_foo);
23 This hook adds an additional [[ikiwiki/pagespec/sorting]] order or overrides
24 an existing one. The callback is given two page names as arguments, and
25 returns negative, zero or positive if the first page should come before,
26 close to (i.e. undefined order), or after the second page.
28 For instance, the built-in `title` sort order could be reimplemented as
30        sub sort_by_title {
31                pagetitle(basename($_[0])) cmp pagetitle(basename($_[1]));
32        }
34 ### meta_title sort order (conditionally added to [[ikiwiki/pagespec/sorting]])
36 * `meta_title` - Order according to the `\[[!meta title="foo" sort="bar"]]`
37   or `\[[!meta title="foo"]]` [[ikiwiki/directive]], or the page name if no
38   full title was set.
40 ### meta title sort parameter (added to [[ikiwiki/directive/meta]])
42 An optional `sort` parameter will be used preferentially when
43 [[ikiwiki/pagespec/sorting]] by `meta_title`:
45        \[[!meta title="The Beatles" sort="Beatles, The"]]
47        \[[!meta title="David Bowie" sort="Bowie, David"]]