]> sipb.mit.edu Git - ikiwiki.git/blob - doc/bugs/multiple_pages_with_same_name.mdwn
there is now a patch for this too, in my repo
[ikiwiki.git] / doc / bugs / multiple_pages_with_same_name.mdwn
1 I'm just working on an updated solution to [[todo/automatic_use_of_syntax_plugin_on_source_code_files]] (see also [[plugins/contrib/highlightcode]] or [[plugins/contrib/sourcehighlight]]).
2
3 I realised that this is going to have problems when you ask it to process `.c` and `.h` files with the same base name.  e.g. `hello.c` and `hello.h`.
4
5 I tested it briefly with `test.java` and `test.mdwn` just to see what would happen.  Things got quite strange.  The source-highlighting plugin was called (probably for the java file), but then when it calls `pagetype($pagesources{$page})` to figure out the file type, that function returns `mdwn`, which confuses things somewhat.
6
7 > This is a known possible point of confusion. If there are multiple source
8 > files, it will render them both, in an arbitrary sequence, so one "wins".
9 > --[[Joey]]
10
11 Anyway, I'm thinking about possible solutions.  The best option I've come up with so far is: when registering an htmlize hook, add a new optional paramter 'keep_extension'.  This would make a source file of `hello.c` generate a page with name `hello.c` rather than the current `hello`.  This would keep the pages unique (until someone makes `hello.c.mdwn`...).
12
13 Suggestions welcome.
14
15 -- [[Will]]
16
17 > Ok, this turned out not to be a hard change.  [[patch]] is below.  With this patch you can tell IkiWiki not to drop the suffix when you register a hook: `hook(type => "htmlize", id => $lang, call => \&htmlize, leavesuffix => 1);`
18
19 >> I think that's a good solution to the problem that most syntax plugins
20 >> have struggled with. It makes sense. It doesn't solve the case where
21 >> you have source files without any extension (eg `Makefile`), but at
22 >> least it covers the common cases.
23 >>
24 >> I'm going to be annoying and call it "keepextension", otherwise, applied
25 >> as-is. --[[Joey]] [[done]]
26
27     diff --git a/IkiWiki.pm b/IkiWiki.pm
28     index 4e4da11..853f905 100644
29     --- a/IkiWiki.pm
30     +++ b/IkiWiki.pm
31     @@ -618,7 +618,7 @@ sub pagename ($) {
32      
33         my $type=pagetype($file);
34         my $page=$file;
35     -   $page=~s/\Q.$type\E*$// if defined $type;
36     +   $page=~s/\Q.$type\E*$// if defined $type && !$hooks{htmlize}{$type}{leavesuffix};
37         return $page;
38      }
39      
40     diff --git a/t/pagename.t b/t/pagename.t
41     index 96e6a87..58811b9 100755
42     --- a/t/pagename.t
43     +++ b/t/pagename.t
44     @@ -6,7 +6,7 @@ use Test::More tests => 5;
45      BEGIN { use_ok("IkiWiki"); }
46      
47      # Used internally.
48     -$IkiWiki::hooks{htmlize}{mdwn}=1;
49     +$IkiWiki::hooks{htmlize}{mdwn}{call}=1;
50      
51      is(pagename("foo.mdwn"), "foo");
52      is(pagename("foo/bar.mdwn"), "foo/bar");
53
54 ----
55
56 I wonder if this patch will also be useful:
57
58 > Reasonable, applied.
59
60     diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
61     index 752d176..3f1b67b 100644
62     --- a/IkiWiki/Render.pm
63     +++ b/IkiWiki/Render.pm
64     @@ -279,7 +279,11 @@ sub refresh () {
65                                 else {
66                                         $f=~s/^\Q$config{srcdir}\E\/?//;
67                                         push @files, $f;
68     -                                   $exists{pagename($f)}=1;
69     +                                   my $pagename = pagename($f);
70     +                                   if ($exists{$pagename}) {
71     +                                           warn(sprintf(gettext("Page %s has multiple possible source pages"), $pagename)."\n");
72     +                                   }
73     +                                   $exists{$pagename}=1;
74                                 }
75                         }
76                 },