From b0ae19872d443860aeaab7069255e3a68a520887 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 24 Mar 2010 03:18:24 +0000 Subject: Add an optional "sort" argument to meta titles, defaulting to the title This allows correct sorting of titles, names, etc., with: [[!meta title="David Bowie" sort="Bowie, David"]] [[!meta title="The Beatles" sort="Beatles, The"]] --- IkiWiki/Plugin/meta.pm | 16 +++++++++++----- doc/ikiwiki/directive/meta.mdwn | 7 +++++++ doc/ikiwiki/pagespec/sorting.mdwn | 7 ++++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm index bf8159814..a470041c9 100644 --- a/IkiWiki/Plugin/meta.pm +++ b/IkiWiki/Plugin/meta.pm @@ -90,6 +90,12 @@ sub preprocess (@) { # Metadata collection that needs to happen during the scan pass. if ($key eq 'title') { $pagestate{$page}{meta}{title}=HTML::Entities::encode_numeric($value); + if (exists $params{sort}) { + $pagestate{$page}{meta}{titlesort}=$params{sort}; + } + else { + $pagestate{$page}{meta}{titlesort}=$value; + } return ""; } elsif ($key eq 'description') { @@ -283,18 +289,18 @@ sub pagetemplate (@) { } } -sub title { - my $title = $pagestate{$_[0]}{meta}{title}; +sub titlesort { + my $key = $pagestate{$_[0]}{meta}{titlesort}; - if (defined $title) { - return $title; + if (defined $key) { + return $key; } return pagetitle(IkiWiki::basename($_[0])); } sub sort_meta_title { - return title($_[0]) cmp title($_[1]); + return titlesort($_[0]) cmp titlesort($_[1]); } sub match { diff --git a/doc/ikiwiki/directive/meta.mdwn b/doc/ikiwiki/directive/meta.mdwn index 557441c0b..8d2a5b1ad 100644 --- a/doc/ikiwiki/directive/meta.mdwn +++ b/doc/ikiwiki/directive/meta.mdwn @@ -23,6 +23,13 @@ Supported fields: be set to a true value in the template; this can be used to format things differently in this case. + An optional `sort` parameter will be used preferentially when + [[ikiwiki/pagespec/sorting]] by `meta_title`: + + \[[!meta title="The Beatles" sort="Beatles, The"]] + + \[[!meta title="David Bowie" sort="Bowie, David"]] + * license Specifies a license for the page, for example, "GPL". Can contain diff --git a/doc/ikiwiki/pagespec/sorting.mdwn b/doc/ikiwiki/pagespec/sorting.mdwn index 3a9fef9b6..61516bec5 100644 --- a/doc/ikiwiki/pagespec/sorting.mdwn +++ b/doc/ikiwiki/pagespec/sorting.mdwn @@ -5,13 +5,14 @@ orders can be specified. * `age` - List pages from the most recently created to the oldest. * `mtime` - List pages with the most recently modified first. -* `title` - Order by title. +* `title` - Order by title (page name). * `title_natural` - Only available if [[!cpan Sort::Naturally]] is installed. Orders by title, but numbers in the title are treated as such, ("1 2 9 10 20" instead of "1 10 2 20 9") [[!if test="enabled(meta)" then=""" -* `meta_title` - Order by the full title set by the `\[[!meta title="foo"]]` - [[ikiwiki/directive]]. +* `meta_title` - Order according to the `\[[!meta title="foo" sort="bar"]]` + or `\[[!meta title="foo"]]` [[ikiwiki/directive]], or the page name if no + full title was set. """]] Plugins can add additional sort orders, so more might be available on this -- cgit v1.2.3