]> sipb.mit.edu Git - ikiwiki.git/blob - doc/bugs/pagetitle_function_does_not_respect_meta_titles.mdwn
11735f77007abc4205c8da81dc25d36ef1695e78
[ikiwiki.git] / doc / bugs / pagetitle_function_does_not_respect_meta_titles.mdwn
1 The `IkiWiki::pagetitle` function does not respect title changes via `meta.title`. It really should, so that links rendered with `htmllink` get the proper title in the link text.
2
3 --[[madduck]]
4
5 ----
6
7 It is possible to set a Page-Title in the meta-plugin, but that one isn't
8 reused in parentlinks. This [[patch]] may fix it.
9
10 <ul>
11 <li> I give pagetitle the full path to a page.
12 <li> I redefine the 'pagetitle'-sub to deal with it.
13 <li> to maintain compatibility for IkiWikis without the meta-plugin, i added a 'basename' to the Original-pagetitle.
14 </ul>
15
16 <pre>
17 diff -c /usr/share/perl5/IkiWiki/Render.pm.distrib /usr/share/perl5/IkiWiki/Render.pm
18 *** /usr/share/perl5/IkiWiki/Render.pm.distrib  Wed Aug  6 07:34:55 2008
19 --- /usr/share/perl5/IkiWiki/Render.pm  Tue Aug 26 23:29:32 2008
20 ***************
21 *** 102,108 ****
22         $template->param(
23                 title => $page eq 'index' 
24                         ? $config{wikiname} 
25 !                       : pagetitle(basename($page)),
26                 wikiname => $config{wikiname},
27                 content => $content,
28                 backlinks => $backlinks,
29 --- 102,108 ----
30         $template->param(
31                 title => $page eq 'index' 
32                         ? $config{wikiname} 
33 !                       : pagetitle($page),
34                 wikiname => $config{wikiname},
35                 content => $content,
36                 backlinks => $backlinks,
37
38 diff -c /usr/share/perl5/IkiWiki/Plugin/parentlinks.pm.distrib /usr/share/perl5/IkiWiki/Plugin/parentlinks.pm
39 *** /usr/share/perl5/IkiWiki/Plugin/parentlinks.pm.distrib      Wed Aug  6 07:34:55 2008
40 --- /usr/share/perl5/IkiWiki/Plugin/parentlinks.pm      Tue Aug 26 23:19:43 2008
41 ***************
42 *** 44,50 ****
43                         "height_$height" => 1,
44                 };
45                 $path.="/".$dir;
46 !               $title=IkiWiki::pagetitle($dir);
47                 $i++;
48         }
49         return @ret;
50 --- 44,50 ----
51                         "height_$height" => 1,
52                 };
53                 $path.="/".$dir;
54 !               $title=IkiWiki::pagetitle($path);
55                 $i++;
56         }
57         return @ret;
58
59 diff -c /usr/share/perl5/IkiWiki.pm.distrib /usr/share/perl5/IkiWiki.pm
60 *** /usr/share/perl5/IkiWiki.pm.distrib Wed Aug  6 07:48:34 2008
61 --- /usr/share/perl5/IkiWiki.pm Tue Aug 26 23:47:30 2008
62 ***************
63 *** 792,797 ****
64 --- 792,799 ----
65         my $page=shift;
66         my $unescaped=shift;
67   
68 +       $page=basename($page);
69
70         if ($unescaped) {
71                 $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : chr($2)/eg;
72         }
73
74 diff -c /usr/share/perl5/IkiWiki/Plugin/meta.pm.distrib /usr/share/perl5/IkiWiki/Plugin/meta.pm
75 *** /usr/share/perl5/IkiWiki/Plugin/meta.pm.distrib     Wed Aug  6 07:34:55 2008
76 --- /usr/share/perl5/IkiWiki/Plugin/meta.pm     Tue Aug 26 23:30:58 2008
77 ***************
78 *** 3,8 ****
79 --- 3,9 ----
80   package IkiWiki::Plugin::meta;
81   
82   use warnings;
83 + no warnings 'redefine';
84   use strict;
85   use IkiWiki 2.00;
86   
87 ***************
88 *** 289,294 ****
89 --- 290,319 ----
90         }
91   }
92   
93 + sub IkiWiki::pagetitle ($;$) {
94 +       my $page=shift;
95 +       my $unescaped=shift;
96
97 +       if ($page =~ m#/#) {
98 +               $page =~ s#^/##;
99 +               $page =~ s#/index$##;
100 +               if ($pagestate{"$page/index"}{meta}{title}) {
101 +                       $page = $pagestate{"$page/index"}{meta}{title};
102 +               } else {
103 +                       $page = IkiWiki::basename($page);
104 +               }
105 +       }
106
107 +       if ($unescaped) {
108 +               $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : chr($2)/eg;
109 +       }
110 +       else {
111 +               $page=~s/(__(\d+)__|_)/$1 eq '_' ? ' ' : "&#$2;"/eg;
112 +       }
113
114 +       return $page;
115 + }
116
117   package IkiWiki::PageSpec;
118   
119   sub match_title ($$;@) {
120
121 </pre>
122
123 --
124
125 > A few quick notes about it:
126
127 > - Using <code>inline</code> would avoid the redefinition + code duplication.
128 > - A few plugins would need to be upgraded.
129 > - It may be necessary to adapt the testsuite in `t/pagetitle.t`, as well.
130 >
131 > --[[intrigeri]]
132 >
133 >> It was actually more complicated than expected. A working prototype is
134 >> now in my `meta` branch, see my userpage for the up-to-date url.
135 >> Thus tagging [[patch]]. --[[intrigeri]]
136 >>
137 >>> Joey, please consider merging my `meta` branch. --[[intrigeri]]