1 Instead of having files foo.html "in front of" foo/, I prefer to have
2 foo/index.html. This patch allows that. Specifically, foo/index.type
3 is translated to $links{'foo/'}, and bestlink looks for either "foo" or
4 "foo/" when linking to pages. There are other miscellaneous changes that
7 1. change the `cgi_editpage` `@page_locs` code so that creating foo from
8 a/b/c prefers a/b/foo and then a/b/c/foo, but if creating foo from a/b/c/,
9 then prefer a/b/c/foo. I'm not really sure why the original was doing what
10 it did (why trim terminal `/` if no pages end in `/`?), so this part might
12 2. tweak things so that index.rss and index.atom are generated if inlining
14 2. backlinks from "foo/bar" to "foo/" trim common prefixes as long as there
15 would be something left when the trimming is done (i.e. don't trim "foo/")
16 3. parentlinks for "foo/" are the same as for "foo", except one directory
18 4. rewrite parentlinks so that bestlink is called at each level
19 5. basename("foo/") => basename("foo")
20 6. links to "foo/" are translated to "foo/index.html" rather than "foo/.html".
21 (Links to "foo/" might be preferred, but that causes an infinite loop in
22 writefile, because apparently dirname("foo/") == "foo/" on my system for
23 reasons that aren't clear to me.)
24 7. pagetitle("foo/") => pagetitle("foo")
25 8. clip the final slash when matching a relative pagespec, even if there are
26 no characters after it (otherwise inlining "./a" from "foo/" gets
27 translated to "foo//a")
29 In case whitespace gets garbled, I'm also leaving a copy of the patch on
30 [my site](http://ikidev.betacantrips.com/patches/index.patch). It should apply
31 cleanly to a freshly unpacked ikiwiki-1.42. You can also see it in action
32 [here](http://ikidev.betacantrips.com/one/). --Ethan
34 diff -urX ignorepats ikiclean/IkiWiki/CGI.pm ikidev/IkiWiki/CGI.pm
35 --- ikiclean/IkiWiki/CGI.pm 2007-02-11 21:40:32.419641000 -0800
36 +++ ikidev/IkiWiki/CGI.pm 2007-02-11 21:54:36.252357000 -0800
38 @page_locs=$best_loc=$page;
46 if ((defined $form->field('subpage') && length $form->field('subpage')) ||
47 $page eq gettext('discussion')) {
51 push @page_locs, $dir.$page;
52 - push @page_locs, "$from/$page";
53 + if ($dir ne $from){ # i.e. $from not a directory
54 + push @page_locs, "$from/$page";
58 push @page_locs, $dir.$page;
59 diff -urX ignorepats ikiclean/IkiWiki/Plugin/inline.pm ikidev/IkiWiki/Plugin/inline.pm
60 --- ikiclean/IkiWiki/Plugin/inline.pm 2007-02-11 21:40:31.996007000 -0800
61 +++ ikidev/IkiWiki/Plugin/inline.pm 2007-02-11 21:54:36.008358000 -0800
64 add_depends($params{page}, $params{pages});
66 - my $rssurl=rsspage(basename($params{page}));
67 - my $atomurl=atompage(basename($params{page}));
68 + my $rssurl=basename(rsspage($params{page}));
69 + my $atomurl=basename(atompage($params{page}));
72 if (exists $params{rootpage} && $config{cgiurl}) {
75 sub rsspage ($) { #{{{
77 + $page = htmlpage($page);
78 + $page =~s/\.html$/.rss/;
80 - return $page.".rss";
84 sub atompage ($) { #{{{
86 + $page = htmlpage($page);
87 + $page =~s/\.html$/.atom/;
89 - return $page.".atom";
93 sub genfeed ($$$$@) { #{{{
94 diff -urX ignorepats ikiclean/IkiWiki/Render.pm ikidev/IkiWiki/Render.pm
95 --- ikiclean/IkiWiki/Render.pm 2007-02-11 21:40:32.413641000 -0800
96 +++ ikidev/IkiWiki/Render.pm 2007-02-11 21:54:36.246356000 -0800
99 1 while (($dir)=$page_trimmed=~m!^([^/]+/)!) &&
101 + $p_trimmed=~m/^\Q$dir\E(?:.)/ &&
102 $p_trimmed=~s/^\Q$dir\E// &&
103 $page_trimmed=~s/^\Q$dir\E//;
108 return if $page eq 'index'; # toplevel
109 - foreach my $dir (reverse split("/", $page)) {
110 + if ($page =~ m{/$}){
115 + while ($page =~ m!([^/]+)$!) {
117 + $page =~ s!/?[^/]+$!!;
120 - unshift @ret, { url => $path.htmlpage($dir), page => pagetitle($dir) };
121 + my $target = abs2rel(htmlpage(bestlink($page, $last)), $page);
122 + unshift @ret, { url => $path.$target, page => pagetitle($last) };
126 diff -urX ignorepats ikiclean/IkiWiki.pm ikidev/IkiWiki.pm
127 --- ikiclean/IkiWiki.pm 2007-02-11 21:40:35.118406000 -0800
128 +++ ikidev/IkiWiki.pm 2007-02-11 22:22:49.146071000 -0800
130 sub basename ($) { #{{{
137 @@ -214,12 +215,14 @@
138 my $type=pagetype($file);
140 $page=~s/\Q.$type\E*$// if defined $type;
141 + $page=~s#index$## if $page=~m{/index$};
145 sub htmlpage ($) { #{{{
148 + return $page."index.html" if $page=~m{/$};
149 return $page.".html";
158 if ($link=~s/^\/+//) {
161 if (exists $links{$l}) {
164 + if (exists $links{$l.'/'}){
167 elsif (exists $pagecase{lc $l}) {
168 return $pagecase{lc $l};
171 $page=~s/__(\d+)__/&#$1;/g;
181 if ($glob =~ m!^\./!) {
182 - $from=~s!/?[^/]+$!!;
183 + $from=~s!/?[^/]*$!!;
185 $glob="$from/$glob" if length $from;
188 I independently implemented a similar, but smaller patch.
189 (It's smaller because I only care about rendering; not CGI, for example.)
190 The key to this patch is that "A/B/C" is treated as equivalent
192 Here it is: --Per Bothner
194 --- IkiWiki/Render.pm~ 2007-01-11 15:01:51.000000000 -0800
195 +++ IkiWiki/Render.pm 2007-02-02 22:24:12.000000000 -0800
197 foreach my $dir (reverse split("/", $page)) {
200 - unshift @ret, { url => $path.htmlpage($dir), page => pagetitle($dir) };
201 + unshift @ret, { url => abs2rel(htmlpage(bestlink($page, $dir)), dirname($page)), page => pagetitle($dir) };
204 + elsif ($dir ne "index") {
209 --- IkiWiki.pm~ 2007-01-12 12:47:09.000000000 -0800
210 +++ IkiWiki.pm 2007-02-02 18:02:16.000000000 -0800
212 elsif (exists $pagecase{lc $l}) {
213 return $pagecase{lc $l};
216 + my $lindex = $l . "/index";
217 + if (exists $links{$lindex}) {
221 } while $cwd=~s!/?[^/]+$!!;
223 if (length $config{userdir} && exists $links{"$config{userdir}/".lc($link)}) {
225 Note I handle setting the url; slightly differently.
226 Also note that an initial "index" is ignored. I.e. a
227 page "A/B/index.html" is treated as "A/B".
229 > This is actually a pretty cool hack. I'll have to think about
230 > whether I like it better than my way though :) --Ethan
234 How about doing the index stuff only on the output side? (Or does the latter patch do it? I haven't tried them.) That is, render every `foo.type` for the rendered types (mdwn etc.) as `foo/index.html`, generating links to `foo/` instead of `foo.html`, but not earlier than the point where the .html as presently appended to the page name. Then you just flip a build time option on an existing wiki without any changes to that, and the pages appear elsewhere. The `index.type` files might be left out of this scheme, though (and the top-level one, of course, has to). --[[tuomov]]
236 > Well, get around to wasting time on it after all, and [here's the patch](http://iki.fi/tuomov/use_dirs.diff). The `-use_dirs` option will cause everything to be rendered inside directories. There may still be some problems with it, that need looking into (it doesn't e.g. check for conflicts between foo/index.mdwn and foo.mdwn), but seems to work well enough for me... The patch also improves, I think, the parentlinks code a little, as it uses generic routines to actually find the target location now. The only places where the `use_dirs` option is used is `htmlpage`, in fact, although other specific kludges needed to be removed from other points in the code.