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.
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
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
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.
244 >>>>> 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
248 First pass over Tumov's patch -- which doesn't cleanly apply anymore, so
249 I'll attach an updated and modified version below. --[[Joey]]
251 * As we discussed in email, this will break handling of `foo/index.mdwn`
252 pages. Needs to be changed to generate `foo/index/index.html` for such
253 pages (though not for the toplevel `index`).
255 >> Can someone elaborate on this? What's broken about it? Will pages
256 >> foo/index/index.html include foo/index in their parentlinks? --Ethan
258 >>> Presently the patch does not move `foo/index.type` as `foo/index/index.html`, but renders
259 >>> it as `foo/index.html`, not because I particularly want that (except for the top-level one, of
260 >>> course), but because it could be done :). This, however, conflicts with a `foo.mdwn`
261 >>> rendered as `foo/index.html`. The easiest and cleanest way to fix this, is to simply
262 >>> not handle `index` in such a special manner -- except for the top-level one. --[[tuomov]]
264 >>>> Oh, I see, this patch doesn't address wanting to use foo/index.mdwn as
265 >>>> an input page. Hmm. --Ethan
267 >>>>> No, it doesn't. I originally also was after that, but after discussing the
268 >>>>> complexities of supporting that with Joey, came up with this simpler scheme
269 >>>>> without many of those issues. It is the output that I primarily care about, anyway,
270 >>>>> and I do, in fact, find the present input file organisation quite nice. The output
271 >>>>> locations just aren't very good for conversion of an existing site to ikiwiki, and do
272 >>>>> make for rather ugly URLs with the .html extensions. (I do often type some URLs
273 >>>>> out of memory, when they're gone from the browser's completion history, and the
274 >>>>> .html makes that more laboursome.)
276 >>>>>> I support your decision, but now this wiki page serves two different patches :).
277 >>>>>> Can we split them somehow?
278 >>>>>> What are the complexities involved?
279 >>>>>> I think I overcomplicated it a little with my patch, and Per Bothner's gets
280 >>>>>> much closer to the heart of it. --Ethan
282 * This does make the resulting wikis much less browsable directly on the
283 filesystem, since `dir` to `dir/index.html` conversion is only handled by web
284 servers and so you end up browsing to a directory index all the time.
285 Wouldn't it be better to make the links themselves include the index.html?
286 (Although that would mean that [[bugs/broken_parentlinks]] would not be
287 fixed en passant by this patch..)
289 > Yes, the sites are not that browsable on the FS (I blame the browsers
290 > for being stupid!), but linking to the directory produces so much
291 > cleaner URLs for the Web, that I specifically want it. This is,
292 > after all, an optional arrangement.
294 >> It's optional for *now* ... I suppose that I could make adding the
295 >> index.html yet another option. I'm not _that_ fond of optioons
296 >> however. --[[Joey]]
298 >>> It is worth noting, that with this patch, you _can_ render the local
299 >>> copy in the present manner, while rendering the Web copy under
300 >>> directories. So no extra options are really needed for local browsing,
301 >>> unless you also want to serve the same copy over the Web, which I
302 >>> doubt. --[[tuomov]]
304 * Some of the generated links are missing the trailing / , which is
305 innefficient since it leads to a http redirect when clicking on that
306 link. Seems to be limited to ".." links, and possibly only to
307 parentlinks. (Already fixed it for "." links.)
309 > The solution seems to be to add to `urlto` the following snippet,
310 > which might also help with the next point. (Sorry, no updated patch
311 > yet. Should be on my way out in the cold anyway...)
314 return baseurl($from);
317 >> Indeed, this brings the number of abs2rels closer to par, as well
318 >> as fixing the .. links. --[[Joey]]
320 * It calles abs2rel about 16% more often with the patch, which makes it
321 a bit slower, since abs2rel is not very efficient. (This omits abs2rel
322 calls that might be memoized away already.) This seems to be due to one
323 extra abs2rel for the toplevel wiki page due to the nicely cleaned up code
324 in `parentlinks` -- so I'm not really complaining.. Especially since the
325 patch adds a new nice memoizable `urlto`.
326 * The rss page name generation code seems unnecesarily roundabout, I'm sure
327 that can be cleaned up somehow, perhaps by making `htmlpage` more
330 > Something like `targetpage(basename, extension)`?
332 >> Yes exactly. It might also be possible to remove htmlpage from the
333 >> plugin interface entirely (in favour of urlto), which would be a
334 >> good time to make such a changes. Not required to accept this patch
337 >>> [...] in fact, all uses of htmlpage in the plugins are used to
338 >>> construct an absolute address: the absolute url in most cases, so an `absurl`
339 >>> call could be added to be used instead of htmlpage
342 >>>> Or it could use urlto("index", $page) instead. --[[Joey]]
344 >>>>> That is, however, a relative URL, and maybe an absolute one
345 >>>>> is wanted. Perhaps `urlto($targetpage)` should return the
346 >>>>> absolute version --[[tuomov]]
348 * > and something else in the
349 > aggregate plugin (above), that I also think isn't what's wanted:
350 > aren't `foo.html` pages also "rendered", so that they get moved as `foo/index.html`?
353 >> Yes, the aggregate plugin will save the files as foo.html in the
354 >> sourcedir, and that will result in foo/index.html in the web site, same
355 >> as any other page. --[[Joey]]
357 * `img.pm` makes some assumptions about name of the page that will be
358 linking to the image, which are probably broken.
360 * The changes to htmlpage's behavior probably call for the plugin
361 interface version number to be changed.
363 Latest version of my patch... with most of the stuff that's been discussed, including `targetpage`.
364 Also available [here](http://iki.fi/tuomov/use_dirs-20070221.diff). (BTW, this posting, applying, and
365 updating of plain-old-diffs containing all the previous changes is starting to be painful. Reminds
366 me why I use darcs..) --[[tuomov]]
370 ===================================================================
371 --- IkiWiki.pm (revision 2806)
372 +++ IkiWiki.pm (working copy)
374 use Exporter q{import};
375 our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
376 bestlink htmllink readfile writefile pagetype srcfile pagename
377 - displaytime will_render gettext
378 + displaytime will_render gettext urlto targetpage
379 %config %links %renderedfiles %pagesources);
380 our $VERSION = 1.02; # plugin interface version, next is ikiwiki version
381 our $version='unknown'; # VERSION_AUTOREPLACE done by Makefile, DNE
389 sub checkconfig () { #{{{
390 @@ -224,10 +225,21 @@
394 +sub targetpage ($$) { #{{{
398 + if (! $config{usedirs} || $page =~ /^index$/ ) {
399 + return $page.".".$ext;
401 + return $page."/index.".$ext;
405 sub htmlpage ($) { #{{{
408 - return $page.".html";
410 + return targetpage($page, "html");
413 sub srcfile ($) { #{{{
416 return "$config{url}/" if ! defined $page;
418 + $page=htmlpage($page);
420 $page=~s/[^\/]+\//..\//g;
423 $config{timeformat}, localtime($time)));
426 +sub beautify_url ($) { #{{{
429 + $url =~ s!/index.html$!/!;
430 + $url =~ s!^$!./!; # Browsers don't like empty links...
435 +sub urlto ($$) { #{{{
439 + if (! length $to) {
440 + return beautify_url(baseurl($from));
443 + if (! grep { $_ eq $to } map { @{$_} } values %renderedfiles) {
447 + my $link = abs2rel($to, dirname(htmlpage($from)));
449 + return beautify_url($link);
452 sub htmllink ($$$;@) { #{{{
453 my $lpage=shift; # the page doing the linking
454 my $page=shift; # the page that will contain the link (different for inline)
456 "\">?</a>$linktext</span>"
459 - $bestlink=abs2rel($bestlink, dirname($page));
460 + $bestlink=abs2rel($bestlink, dirname(htmlpage($page)));
461 + $bestlink=beautify_url($bestlink);
463 if (! $opts{noimageinline} && isinlinableimage($bestlink)) {
464 return "<img src=\"$bestlink\" alt=\"$linktext\" />";
465 Index: IkiWiki/Render.pm
466 ===================================================================
467 --- IkiWiki/Render.pm (revision 2806)
468 +++ IkiWiki/Render.pm (working copy)
471 return unless $backlinks{$page};
472 foreach my $p (keys %{$backlinks{$page}}) {
473 - my $href=abs2rel(htmlpage($p), dirname($page));
475 + my $href=urlto($p, $page);
477 # Trim common dir prefixes from both pages.
479 my $page_trimmed=$page;
485 + my $title=$config{wikiname};
487 return if $page eq 'index'; # toplevel
488 - foreach my $dir (reverse split("/", $page)) {
491 - unshift @ret, { url => $path.htmlpage($dir), page => pagetitle($dir) };
496 + foreach my $dir (split("/", $page)) {
497 + push @ret, { url => urlto($path, $page), page => $title };
499 + $title=pagetitle($dir);
501 - unshift @ret, { url => length $path ? $path : ".", page => $config{wikiname} };
505 Index: IkiWiki/Plugin/inline.pm
506 ===================================================================
507 --- IkiWiki/Plugin/inline.pm (revision 2806)
508 +++ IkiWiki/Plugin/inline.pm (working copy)
511 add_depends($params{page}, $params{pages});
513 - my $rssurl=rsspage(basename($params{page}));
514 - my $atomurl=atompage(basename($params{page}));
515 + my $rssurl=basename(rsspage($params{page}));
516 + my $atomurl=basename(atompage($params{page}));
519 if (exists $params{rootpage} && $config{cgiurl}) {
521 # Don't use htmllink because this way the
522 # title is separate and can be overridden by
524 - my $link=bestlink($params{page}, $page);
525 - $link=htmlpage($link) if defined $type;
526 - $link=abs2rel($link, dirname($params{destpage}));
527 - $template->param(pageurl => $link);
528 + $template->param(pageurl => urlto(bestlink($params{page}, $page), $params{destpage}));
529 $template->param(title => pagetitle(basename($page)));
530 $template->param(ctime => displaytime($pagectime{$page}));
532 @@ -205,15 +202,17 @@
536 - will_render($params{page}, rsspage($params{page}));
537 - writefile(rsspage($params{page}), $config{destdir},
538 + my $rssp=rsspage($params{page});
539 + will_render($params{page}, $rssp);
540 + writefile($rssp, $config{destdir},
541 genfeed("rss", $rssurl, $desc, $params{page}, @list));
542 $toping{$params{page}}=1 unless $config{rebuild};
543 $feedlinks{$params{destpage}}=qq{<link rel="alternate" type="application/rss+xml" title="RSS" href="$rssurl" />};
546 - will_render($params{page}, atompage($params{page}));
547 - writefile(atompage($params{page}), $config{destdir},
548 + my $atomp=atompage($params{page});
549 + will_render($params{page}, $atomp);
550 + writefile($atomp, $config{destdir},
551 genfeed("atom", $atomurl, $desc, $params{page}, @list));
552 $toping{$params{page}}=1 unless $config{rebuild};
553 $feedlinks{$params{destpage}}=qq{<link rel="alternate" type="application/atom+xml" title="Atom" href="$atomurl" />};
554 @@ -288,16 +287,21 @@
558 -sub rsspage ($) { #{{{
559 +sub basepage ($) { #{{{
562 + $page=htmlpage($page);
563 + $page =~ s/\.html$//;
568 - return $page.".rss";
569 +sub rsspage ($) { #{{{
570 + return targetpage(shift, "rss");
573 sub atompage ($) { #{{{
576 - return $page.".atom";
577 + return targetpage(shift, "atom");
580 sub genfeed ($$$$@) { #{{{
581 Index: IkiWiki/Plugin/aggregate.pm
582 ===================================================================
583 --- IkiWiki/Plugin/aggregate.pm (revision 2806)
584 +++ IkiWiki/Plugin/aggregate.pm (working copy)
586 # NB: This doesn't check for path length limits.
588 my $max=POSIX::pathconf($config{srcdir}, &POSIX::_PC_NAME_MAX);
589 - if (defined $max && length(htmlpage($page)) >= $max) {
590 + if (defined $max && length(htmlfn($page)) >= $max) {
592 $page=$feed->{dir}."/item";
593 while (exists $IkiWiki::pagecase{lc $page.$c} ||
595 if (ref $feed->{tags}) {
596 $template->param(tags => [map { tag => $_ }, @{$feed->{tags}}]);
598 - writefile(htmlpage($guid->{page}), $config{srcdir},
599 + writefile(htmlfn($guid->{page}), $config{srcdir},
602 # Set the mtime, this lets the build process get the right creation
604 return "$config{srcdir}/".htmlpage($page);
607 +sub htmlfn ($) { #{{{
608 + return shift().".html";
612 Index: IkiWiki/Plugin/linkmap.pm
613 ===================================================================
614 --- IkiWiki/Plugin/linkmap.pm (revision 2806)
615 +++ IkiWiki/Plugin/linkmap.pm (working copy)
618 foreach my $item (keys %links) {
619 if (pagespec_match($item, $params{pages}, $params{page})) {
620 - my $link=htmlpage($item);
621 - $link=IkiWiki::abs2rel($link, IkiWiki::dirname($params{page}));
622 - $mapitems{$item}=$link;
623 + $mapitems{$item}=urlto($item, $params{destpage});
627 Index: doc/usage.mdwn
628 ===================================================================
629 --- doc/usage.mdwn (revision 2806)
630 +++ doc/usage.mdwn (working copy)
637 + Create output files named page/index.html instead of page.html.
639 * --w3mmode, --no-w3mmode
641 Enable [[w3mmode]], which allows w3m to use ikiwiki as a local CGI script,
642 Index: doc/plugins/write.mdwn
643 ===================================================================
644 --- doc/plugins/write.mdwn (revision 2806)
645 +++ doc/plugins/write.mdwn (working copy)
648 This is the standard gettext function, although slightly optimised.
652 +Construct a relative url to the first parameter from the second.
656 ikiwiki's support for revision control systems also uses pluggable perl
657 Index: doc/ikiwiki.setup
658 ===================================================================
659 --- doc/ikiwiki.setup (revision 2806)
660 +++ doc/ikiwiki.setup (working copy)
663 # To link to user pages in a subdirectory of the wiki.
665 + # To enable alternate output filenames.
668 # To add plugins, list them here.
669 #add_plugins => [qw{goodstuff openid search wikitext camelcase