1 diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm
2 index 38f090f..6b884cd 100644
3 --- a/IkiWiki/Plugin/map.pm
4 +++ b/IkiWiki/Plugin/map.pm
5 @@ -25,6 +25,42 @@ sub getsetup () {
9 +sub strategy_byparents (@) {
10 + # Sort by parents only
12 + # With this strategy, children are sorted *under* their parents
13 + # regardless of their own position, and the parents' positions are
14 + # determined only by comparing the parents themselves.
16 + # FIXME this is *not* what's described above, but the old behavior (for
17 + # testing/comparison)
19 + my (@sequence,) = @_;
20 + @sequence = sort @sequence;
24 +sub strategy_forcedsequence (@) {
25 + # Forced Sequence Mode
27 + # Using this strategy, all entries will be shown in the sequence; this
28 + # can cause parents to show up multiple times.
30 + # The only reason why this is not the identical function is that
31 + # parents that are sorted between their children are bubbled up to the
32 + # top of their contiguous children to avoid being repeated in the
37 + my (@sequence,) = @_;
38 + # FIXME: i'm surprised that this actually works. i'd expect this to
39 + # work with bubblesort, but i'm afraid that this may just not yield the
40 + # correct results with mergesort.
41 + @sequence = sort {($b eq substr($a, 0, length($b))) - ($a eq substr($b, 0, length($a)))} @sequence;
47 $params{pages}="*" unless defined $params{pages};
48 @@ -37,8 +73,11 @@ sub preprocess (@) {
50 # Get all the items to map.
53 foreach my $page (pagespec_match_list($params{page}, $params{pages},
54 - deptype => $deptype)) {
55 + deptype => $deptype,
56 + sort => exists $params{sort} ? $params{sort} : "title")) {
57 + push(@mapsequence, $page);
58 if (exists $params{show} &&
59 exists $pagestate{$page} &&
60 exists $pagestate{$page}{meta}{$params{show}}) {
61 @@ -88,7 +127,15 @@ sub preprocess (@) {
65 - foreach my $item (sort keys %mapitems) {
66 + if (!exists $params{strategy} || $params{strategy} eq "parent") {
67 + @mapsequence = strategy_byparents(@mapsequence);
68 + } elsif ($params{strategy} eq "forced") {
69 + @mapsequence = strategy_forcedsequence(@mapsequence);
71 + error("Unknown strategy.");
74 + foreach my $item (@mapsequence) {
75 my @linktext = (length $mapitems{$item} ? (linktext => $mapitems{$item}) : ());
76 $item=~s/^\Q$common_prefix\E\///
77 if defined $common_prefix && length $common_prefix;