1 The [[plugins/map]] plugin has inconsistent behaviour. In particular, I have in my wiki some directory structures holding files without wikitext pointers (I point directly to the files from elsewhere). For example, imagine the following file structure in the source dir:
22 When I use map to make a map of this, the result looks more like this:
25 <li><span class="createlink">? dirA</span>
27 <li><span class="createlink">? subA</span>
45 <li><span class="createlink">? dirB</span>
47 <li><span class="createlink">? subA</span>
55 <li><span class="createlink">? subC</span>
69 Note that while the dirA/subA directory exists with a create link, the dirA/subB directory is missing from the map. Interestingly, dirB/subC is shown in the map. If you add a second file to dirB/subA then dirB/subC disappears as well.
71 I could imagine including all 'bare' directories in the map, and I could imagine including no 'bare' directories in the map. Just including the first bare directory seems a strange intermediate point.
73 Attached is a [[patch]] that fixes the issue. The current map code makes one pass over the sorted list of pages. This adds an initial pass that goes through and makes sure that all parent directories are included. With this initial pass added, the following pass could probably be simplified.
75 One solution could also use the [[plugins/autoindex]] plugin to make sure that parent pages actually exist. This is really only a stop-gap solution until the patch is applied - map still needs to be made bug-free.
77 Note: This patch adds items to a map while it is in a foreach loop over a sorted list of keys from that same map. Changing a map while iterating through it is normally problematic. I'm assuming the sort insulates the code from this - I do not need to iterate over any of the newly added elements.
79 diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm
80 index 5b6a843..16de45e 100644
81 --- a/IkiWiki/Plugin/map.pm
82 +++ b/IkiWiki/Plugin/map.pm
83 @@ -67,6 +67,39 @@ sub preprocess (@) { #{{{
85 add_depends($params{page}, join(" or ", keys %mapitems));
87 + # Include all the parent directories in the map
89 + my $commonbase = "";
90 + $commonbase = $common_prefix if defined $common_prefix && length $common_prefix;
91 + foreach my $item (sort keys %mapitems) {
92 + $item=~s/^\Q$common_prefix\E\///
93 + if defined $common_prefix && length $common_prefix;
94 + my $itembase=IkiWiki::dirname($item);
95 + if ($itembase ne $lastbase) {
96 + # find the common dir
97 + my @a=split(/\//, $itembase);
98 + my @b=split(/\//, $lastbase);
99 + my $common_dir=$commonbase;
100 + while (@a && @b && $a[0] eq $b[0]) {
101 + if (length $common_dir) {
104 + $common_dir.=shift(@a);
107 + # add all the dirs down to the current base
109 + if (length $common_dir) {
112 + $common_dir.=shift(@a);
113 + $mapitems{$common_dir}=''
114 + unless defined $mapitems{$common_dir};
116 + $lastbase = $itembase;