26269c9ce9227041238b122d272256ded9f4aaa3
[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 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`...).
8
9 Suggestions welcome.
10
11 -- [[Will]]
12
13 > 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);`
14
15     diff --git a/IkiWiki.pm b/IkiWiki.pm
16     index 4e4da11..853f905 100644
17     --- a/IkiWiki.pm
18     +++ b/IkiWiki.pm
19     @@ -618,7 +618,7 @@ sub pagename ($) { #{{{
20      
21         my $type=pagetype($file);
22         my $page=$file;
23     -   $page=~s/\Q.$type\E*$// if defined $type;
24     +   $page=~s/\Q.$type\E*$// if defined $type && !$hooks{htmlize}{$type}{leavesuffix};
25         return $page;
26      } #}}}
27      
28     diff --git a/t/pagename.t b/t/pagename.t
29     index 96e6a87..58811b9 100755
30     --- a/t/pagename.t
31     +++ b/t/pagename.t
32     @@ -6,7 +6,7 @@ use Test::More tests => 5;
33      BEGIN { use_ok("IkiWiki"); }
34      
35      # Used internally.
36     -$IkiWiki::hooks{htmlize}{mdwn}=1;
37     +$IkiWiki::hooks{htmlize}{mdwn}{call}=1;
38      
39      is(pagename("foo.mdwn"), "foo");
40      is(pagename("foo/bar.mdwn"), "foo/bar");
41
42 ----
43
44 I wonder if this patch will also be useful:
45
46     diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
47     index 752d176..3f1b67b 100644
48     --- a/IkiWiki/Render.pm
49     +++ b/IkiWiki/Render.pm
50     @@ -279,7 +279,11 @@ sub refresh () { #{{{
51                                 else {
52                                         $f=~s/^\Q$config{srcdir}\E\/?//;
53                                         push @files, $f;
54     -                                   $exists{pagename($f)}=1;
55     +                                   my $pagename = pagename($f);
56     +                                   if ($exists{$pagename}) {
57     +                                           warn(sprintf(gettext("Page %s has multiple possible source pages"), $pagename)."\n");
58     +                                   }
59     +                                   $exists{$pagename}=1;
60                                 }
61                         }
62                 },