aboutsummaryrefslogtreecommitdiff
path: root/doc/bugs/multiple_pages_with_same_name.mdwn
blob: 5ddfb1f6b17bad4e992e8947095780564655f255 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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]]).

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`.

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.

> This is a known possible point of confusion. If there are multiple source
> files, it will render them both, in an arbitrary sequence, so one "wins".
> --[[Joey]]

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`...).

Suggestions welcome.

-- [[Will]]

> 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);`

>> I think that's a good solution to the problem that most syntax plugins
>> have struggled with. It makes sense. It doesn't solve the case where
>> you have source files without any extension (eg `Makefile`), but at
>> least it covers the common cases.
>>
>> I'm going to be annoying and call it "keepextension", otherwise, applied
>> as-is. --[[Joey]] [[done]]

    diff --git a/IkiWiki.pm b/IkiWiki.pm
    index 4e4da11..853f905 100644
    --- a/IkiWiki.pm
    +++ b/IkiWiki.pm
    @@ -618,7 +618,7 @@ sub pagename ($) { #{{{
     
     	my $type=pagetype($file);
     	my $page=$file;
    -	$page=~s/\Q.$type\E*$// if defined $type;
    +	$page=~s/\Q.$type\E*$// if defined $type && !$hooks{htmlize}{$type}{leavesuffix};
     	return $page;
     } #}}}
     
    diff --git a/t/pagename.t b/t/pagename.t
    index 96e6a87..58811b9 100755
    --- a/t/pagename.t
    +++ b/t/pagename.t
    @@ -6,7 +6,7 @@ use Test::More tests => 5;
     BEGIN { use_ok("IkiWiki"); }
     
     # Used internally.
    -$IkiWiki::hooks{htmlize}{mdwn}=1;
    +$IkiWiki::hooks{htmlize}{mdwn}{call}=1;
     
     is(pagename("foo.mdwn"), "foo");
     is(pagename("foo/bar.mdwn"), "foo/bar");

----

I wonder if this patch will also be useful:

> Reasonable, applied.

    diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
    index 752d176..3f1b67b 100644
    --- a/IkiWiki/Render.pm
    +++ b/IkiWiki/Render.pm
    @@ -279,7 +279,11 @@ sub refresh () { #{{{
     				else {
     					$f=~s/^\Q$config{srcdir}\E\/?//;
     					push @files, $f;
    -					$exists{pagename($f)}=1;
    +					my $pagename = pagename($f);
    +					if ($exists{$pagename}) {
    +						warn(sprintf(gettext("Page %s has multiple possible source pages"), $pagename)."\n");
    +					}
    +					$exists{$pagename}=1;
     				}
     			}
     		},