ikiwiki (3.20130711) unstable; urgency=low
[ikiwiki.git] / IkiWiki / Plugin / sortnaturally.pm
1 #!/usr/bin/perl
2 # Sort::Naturally-powered title_natural sort order for IkiWiki
3 package IkiWiki::Plugin::sortnaturally;
4
5 use IkiWiki 3.00;
6 no warnings;
7
8 sub import {
9         hook(type => "getsetup", id => "sortnaturally", call => \&getsetup);
10         hook(type => "checkconfig", id => "sortnaturally", call => \&checkconfig);
11 }
12
13 sub getsetup {
14         return
15                 plugin => {
16                         safe => 1,
17                         rebuild => undef,
18                 },
19 }
20
21 sub checkconfig () {
22         eval q{use Sort::Naturally};
23         error $@ if $@;
24 }
25
26 package IkiWiki::SortSpec;
27
28 sub cmp_title_natural {
29         Sort::Naturally::ncmp(IkiWiki::pagetitle(IkiWiki::basename($a)),
30                 IkiWiki::pagetitle(IkiWiki::basename($b)))
31 }
32
33 sub cmp_path_natural {
34         Sort::Naturally::ncmp(IkiWiki::pagetitle($a),
35                 IkiWiki::pagetitle($b))
36 }
37
38 1;