]> sipb.mit.edu Git - ikiwiki.git/blob - doc/patchqueue/index.html_allowed.mdwn
meh
[ikiwiki.git] / doc / patchqueue / index.html_allowed.mdwn
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 
5 go with that:
6
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
11    break something.
12 2. tweak things so that index.rss and index.atom are generated if inlining 
13    from 'foo/'
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 
17    higher
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")
28
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
33
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
37     @@ -408,8 +408,8 @@
38                                 @page_locs=$best_loc=$page;
39                         }
40                         else {
41     -                           my $dir=$from."/";
42     -                           $dir=~s![^/]+/+$!!;
43     +                           my $dir=$from;
44     +                           $dir=~s![^/]+$!!;
45                                 
46                                 if ((defined $form->field('subpage') && length $form->field('subpage')) ||
47                                     $page eq gettext('discussion')) {
48     @@ -420,7 +420,9 @@
49                                 }
50                                 
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";
55     +                           }
56                                 while (length $dir) {
57                                         $dir=~s![^/]+/+$!!;
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
62     @@ -110,8 +110,8 @@
63      
64         add_depends($params{page}, $params{pages});
65      
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}));
70         my $ret="";
71      
72         if (exists $params{rootpage} && $config{cgiurl}) {
73     @@ -285,14 +285,18 @@
74      
75      sub rsspage ($) { #{{{
76         my $page=shift;
77     +   $page = htmlpage($page);
78     +   $page =~s/\.html$/.rss/;
79      
80     -   return $page.".rss";
81     +   return $page;
82      } #}}}
83      
84      sub atompage ($) { #{{{
85         my $page=shift;
86     +   $page = htmlpage($page);
87     +   $page =~s/\.html$/.atom/;
88      
89     -   return $page.".atom";
90     +   return $page;
91      } #}}}
92      
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
97     @@ -40,6 +40,7 @@
98                 my $dir;
99                 1 while (($dir)=$page_trimmed=~m!^([^/]+/)!) &&
100                         defined $dir &&
101     +                   $p_trimmed=~m/^\Q$dir\E(?:.)/ &&
102                         $p_trimmed=~s/^\Q$dir\E// &&
103                         $page_trimmed=~s/^\Q$dir\E//;
104                                
105     @@ -57,10 +58,18 @@
106         my $path="";
107         my $skip=1;
108         return if $page eq 'index'; # toplevel
109     -   foreach my $dir (reverse split("/", $page)) {
110     +   if ($page =~ m{/$}){
111     +           $page =~ s{/$}{};
112     +           $path="../";
113     +   }
114     +
115     +   while ($page =~ m!([^/]+)$!) {
116     +           my $last = $1;
117     +           $page =~ s!/?[^/]+$!!;
118                 if (! $skip) {
119                         $path.="../";
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) };
123                 }
124                 else {
125                         $skip=0;
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
129     @@ -188,6 +188,7 @@
130      sub basename ($) { #{{{
131         my $file=shift;
132      
133     +   $file=~s!/$!!;
134         $file=~s!.*/+!!;
135         return $file;
136      } #}}}
137     @@ -214,12 +215,14 @@
138         my $type=pagetype($file);
139         my $page=$file;
140         $page=~s/\Q.$type\E*$// if defined $type;
141     +   $page=~s#index$## if $page=~m{/index$};
142         return $page;
143      } #}}}
144      
145      sub htmlpage ($) { #{{{
146         my $page=shift;
147      
148     +   return $page."index.html" if $page=~m{/$};
149         return $page.".html";
150      } #}}}
151      
152     @@ -307,6 +310,7 @@
153         my $page=shift;
154         my $link=shift;
155         
156     +   $page =~ s!/$!!;
157         my $cwd=$page;
158         if ($link=~s/^\/+//) {
159                 # absolute links
160     @@ -321,6 +325,9 @@
161                 if (exists $links{$l}) {
162                         return $l;
163                 }
164     +           if (exists $links{$l.'/'}){
165     +                   return $l.'/';
166     +           }
167                 elsif (exists $pagecase{lc $l}) {
168                         return $pagecase{lc $l};
169                 }
170     @@ -351,6 +358,7 @@
171                 $page=~s/__(\d+)__/&#$1;/g;
172         }
173         $page=~y/_/ /;
174     +   $page=~s!/$!!;
175      
176         return $page;
177      } #}}}
178     @@ -879,7 +887,7 @@
179      
180         # relative matching
181         if ($glob =~ m!^\./!) {
182     -           $from=~s!/?[^/]+$!!;
183     +           $from=~s!/?[^/]*$!!;
184                 $glob=~s!^\./!!;
185                 $glob="$from/$glob" if length $from;
186         }
187
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
191 to "A/B/C/index".
192 Here it is:  --Per Bothner
193
194     --- IkiWiki/Render.pm~  2007-01-11 15:01:51.000000000 -0800
195     +++ IkiWiki/Render.pm   2007-02-02 22:24:12.000000000 -0800
196     @@ -60,9 +60,9 @@
197             foreach my $dir (reverse split("/", $page)) {
198                     if (! $skip) {
199                             $path.="../";
200     -                       unshift @ret, { url => $path.htmlpage($dir), page => pagetitle($dir) };
201     +                       unshift @ret, { url => abs2rel(htmlpage(bestlink($page, $dir)), dirname($page)), page => pagetitle($dir) };
202                     }
203     -               else {
204     +               elsif ($dir ne "index") {
205                             $skip=0;
206                     }
207             }
208
209     --- IkiWiki.pm~ 2007-01-12 12:47:09.000000000 -0800
210     +++ IkiWiki.pm  2007-02-02 18:02:16.000000000 -0800
211     @@ -315,6 +315,12 @@
212                     elsif (exists $pagecase{lc $l}) {
213                             return $pagecase{lc $l};
214                      }
215     +               else {
216     +                   my $lindex = $l . "/index";
217     +                   if (exists $links{$lindex}) {
218     +                       return $lindex;
219     +               }
220     +               }
221              } while $cwd=~s!/?[^/]+$!!;
222      
223             if (length $config{userdir} && exists $links{"$config{userdir}/".lc($link)}) {
224
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".
228
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
231
232 ---
233
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]]
235
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.
237
238 >> FWIW, [use_dirs.diff](http://iki.fi/tuomov/use_dirs.diff) applies cleanly, and works well for me. Given that it makes this behaviour optional, how about merging it? I have some follow-up patches which I'm sitting on for now. ;-) -- Ben
239
240 >>> How do you apply a patch created by svn diff? I've been curious about this for a long time. The use_dirs patch looks OK but I'd like to play with it. --Ethan
241
242 >>>> Just do `svn co svn://ikiwiki.kitenet.net/ikiwiki/trunk ikiwiki` then `cd ikiwiki && patch -p0 <use_dirs.diff`. :-) Same would work with a tarball as well.   
243
244
245 ----
246
247 First pass over Tumov's patch -- which doesn't cleanly apply anymore, so
248 I'll attach an updated and slightly modified version below.
249
250 * `urlto()` is O(N) to the number of pages in the wiki, which leads to
251   O(N^2) behavior, which could be a scalability problem. This happens because
252   of the lookup for `$to` in `%renderedfiles`, which shouldn't be necessary
253   most of the time. Couldn't it just be required that `$to` be a html page
254   name on input? Or require it be a non-html page name and always run
255   htmlpage on it.
256 * As we discussed in email, this will break handling of `foo/index.mdwn`
257   pages. Needs to be changed to generate `foo/index/index.html` for such
258   pages (though not for the toplevel `index`).
259 * This does make the resulting wikis much less browsable directly on the
260   filesystem, since `dir` to `dir/index.html` conversion is only handled by web
261   servers and so you end up browsing to a directory index all the time.
262   Wouldn't it be better to make the links themselves include the index.html?
263 * Some of the generated links are missing the trailing / , which is
264   innefficient since it leads to a http redirect when clicking on that
265   link. Seems to be limited to ".." links, and possibly only to
266   parentlinks. (Already fixed it for "." links.)
267 * It calles abs2rel about 16% more often with the patch, which makes it
268   a bit slower, since abs2rel is not very efficient. (This omits abs2rel
269   calls that might be memoized away already.) This seems to be due to one
270   extra abs2rel for the toplevel wiki page due to the nicely cleaned up code
271   in `parentlinks` -- so I'm not really complaining.. Especially since the
272   patch adds a new nice memoizable `urlto`.
273 * The rss page name generation code seems unnecesarily roundabout, I'm sure
274   that can be cleaned up somehow, perhaps by making `htmlpage` more
275   generic.
276 * `aggregate.pm` uses htmlpage in a way that breaks with its new behavior.
277   It will need to be changed as follows:
278
279 <pre>
280 Index: aggregate.pm
281 ===================================================================
282 --- aggregate.pm        (revision 2700)
283 +++ aggregate.pm        (working copy)
284 @@ -320,7 +320,7 @@
285                 # NB: This doesn't check for path length limits.
286                 eval q{use POSIX};
287                 my $max=POSIX::pathconf($config{srcdir}, &POSIX::_PC_NAME_MAX);
288 -               if (defined $max && length(htmlpage($page)) >= $max) {
289 +               if (defined $max && length(htmlfn($page)) >= $max) {
290                         $c="";
291                         $page=$feed->{dir}."/item";
292                         while (exists $IkiWiki::pagecase{lc $page.$c} ||
293 @@ -356,7 +356,7 @@
294         if (ref $feed->{tags}) {
295                 $template->param(tags => [map { tag => $_ }, @{$feed->{tags}}]);
296         }
297 -       writefile(htmlpage($guid->{page}), $config{srcdir},
298 +       writefile(htmlfn($guid->{page}), $config{srcdir},
299                 $template->output);
300  
301         # Set the mtime, this lets the build process get the right creation
302 @@ -434,4 +434,8 @@
303         return "$config{srcdir}/".htmlpage($page);
304  } #}}}
305  
306 +sub htmlfn ($) { #{{{
307 +       return shift().".html";
308 +} #}}}
309 +
310  1
311 </pre>
312
313 * `linkmap.pm` uses `htmlpage` to construct a link and should probably be
314   changed like this (untested):
315
316 <pre>
317 Index: linkmap.pm
318 ===================================================================
319 --- linkmap.pm  (revision 2700)
320 +++ linkmap.pm  (working copy)
321 @@ -50,8 +50,7 @@
322         foreach my $item (keys %links) {
323                 if (pagespec_match($item, $params{pages}, $params{page})) {
324                         my $link=htmlpage($item);
325 -                       $link=IkiWiki::abs2rel($link, IkiWiki::dirname($params{page}));
326 -                       $mapitems{$item}=$link;
327 +                       $mapitems{$item}=urlto($link, $params{destpage});
328                 }
329         }
330 </pre>
331
332 * `inline.pm` uses htmlpage and `abs2rel` to generate a link, and probably
333   needs to be changed to either use `urlto` or to call `beautify_url` like
334   htmllink does. This might work:
335
336 <pre>
337 Index: inline.pm
338 ===================================================================
339 --- inline.pm   (revision 2700)
340 +++ inline.pm   (working copy)
341 @@ -150,10 +150,7 @@
342                         # Don't use htmllink because this way the
343                         # title is separate and can be overridden by
344                         # other plugins.
345 -                       my $link=bestlink($params{page}, $page);
346 -                       $link=htmlpage($link) if defined $type;
347 -                       $link=abs2rel($link, dirname($params{destpage}));
348 -                       $template->param(pageurl => $link);
349 +                       $template->param(pageurl => urlto(bestlink($params{page}, $page), $params{destpage}));
350                         $template->param(title => pagetitle(basename($page)));
351                         $template->param(ctime => displaytime($pagectime{$page}));
352 </pre>
353
354 * `img.pm` makes some assumptions about name of the page that will be
355   linking to the image, which are probably broken.
356
357 * The changes to htmlpage's behavior probably call for the plugin
358   interface version number to be changed.
359
360 --[[Joey]]
361
362 Updated version of Tumov's patch follows:
363
364 <pre>
365 Index: IkiWiki/Render.pm
366 ===================================================================
367 --- IkiWiki/Render.pm   (revision 2700)
368 +++ IkiWiki/Render.pm   (working copy)
369 @@ -32,8 +32,8 @@
370         my @links;
371         return unless $backlinks{$page};
372         foreach my $p (keys %{$backlinks{$page}}) {
373 -               my $href=abs2rel(htmlpage($p), dirname($page));
374 -                       
375 +               my $href=urlto($p, $page);
376 +                
377                 # Trim common dir prefixes from both pages.
378                 my $p_trimmed=$p;
379                 my $page_trimmed=$page;
380 @@ -55,18 +55,14 @@
381         my @ret;
382         my $pagelink="";
383         my $path="";
384 -       my $skip=1;
385 +       my $title=$config{wikiname};
386 +       
387         return if $page eq 'index'; # toplevel
388 -       foreach my $dir (reverse split("/", $page)) {
389 -               if (! $skip) {
390 -                       $path.="../";
391 -                       unshift @ret, { url => $path.htmlpage($dir), page => pagetitle($dir) };
392 -               }
393 -               else {
394 -                       $skip=0;
395 -               }
396 +       foreach my $dir (split("/", $page)) {
397 +               push @ret, { url => urlto($path, $page), page => $title };
398 +               $path.="/".$dir;
399 +               $title=pagetitle($dir);
400         }
401 -       unshift @ret, { url => length $path ? $path : ".", page => $config{wikiname} };
402         return @ret;
403  } #}}}
404  
405 Index: IkiWiki/Plugin/inline.pm
406 ===================================================================
407 --- IkiWiki/Plugin/inline.pm    (revision 2700)
408 +++ IkiWiki/Plugin/inline.pm    (working copy)
409 @@ -110,8 +110,8 @@
410  
411         add_depends($params{page}, $params{pages});
412  
413 -       my $rssurl=rsspage(basename($params{page}));
414 -       my $atomurl=atompage(basename($params{page}));
415 +       my $rssurl=basename(rsspage($params{page}));
416 +       my $atomurl=basename(atompage($params{page}));
417         my $ret="";
418  
419         if (exists $params{rootpage} && $config{cgiurl}) {
420 @@ -151,8 +151,7 @@
421                         # title is separate and can be overridden by
422                         # other plugins.
423                         my $link=bestlink($params{page}, $page);
424 -                       $link=htmlpage($link) if defined $type;
425 -                       $link=abs2rel($link, dirname($params{destpage}));
426 +                       $link=urlto($link, $params{destpage});
427                         $template->param(pageurl => $link);
428                         $template->param(title => pagetitle(basename($page)));
429                         $template->param(ctime => displaytime($pagectime{$page}));
430 @@ -205,15 +204,17 @@
431                 }
432         
433                 if ($rss) {
434 -                       will_render($params{page}, rsspage($params{page}));
435 -                       writefile(rsspage($params{page}), $config{destdir},
436 +                       my $rssp=rsspage($params{page});
437 +                       will_render($params{page}, $rssp);
438 +                       writefile($rssp, $config{destdir},
439                                 genfeed("rss", $rssurl, $desc, $params{page}, @list));
440                         $toping{$params{page}}=1 unless $config{rebuild};
441                         $feedlinks{$params{destpage}}=qq{<link rel="alternate" type="application/rss+xml" title="RSS" href="$rssurl" />};
442                 }
443                 if ($atom) {
444 -                       will_render($params{page}, atompage($params{page}));
445 -                       writefile(atompage($params{page}), $config{destdir},
446 +                       my $atomp=atompage($params{page});
447 +                       will_render($params{page}, $atomp);
448 +                       writefile($atomp, $config{destdir},
449                                 genfeed("atom", $atomurl, $desc, $params{page}, @list));
450                         $toping{$params{page}}=1 unless $config{rebuild};
451                         $feedlinks{$params{destpage}}=qq{<link rel="alternate" type="application/atom+xml" title="Atom" href="$atomurl" />};
452 @@ -288,16 +289,25 @@
453         return $content;
454  } #}}}
455  
456 +sub basepage ($) { #{{{
457 +       my $page=shift;
458 +       
459 +       $page=htmlpage($page);
460 +       $page =~ s/\.html$//;
461 +       
462 +       return $page;
463 +} #}}}
464 +
465  sub rsspage ($) { #{{{
466         my $page=shift;
467  
468 -       return $page.".rss";
469 +       return basepage($page).".rss";
470  } #}}}
471  
472  sub atompage ($) { #{{{
473         my $page=shift;
474  
475 -       return $page.".atom";
476 +       return basepage($page).".atom";
477  } #}}}
478  
479  sub genfeed ($$$$@) { #{{{
480 Index: ikiwiki.in
481 ===================================================================
482 --- ikiwiki.in  (revision 2700)
483 +++ ikiwiki.in  (working copy)
484 @@ -46,6 +46,7 @@
485                         "sslcookie!" => \$config{sslcookie},
486                         "httpauth!" => \$config{httpauth},
487                         "userdir=s" => \$config{userdir},
488 +                       "usedirs!" => \$config{usedirs},
489                         "exclude=s@" => sub {
490                                 push @{$config{wiki_file_prune_regexps}}, $_[1];
491                         },
492 Index: doc/usage.mdwn
493 ===================================================================
494 --- doc/usage.mdwn      (revision 2700)
495 +++ doc/usage.mdwn      (working copy)
496 @@ -244,6 +244,10 @@
497  
498    Log to syslog(3).
499  
500 +* --usedirs
501 +
502 +  Create output files named page/index.html instead of page.html.
503 +
504  * --w3mmode, --no-w3mmode
505  
506    Enable [[w3mmode]], which allows w3m to use ikiwiki as a local CGI script,
507 Index: doc/plugins/write.mdwn
508 ===================================================================
509 --- doc/plugins/write.mdwn      (revision 2700)
510 +++ doc/plugins/write.mdwn      (working copy)
511 @@ -412,6 +412,10 @@
512  
513  This is the standard gettext function, although slightly optimised.
514  
515 +#### `urlto($$)`
516 +
517 +Construct a relative url to the first parameter from the second.
518 +
519  ## RCS plugins
520  
521  ikiwiki's support for revision control systems also uses pluggable perl
522 Index: doc/ikiwiki.setup
523 ===================================================================
524 --- doc/ikiwiki.setup   (revision 2700)
525 +++ doc/ikiwiki.setup   (working copy)
526 @@ -94,6 +94,8 @@
527         syslog => 0,
528         # To link to user pages in a subdirectory of the wiki.
529         #userdir => "users",
530 +       # To enable alternate output filenames.
531 +       #usedirs => 1,
532  
533         # To add plugins, list them here.
534         #add_plugins => [qw{goodstuff openid search wikitext camelcase
535 Index: IkiWiki.pm
536 ===================================================================
537 --- IkiWiki.pm  (revision 2700)
538 +++ IkiWiki.pm  (working copy)
539 @@ -14,7 +14,7 @@
540  use Exporter q{import};
541  our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
542                   bestlink htmllink readfile writefile pagetype srcfile pagename
543 -                 displaytime will_render gettext
544 +                 displaytime will_render gettext urlto
545                   %config %links %renderedfiles %pagesources);
546  our $VERSION = 1.02; # plugin interface version, next is ikiwiki version
547  our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
548 @@ -72,6 +72,7 @@
549         sslcookie => 0,
550         httpauth => 0,
551         userdir => "",
552 +       usedirs => 0
553  } #}}}
554     
555  sub checkconfig () { #{{{
556 @@ -226,7 +227,11 @@
557  sub htmlpage ($) { #{{{
558         my $page=shift;
559  
560 -       return $page.".html";
561 +       if (! $config{usedirs} || $page =~ /^index$/ || $page =~ /\/index$/) {
562 +               return $page.".html";
563 +       } else {
564 +               return $page."/index.html"; 
565 +       }
566  } #}}}
567  
568  sub srcfile ($) { #{{{
569 @@ -390,6 +395,7 @@
570  
571         return "$config{url}/" if ! defined $page;
572         
573 +       $page=htmlpage($page);
574         $page=~s/[^\/]+$//;
575         $page=~s/[^\/]+\//..\//g;
576         return $page;
577 @@ -419,6 +425,29 @@
578                         $config{timeformat}, localtime($time)));
579  } #}}}
580  
581 +sub beautify_url ($) { #{{{
582 +       my $url=shift;
583 +
584 +       $url =~ s!/index.html$!/!;
585 +       $url =~ s!^$!./!; # Browsers don't like empty links...
586 +
587 +       return $url;
588 +} #}}}
589 +
590 +sub urlto ($$) { #{{{
591 +       my $to=shift;
592 +       my $from=shift;
593 +
594 +       if (length $to &&
595 +           ! grep { $_ eq $to } map { @{$_} } values %renderedfiles) {
596 +               $to=htmlpage($to);
597 +       }
598 +
599 +       my $link = abs2rel($to, dirname(htmlpage($from)));
600 +
601 +       return beautify_url($link);
602 +} #}}}
603 +
604  sub htmllink ($$$;@) { #{{{
605         my $lpage=shift; # the page doing the linking
606         my $page=shift; # the page that will contain the link (different for inline)
607 @@ -454,7 +483,8 @@
608                         "\">?</a>$linktext</span>"
609         }
610         
611 -       $bestlink=abs2rel($bestlink, dirname($page));
612 +       $bestlink=abs2rel($bestlink, dirname(htmlpage($page)));
613 +       $bestlink=beautify_url($bestlink);
614         
615         if (! $opts{noimageinline} && isinlinableimage($bestlink)) {
616                 return "<img src=\"$bestlink\" alt=\"$linktext\" />";
617 </pre>