aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IkiWiki/Plugin/meta.pm58
-rw-r--r--doc/ikiwiki/directive/meta.mdwn7
-rw-r--r--doc/ikiwiki/pagespec/sorting.mdwn5
3 files changed, 58 insertions, 12 deletions
diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
index cd7d0d127..c9fdbc934 100644
--- a/IkiWiki/Plugin/meta.pm
+++ b/IkiWiki/Plugin/meta.pm
@@ -122,6 +122,12 @@ sub preprocess (@) {
}
elsif ($key eq 'author') {
$pagestate{$page}{meta}{author}=$value;
+ if (exists $params{sort}) {
+ $pagestate{$page}{meta}{authorsort}=$params{sort};
+ }
+ else {
+ $pagestate{$page}{meta}{authorsort}=$value;
+ }
# fallthorough
}
elsif ($key eq 'authorurl') {
@@ -288,14 +294,31 @@ sub pagetemplate (@) {
}
}
-sub titlesort {
- my $key = $pagestate{$_[0]}{meta}{titlesort};
+sub get_sort_key {
+ my $page = $_[0];
+ my $meta = $_[1];
- if (defined $key) {
- return $key;
- }
+ # e.g. titlesort (also makes sense for author)
+ my $key = $pagestate{$page}{meta}{$meta . "sort"};
+ return $key if defined $key;
+
+ # e.g. title
+ $key = $pagestate{$page}{meta}{$meta};
+ return $key if defined $key;
- return pagetitle(IkiWiki::basename($_[0]));
+ # fall back to closer-to-core things
+ if ($meta eq 'title') {
+ return pagetitle(IkiWiki::basename($page));
+ }
+ elsif ($meta eq 'date') {
+ return $IkiWiki::pagectime{$page};
+ }
+ elsif ($meta eq 'updated') {
+ return $IkiWiki::pagemtime{$page};
+ }
+ else {
+ return '';
+ }
}
sub match {
@@ -350,10 +373,27 @@ sub match_copyright ($$;@) {
package IkiWiki::SortSpec;
+sub cmp_meta {
+ my $left = $_[0];
+ my $right = $_[1];
+ my $meta = $_[2];
+ error(gettext("sort=meta requires a parameter")) unless defined $meta;
+
+ if ($meta eq 'updated' || $meta eq 'date') {
+ return IkiWiki::Plugin::meta::get_sort_key($left, $meta)
+ <=>
+ IkiWiki::Plugin::meta::get_sort_key($right, $meta);
+ }
+
+ return IkiWiki::Plugin::meta::get_sort_key($left, $meta)
+ cmp
+ IkiWiki::Plugin::meta::get_sort_key($right, $meta);
+}
+
+# A prototype of how sort=title could behave in 4.0 or something
sub cmp_meta_title {
- IkiWiki::Plugin::meta::titlesort($_[0])
- cmp
- IkiWiki::Plugin::meta::titlesort($_[1])
+ $_[2] = 'title';
+ return cmp_meta(@_);
}
1
diff --git a/doc/ikiwiki/directive/meta.mdwn b/doc/ikiwiki/directive/meta.mdwn
index 8d2a5b1ad..c5f74fac5 100644
--- a/doc/ikiwiki/directive/meta.mdwn
+++ b/doc/ikiwiki/directive/meta.mdwn
@@ -24,7 +24,7 @@ Supported fields:
differently in this case.
An optional `sort` parameter will be used preferentially when
- [[ikiwiki/pagespec/sorting]] by `meta_title`:
+ [[ikiwiki/pagespec/sorting]] by `meta(title)`:
\[[!meta title="The Beatles" sort="Beatles, The"]]
@@ -44,6 +44,11 @@ Supported fields:
Specifies the author of a page.
+ An optional `sort` parameter will be used preferentially when
+ [[ikiwiki/pagespec/sorting]] by `meta(author)`:
+
+ \[[!meta author="Joey Hess" sort="Hess, Joey"]]
+
* authorurl
Specifies an url for the author of a page.
diff --git a/doc/ikiwiki/pagespec/sorting.mdwn b/doc/ikiwiki/pagespec/sorting.mdwn
index ba995a521..fbf598340 100644
--- a/doc/ikiwiki/pagespec/sorting.mdwn
+++ b/doc/ikiwiki/pagespec/sorting.mdwn
@@ -11,9 +11,10 @@ orders can be specified.
as such, ("1 2 9 10 20" instead of "1 10 2 20 9")
"""]]
[[!if test="enabled(meta)" then="""
-* `meta_title` - Order according to the `\[[!meta title="foo" sort="bar"]]`
+* `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.
+ full title was set. `meta(author)`, `meta(date)`, `meta(updated)`, etc.
+ also work.
"""]]
In addition, you can combine several sort orders and/or reverse the order of