]> sipb.mit.edu Git - ikiwiki.git/blob - doc/bugs/map_doesn__39__t_calculate___34__common__95__prefix__34___correctly.mdwn
(no commit message)
[ikiwiki.git] / doc / bugs / map_doesn__39__t_calculate___34__common__95__prefix__34___correctly.mdwn
1 Problem with [[plugins/map]]:
2
3 # Observed behavior:
4
5 ## given map:
6
7 \[[!map pages="blog/tags/*"]]
8
9 ## received map:
10
11 <div class="map">
12 <ul>
13 <li><a href="../" class="mapparent">blog</a>
14 <ul>
15 <li><a href="../tags/" class="mapparent">tags</a>
16 <ul>
17 <li>life
18 </li>
19 </ul>
20 <ul>
21 <li>tech
22 </li>
23 </ul>
24 </li>
25 </ul>
26 </li>
27 </ul>
28 </div>
29
30 Note that you get "blog" and "tags", and they're both links, but "life" and "tech" are not links.
31
32 # desired output:
33
34 <div class="map">
35 <ul>
36 <li><a href="../tags/life/" class="mapitem">life</a>
37 </li>
38 <li><a href="../tags/tech/" class="mapitem">tech</a>
39 </li>
40 </ul>
41 </div>
42
43 Note that you you don't get "blog" or "tags", and "life" and "tech" are links now.
44
45 # patch which appears to achieve this:
46
47 <pre>
48 --- map.pm.orig 2007-11-23 16:04:02.000000000 -0500
49 +++ map.pm      2007-12-21 00:12:15.000000000 -0500
50 @@ -37,6 +37,9 @@
51                                 my @b=split(/\//, $common_prefix);
52                                 $common_prefix="";
53                                 while (@a && @b && $a[0] eq $b[0]) {
54 +                                       if ($common_prefix) {
55 +                                         $common_prefix .= "/";
56 +                                       }
57                                         $common_prefix.=shift(@a);
58                                         shift @b;
59                                 }
60 </pre>
61
62 # Discussion
63
64 (Disclaimer: I don't know ikiwiki internals.)
65
66 Map tries to calculate a "common prefix" between the pagespec and the page being rendered, and then later does some substitutions using the prefix.  But the path has /'s in it and the common prefix doesn't, so it never matches correctly.  So, add the /'s.
67
68 -- [[users/Larry_Clapp]]
69
70 > Excellent problem description and analysis. Patch [[applied|done]] --[[Joey]]