aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/sortnaturally.pm
blob: 108b489f80d6f7e71916c891345ecea8569e9ed3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/perl
# Sort::Naturally-powered title_natural sort order for IkiWiki
package IkiWiki::Plugin::sortnaturally;

use IkiWiki 3.00;
no warnings;

sub import {
	hook(type => "getsetup", id => "sortnaturally", call => \&getsetup);
	hook(type => "checkconfig", id => "sortnaturally", call => \&checkconfig);
}

sub getsetup {
	return
		plugin => {
			safe => 1,
			rebuild => undef,
		},
}

sub checkconfig () {
	eval q{use Sort::Naturally};
	error $@ if $@;
}

package IkiWiki::SortSpec;

sub cmp_title_natural {
	Sort::Naturally::ncmp(IkiWiki::pagetitle(IkiWiki::basename($a)),
		IkiWiki::pagetitle(IkiWiki::basename($b)))
}

sub cmp_path_natural {
	Sort::Naturally::ncmp(IkiWiki::pagetitle($a),
		IkiWiki::pagetitle($b))
}

1;