]> sipb.mit.edu Git - ikiwiki.git/blob - doc/patchqueue/index.html_allowed.mdwn
web commit by http://ethan.betacantrips.com/: Per Bothner, you're my hero!
[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.
3
4 I independently implemented a similar, but smaller patch.
5 (It's smaller because I only care about rendering; not CGI, for example.)
6 The key to this patch is that "A/B/C" is treated as equivalent
7 to "A/B/C/index".
8 Here it is:  --Per Bothner
9
10     --- IkiWiki/Render.pm~  2007-01-11 15:01:51.000000000 -0800
11     +++ IkiWiki/Render.pm   2007-02-02 22:24:12.000000000 -0800
12     @@ -60,9 +60,9 @@
13             foreach my $dir (reverse split("/", $page)) {
14                     if (! $skip) {
15                             $path.="../";
16     -                       unshift @ret, { url => $path.htmlpage($dir), page => pagetitle($dir) };
17     +                       unshift @ret, { url => abs2rel(htmlpage(bestlink($page, $dir)), dirname($page)), page => pagetitle($dir) };
18                     }
19     -               else {
20     +               elsif ($dir ne "index") {
21                             $skip=0;
22                     }
23             }
24
25     --- IkiWiki.pm~ 2007-01-12 12:47:09.000000000 -0800
26     +++ IkiWiki.pm  2007-02-02 18:02:16.000000000 -0800
27     @@ -315,6 +315,12 @@
28                     elsif (exists $pagecase{lc $l}) {
29                             return $pagecase{lc $l};
30                      }
31     +               else {
32     +                   my $lindex = $l . "/index";
33     +                   if (exists $links{$lindex}) {
34     +                       return $lindex;
35     +               }
36     +               }
37              } while $cwd=~s!/?[^/]+$!!;
38      
39             if (length $config{userdir} && exists $links{"$config{userdir}/".lc($link)}) {
40
41 Note I handle setting the url; slightly differently.
42 Also note that an initial "index" is ignored.  I.e. a
43 page "A/B/index.html" is treated as "A/B".
44
45 > Actually, your patch is shorter because it's more elegant and better :)
46 > I'm withdrawing my old patch, because yours is much more in line with
47 > ikiwiki's design and architecture.
48 > I would like to make one suggestion to your patch, which is:
49
50     diff -urX ignorepats clean-ikidev/IkiWiki/Render.pm ikidev/IkiWiki/Render.pm
51     --- clean-ikidev/IkiWiki/Render.pm      2007-02-25 12:26:54.745833000 -0800
52     +++ ikidev/IkiWiki/Render.pm    2007-02-25 12:56:40.711261000 -0800
53     @@ -106,11 +106,15 @@
54             if ($actions) {
55                     $template->param(have_actions => 1);
56             }
57     +       my $title = $page;
58     +       if ($page =~ m!/index$!){
59     +               $title =~ s!/index$!!;
60     +       }
61     
62             $template->param(
63                     title => $page eq 'index'
64                             ? $config{wikiname}
65     -                       : pagetitle(basename($page)),
66     +                       : pagetitle(basename($title)),
67                     wikiname => $config{wikiname},
68                     parentlinks => [parentlinks($page)],
69                     content => $content,
70
71 > This way foo/index gets "foo" as its title, not "index". --Ethan
72
73 ---
74
75 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]]
76
77 > 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.
78
79 >> 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
80
81 >>> 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
82
83 >>>> 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.   
84
85 >>>>> Sorry, I'm dumb. I'm so used to doing -p1 that doing -p0 never occurred to me; I thought the patch format generated by svn diff was just "wrong". --Ethan
86
87 ----
88
89 First pass over Tumov's patch -- which doesn't cleanly apply anymore, so
90 I'll attach an updated and modified version below. --[[Joey]]
91
92 * As we discussed in email, this will break handling of `foo/index.mdwn`
93   pages. Needs to be changed to generate `foo/index/index.html` for such
94   pages (though not for the toplevel `index`).
95
96   >> Can someone elaborate on this? What's broken about it? Will pages
97   >> foo/index/index.html include foo/index in their parentlinks? --Ethan
98
99   >>> Presently the patch does not move `foo/index.type` as `foo/index/index.html`, but renders
100   >>> it as `foo/index.html`, not because I particularly want that (except for the top-level one, of
101   >>> course), but because it could be done :). This, however, conflicts with a `foo.mdwn`
102   >>> rendered as `foo/index.html`. The easiest and cleanest way to fix this, is to simply
103   >>> not handle `index` in such a special manner -- except for the top-level one. --[[tuomov]]
104
105   >>>> Oh, I see, this patch doesn't address wanting to use foo/index.mdwn as 
106   >>>> an input page. Hmm. --Ethan
107
108   >>>>> No, it doesn't. I originally also was after that, but after discussing the
109   >>>>> complexities of supporting that with Joey, came up with this simpler scheme
110   >>>>> without many of those issues. It is the output that I primarily care about, anyway,
111   >>>>> and I do, in fact, find the present input file organisation quite nice. The output
112   >>>>> locations just aren't very good for conversion of an existing site to ikiwiki, and do
113   >>>>> make for rather ugly URLs with the .html extensions. (I do often type some URLs
114   >>>>> out of memory, when they're gone from the browser's completion history, and the
115   >>>>> .html makes that more laboursome.)
116
117   >>>>>> I support your decision, but now this wiki page serves two different patches :).
118   >>>>>> Can we split them somehow?
119   >>>>>> What are the complexities involved?
120   >>>>>> I think I overcomplicated it a little with my patch, and Per Bothner's gets 
121   >>>>>> much closer to the heart of it. --Ethan
122
123 * This does make the resulting wikis much less browsable directly on the
124   filesystem, since `dir` to `dir/index.html` conversion is only handled by web
125   servers and so you end up browsing to a directory index all the time.
126   Wouldn't it be better to make the links themselves include the index.html?
127   (Although that would mean that [[bugs/broken_parentlinks]] would not be
128   fixed en passant by this patch..)
129
130      > Yes, the sites are not that browsable on the FS (I blame the browsers
131      > for being stupid!), but linking to the directory produces so much
132      > cleaner URLs for the Web, that I specifically want it. This is,
133      > after all, an optional arrangement. 
134
135      >> It's optional for *now* ... I suppose that I could make adding the
136      >> index.html yet another option. I'm not _that_ fond of optioons
137      >> however. --[[Joey]]
138
139      >>> It is worth noting, that with this patch, you _can_ render the local
140      >>> copy in the present manner, while rendering the Web copy under
141      >>> directories. So no extra options are really needed for local browsing, 
142      >>> unless you also want to serve the same copy over the Web, which I
143      >>> doubt. --[[tuomov]]
144
145 * Some of the generated links are missing the trailing / , which is
146   innefficient since it leads to a http redirect when clicking on that
147   link. Seems to be limited to ".." links, and possibly only to
148   parentlinks. (Already fixed it for "." links.)
149
150       > The solution seems to be to add to `urlto` the following snippet,
151       > which might also help with the next point. (Sorry, no updated patch
152       > yet. Should be on my way out in the cold anyway...)
153
154         if ( !length $to ) {
155                 return baseurl($from);
156         }
157  
158       >> Indeed, this brings the number of abs2rels closer to par, as well
159       >> as fixing the .. links. --[[Joey]]
160
161 * It calles abs2rel about 16% more often with the patch, which makes it
162   a bit slower, since abs2rel is not very efficient. (This omits abs2rel
163   calls that might be memoized away already.) This seems to be due to one
164   extra abs2rel for the toplevel wiki page due to the nicely cleaned up code
165   in `parentlinks` -- so I'm not really complaining.. Especially since the
166   patch adds a new nice memoizable `urlto`.
167 * The rss page name generation code seems unnecesarily roundabout, I'm sure
168   that can be cleaned up somehow, perhaps by making `htmlpage` more
169   generic.
170
171      > Something like `targetpage(basename, extension)`?
172
173      >> Yes exactly. It might also be possible to remove htmlpage from the
174      >> plugin interface entirely (in favour of urlto), which would be a
175      >> good time to make such a changes. Not required to accept this patch
176      >> though.
177
178      >>> [...] in fact, all uses of htmlpage in the plugins are used to
179      >>> construct an absolute address: the absolute url in most cases, so an `absurl`
180      >>> call could be added to be used instead of htmlpage
181      >>> --[[tuomov]]
182
183      >>>> Or it could use urlto("index", $page) instead. --[[Joey]]
184
185      >>>>> That is, however, a relative URL, and maybe an absolute one
186      >>>>> is wanted. Perhaps `urlto($targetpage)` should return the
187      >>>>> absolute version --[[tuomov]]
188
189 * > and something else in the
190   > aggregate plugin (above), that I also think isn't what's wanted:
191   > aren't `foo.html` pages also "rendered", so that they get moved as `foo/index.html`?
192   > --[[tuomov]]
193
194   >> Yes, the aggregate plugin will save the files as foo.html in the
195   >> sourcedir, and that will result in foo/index.html in the web site, same
196   >> as any other page. --[[Joey]]
197
198 * `img.pm` makes some assumptions about name of the page that will be
199   linking to the image, which are probably broken.
200
201 * The changes to htmlpage's behavior probably call for the plugin
202   interface version number to be changed.
203
204 Latest version of my patch... with most of the stuff that's been discussed, including `targetpage`.
205 Also available [here](http://iki.fi/tuomov/use_dirs-20070221.diff). (BTW, this posting, applying, and
206 updating of plain-old-diffs containing all the previous changes is starting to be painful. Reminds
207 me why I use darcs..) --[[tuomov]]
208
209 <pre>
210 Index: IkiWiki.pm
211 ===================================================================
212 --- IkiWiki.pm  (revision 2806)
213 +++ IkiWiki.pm  (working copy)
214 @@ -14,7 +14,7 @@
215  use Exporter q{import};
216  our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
217                   bestlink htmllink readfile writefile pagetype srcfile pagename
218 -                 displaytime will_render gettext
219 +                 displaytime will_render gettext urlto targetpage
220                   %config %links %renderedfiles %pagesources);
221  our $VERSION = 1.02; # plugin interface version, next is ikiwiki version
222  our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
223 @@ -73,6 +73,7 @@
224         sslcookie => 0,
225         httpauth => 0,
226         userdir => "",
227 +       usedirs => 0
228  } #}}}
229     
230  sub checkconfig () { #{{{
231 @@ -224,10 +225,21 @@
232         return $page;
233  } #}}}
234  
235 +sub targetpage ($$) { #{{{
236 +       my $page=shift;
237 +       my $ext=shift;
238 +       
239 +       if (! $config{usedirs} || $page =~ /^index$/ ) {
240 +               return $page.".".$ext;
241 +       } else {
242 +               return $page."/index.".$ext;
243 +       }
244 +} #}}}
245 +
246  sub htmlpage ($) { #{{{
247         my $page=shift;
248 -
249 -       return $page.".html";
250 +       
251 +       return targetpage($page, "html");
252  } #}}}
253  
254  sub srcfile ($) { #{{{
255 @@ -393,6 +405,7 @@
256  
257         return "$config{url}/" if ! defined $page;
258         
259 +       $page=htmlpage($page);
260         $page=~s/[^\/]+$//;
261         $page=~s/[^\/]+\//..\//g;
262         return $page;
263 @@ -422,6 +435,32 @@
264                         $config{timeformat}, localtime($time)));
265  } #}}}
266  
267 +sub beautify_url ($) { #{{{
268 +       my $url=shift;
269 +
270 +       $url =~ s!/index.html$!/!;
271 +       $url =~ s!^$!./!; # Browsers don't like empty links...
272 +
273 +       return $url;
274 +} #}}}
275 +
276 +sub urlto ($$) { #{{{
277 +       my $to=shift;
278 +       my $from=shift;
279 +
280 +       if (! length $to) {
281 +               return beautify_url(baseurl($from));
282 +       }
283 +
284 +       if (! grep { $_ eq $to } map { @{$_} } values %renderedfiles) {
285 +               $to=htmlpage($to);
286 +       }
287 +
288 +       my $link = abs2rel($to, dirname(htmlpage($from)));
289 +
290 +       return beautify_url($link);
291 +} #}}}
292 +
293  sub htmllink ($$$;@) { #{{{
294         my $lpage=shift; # the page doing the linking
295         my $page=shift; # the page that will contain the link (different for inline)
296 @@ -457,7 +496,8 @@
297                         "\">?</a>$linktext</span>"
298         }
299         
300 -       $bestlink=abs2rel($bestlink, dirname($page));
301 +       $bestlink=abs2rel($bestlink, dirname(htmlpage($page)));
302 +       $bestlink=beautify_url($bestlink);
303         
304         if (! $opts{noimageinline} && isinlinableimage($bestlink)) {
305                 return "<img src=\"$bestlink\" alt=\"$linktext\" />";
306 Index: IkiWiki/Render.pm
307 ===================================================================
308 --- IkiWiki/Render.pm   (revision 2806)
309 +++ IkiWiki/Render.pm   (working copy)
310 @@ -32,8 +32,8 @@
311         my @links;
312         return unless $backlinks{$page};
313         foreach my $p (keys %{$backlinks{$page}}) {
314 -               my $href=abs2rel(htmlpage($p), dirname($page));
315 -                       
316 +               my $href=urlto($p, $page);
317 +                
318                 # Trim common dir prefixes from both pages.
319                 my $p_trimmed=$p;
320                 my $page_trimmed=$page;
321 @@ -55,18 +55,14 @@
322         my @ret;
323         my $pagelink="";
324         my $path="";
325 -       my $skip=1;
326 +       my $title=$config{wikiname};
327 +       
328         return if $page eq 'index'; # toplevel
329 -       foreach my $dir (reverse split("/", $page)) {
330 -               if (! $skip) {
331 -                       $path.="../";
332 -                       unshift @ret, { url => $path.htmlpage($dir), page => pagetitle($dir) };
333 -               }
334 -               else {
335 -                       $skip=0;
336 -               }
337 +       foreach my $dir (split("/", $page)) {
338 +               push @ret, { url => urlto($path, $page), page => $title };
339 +               $path.="/".$dir;
340 +               $title=pagetitle($dir);
341         }
342 -       unshift @ret, { url => length $path ? $path : ".", page => $config{wikiname} };
343         return @ret;
344  } #}}}
345  
346 Index: IkiWiki/Plugin/inline.pm
347 ===================================================================
348 --- IkiWiki/Plugin/inline.pm    (revision 2806)
349 +++ IkiWiki/Plugin/inline.pm    (working copy)
350 @@ -110,8 +110,8 @@
351  
352         add_depends($params{page}, $params{pages});
353  
354 -       my $rssurl=rsspage(basename($params{page}));
355 -       my $atomurl=atompage(basename($params{page}));
356 +       my $rssurl=basename(rsspage($params{page}));
357 +       my $atomurl=basename(atompage($params{page}));
358         my $ret="";
359  
360         if (exists $params{rootpage} && $config{cgiurl}) {
361 @@ -150,10 +150,7 @@
362                         # Don't use htmllink because this way the
363                         # title is separate and can be overridden by
364                         # other plugins.
365 -                       my $link=bestlink($params{page}, $page);
366 -                       $link=htmlpage($link) if defined $type;
367 -                       $link=abs2rel($link, dirname($params{destpage}));
368 -                       $template->param(pageurl => $link);
369 +                       $template->param(pageurl => urlto(bestlink($params{page}, $page), $params{destpage}));
370                         $template->param(title => pagetitle(basename($page)));
371                         $template->param(ctime => displaytime($pagectime{$page}));
372  
373 @@ -205,15 +202,17 @@
374                 }
375         
376                 if ($rss) {
377 -                       will_render($params{page}, rsspage($params{page}));
378 -                       writefile(rsspage($params{page}), $config{destdir},
379 +                       my $rssp=rsspage($params{page});
380 +                       will_render($params{page}, $rssp);
381 +                       writefile($rssp, $config{destdir},
382                                 genfeed("rss", $rssurl, $desc, $params{page}, @list));
383                         $toping{$params{page}}=1 unless $config{rebuild};
384                         $feedlinks{$params{destpage}}=qq{<link rel="alternate" type="application/rss+xml" title="RSS" href="$rssurl" />};
385                 }
386                 if ($atom) {
387 -                       will_render($params{page}, atompage($params{page}));
388 -                       writefile(atompage($params{page}), $config{destdir},
389 +                       my $atomp=atompage($params{page});
390 +                       will_render($params{page}, $atomp);
391 +                       writefile($atomp, $config{destdir},
392                                 genfeed("atom", $atomurl, $desc, $params{page}, @list));
393                         $toping{$params{page}}=1 unless $config{rebuild};
394                         $feedlinks{$params{destpage}}=qq{<link rel="alternate" type="application/atom+xml" title="Atom" href="$atomurl" />};
395 @@ -288,16 +287,21 @@
396         return $content;
397  } #}}}
398  
399 -sub rsspage ($) { #{{{
400 +sub basepage ($) { #{{{
401         my $page=shift;
402 +       
403 +       $page=htmlpage($page);
404 +       $page =~ s/\.html$//;
405 +       
406 +       return $page;
407 +} #}}}
408  
409 -       return $page.".rss";
410 +sub rsspage ($) { #{{{
411 +       return targetpage(shift, "rss");
412  } #}}}
413  
414  sub atompage ($) { #{{{
415 -       my $page=shift;
416 -
417 -       return $page.".atom";
418 +       return targetpage(shift, "atom");
419  } #}}}
420  
421  sub genfeed ($$$$@) { #{{{
422 Index: IkiWiki/Plugin/aggregate.pm
423 ===================================================================
424 --- IkiWiki/Plugin/aggregate.pm (revision 2806)
425 +++ IkiWiki/Plugin/aggregate.pm (working copy)
426 @@ -320,7 +320,7 @@
427                 # NB: This doesn't check for path length limits.
428                 eval q{use POSIX};
429                 my $max=POSIX::pathconf($config{srcdir}, &POSIX::_PC_NAME_MAX);
430 -               if (defined $max && length(htmlpage($page)) >= $max) {
431 +               if (defined $max && length(htmlfn($page)) >= $max) {
432                         $c="";
433                         $page=$feed->{dir}."/item";
434                         while (exists $IkiWiki::pagecase{lc $page.$c} ||
435 @@ -356,7 +356,7 @@
436         if (ref $feed->{tags}) {
437                 $template->param(tags => [map { tag => $_ }, @{$feed->{tags}}]);
438         }
439 -       writefile(htmlpage($guid->{page}), $config{srcdir},
440 +       writefile(htmlfn($guid->{page}), $config{srcdir},
441                 $template->output);
442  
443         # Set the mtime, this lets the build process get the right creation
444 @@ -434,4 +434,8 @@
445         return "$config{srcdir}/".htmlpage($page);
446  } #}}}
447  
448 +sub htmlfn ($) { #{{{
449 +       return shift().".html";
450 +} #}}}
451 +
452  1
453 Index: IkiWiki/Plugin/linkmap.pm
454 ===================================================================
455 --- IkiWiki/Plugin/linkmap.pm   (revision 2806)
456 +++ IkiWiki/Plugin/linkmap.pm   (working copy)
457 @@ -49,9 +49,7 @@
458         my %mapitems = ();
459         foreach my $item (keys %links) {
460                 if (pagespec_match($item, $params{pages}, $params{page})) {
461 -                       my $link=htmlpage($item);
462 -                       $link=IkiWiki::abs2rel($link, IkiWiki::dirname($params{page}));
463 -                       $mapitems{$item}=$link;
464 +                       $mapitems{$item}=urlto($item, $params{destpage});
465                 }
466         }
467  
468 Index: doc/usage.mdwn
469 ===================================================================
470 --- doc/usage.mdwn      (revision 2806)
471 +++ doc/usage.mdwn      (working copy)
472 @@ -244,6 +244,10 @@
473  
474    Log to syslog(3).
475  
476 +* --usedirs
477 +
478 +  Create output files named page/index.html instead of page.html.
479 +
480  * --w3mmode, --no-w3mmode
481  
482    Enable [[w3mmode]], which allows w3m to use ikiwiki as a local CGI script,
483 Index: doc/plugins/write.mdwn
484 ===================================================================
485 --- doc/plugins/write.mdwn      (revision 2806)
486 +++ doc/plugins/write.mdwn      (working copy)
487 @@ -412,6 +412,10 @@
488  
489  This is the standard gettext function, although slightly optimised.
490  
491 +#### `urlto($$)`
492 +
493 +Construct a relative url to the first parameter from the second.
494 +
495  ## RCS plugins
496  
497  ikiwiki's support for revision control systems also uses pluggable perl
498 Index: doc/ikiwiki.setup
499 ===================================================================
500 --- doc/ikiwiki.setup   (revision 2806)
501 +++ doc/ikiwiki.setup   (working copy)
502 @@ -94,6 +94,8 @@
503         syslog => 0,
504         # To link to user pages in a subdirectory of the wiki.
505         #userdir => "users",
506 +       # To enable alternate output filenames.
507 +       #usedirs => 1,
508  
509         # To add plugins, list them here.
510         #add_plugins => [qw{goodstuff openid search wikitext camelcase
511 </pre>