]> sipb.mit.edu Git - ikiwiki.git/blob - doc/patchqueue/index.html_allowed.mdwn
web commit by hb
[ikiwiki.git] / doc / patchqueue / index.html_allowed.mdwn
1 Instead of having files foo.html "in front of" foo/, I prefer to have foo/index.html. This patch allows that. Specifically, foo/index.type is translated to $links{'foo/'}, and bestlink looks for either "foo" or "foo/" when linking to pages. There are other miscellaneous changes that go with that:
2
3 1. backlinks from "foo/bar" to "foo/" trim common prefixes as long as there would be something left when the trimming is done (i.e. don't trim "foo/")
4 2. parentlinks for "foo/" are the same as for "foo", except one directory higher
5 3. rewrite parentlinks so that bestlink is called at each level
6 4. basename("foo/") => basename("foo")
7 5. links to "foo/" are translated to "foo/index.html" rather than "foo/.html". (Links to "foo/" might be preferred, but that causes an infinite loop in writefile, because apparently dirname("foo/") == "foo/" on my system for reasons that aren't clear to me.)
8 6. pagetitle("foo/") => pagetitle("foo")
9
10 In case whitespace gets garbled, I'm also leaving a copy of the patch on [my site](http://ikidev.betacantrips.com/patches/index.patch). It should apply cleanly to a freshly unpacked ikiwiki-1.40. You can also see it in action [here](http://ikidev.betacantrips.com/one/). --Ethan
11
12     diff -urx .svn ikiwiki/IkiWiki/Render.pm ikidev/IkiWiki/Render.pm
13     --- ikiwiki/IkiWiki/Render.pm       2007-01-11 15:01:51.000000000 -0800
14     +++ ikidev/IkiWiki/Render.pm        2007-01-15 18:38:34.000000000 -0800
15     @@ -40,6 +40,7 @@
16                 my $dir;
17                 1 while (($dir)=$page_trimmed=~m!^([^/]+/)!) &&
18                         defined $dir &&
19     +                   $p_trimmed=~m/^\Q$dir\E(?:.)/ &&
20                         $p_trimmed=~s/^\Q$dir\E// &&
21                         $page_trimmed=~s/^\Q$dir\E//;
22                                
23     @@ -57,10 +58,18 @@
24         my $path="";
25         my $skip=1;
26         return if $page eq 'index'; # toplevel
27     -   foreach my $dir (reverse split("/", $page)) {
28     +   if ($page =~ m{/$}){
29     +           $page =~ s{/$}{};
30     +           $path="../";
31     +   }
32     +
33     +   while ($page =~ m!([^/]+)$!) {
34     +           my $last = $1;
35     +           $page =~ s!/?[^/]+$!!;
36                 if (! $skip) {
37                         $path.="../";
38     -                   unshift @ret, { url => $path.htmlpage($dir), page => pagetitle($dir) };
39     +                   my $target = abs2rel(htmlpage(bestlink($page, $last)), $page);
40     +                   unshift @ret, { url => $path.$target, page => pagetitle($last) };
41                 }
42                 else {
43                         $skip=0;
44     diff -urx .svn ikiwiki/IkiWiki.pm ikidev/IkiWiki.pm
45     --- ikiwiki/IkiWiki.pm      2007-01-12 12:47:09.000000000 -0800
46     +++ ikidev/IkiWiki.pm       2007-01-15 16:56:58.000000000 -0800
47     @@ -185,6 +185,7 @@
48      sub basename ($) { #{{{
49         my $file=shift;
50      
51     +   $file=~s!/$!!;
52         $file=~s!.*/+!!;
53         return $file;
54      } #}}}
55     @@ -211,12 +212,14 @@
56         my $type=pagetype($file);
57         my $page=$file;
58         $page=~s/\Q.$type\E*$// if defined $type;
59     +   $page=~s#index$## if $page=~m{/index$};
60         return $page;
61      } #}}}
62      
63      sub htmlpage ($) { #{{{
64         my $page=shift;
65      
66     +   return $page."index.html" if $page=~m{/$};
67         return $page.".html";
68      } #}}}
69      
70     @@ -300,6 +303,7 @@
71         my $page=shift;
72         my $link=shift;
73         
74     +   $page =~ s!/$!!;
75         my $cwd=$page;
76         if ($link=~s/^\/+//) {
77                 # absolute links
78     @@ -314,6 +318,9 @@
79                 if (exists $links{$l}) {
80                         return $l;
81                 }
82     +           if (exists $links{$l.'/'}){
83     +                   return $l.'/';
84     +           }
85                 elsif (exists $pagecase{lc $l}) {
86                         return $pagecase{lc $l};
87                 }
88     @@ -344,6 +351,7 @@
89                 $page=~s/__(\d+)__/&#$1;/g;
90         }
91         $page=~y/_/ /;
92     +   $page=~s!/$!!;
93      
94         return $page;
95      } #}}}