]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/Option_linktext_for_pagestats_directive.mdwn
New plugin: addtag
[ikiwiki.git] / doc / todo / Option_linktext_for_pagestats_directive.mdwn
1 Hello,    
2 here is a proposal to add a new option to [[ikiwiki/directive]]
3 [[ikiwiki/directive/pagestats]] (from plugin [[plugins/pagestats]]).
4
5 This adds global option `pagestats_linktext` (and directive option `linktext`) to specify whether directive `pagestats` should use the page name or the [[title|ikiwiki/directive/meta]] of tags.
6
7 Here is a [[patch]], for both code and documentation.
8
9 [[!toggle id=diff text="View patch"]]
10 [[!toggleable id=diff text="""
11     diff --git a/IkiWiki/Plugin/pagestats.pm b/IkiWiki/Plugin/pagestats.pm
12     index 17b26f7..a65fd7a 100644
13     --- a/IkiWiki/Plugin/pagestats.pm
14     +++ b/IkiWiki/Plugin/pagestats.pm
15     @@ -29,11 +29,31 @@ sub getsetup () {
16                         rebuild => undef,
17                         section => "widget",
18                 },
19     +           pagestats_linktext => {
20     +                   type => "string",
21     +                   example => "title",
22     +                   description => "Set link text to be whether page title (page) or meta title (title).",
23     +                   safe => 1,
24     +                   rebuild => 1,
25     +           },
26     +}
27     +
28     +sub linktext ($$) {
29     +   # Return the text of the link to a tag, depending on option linktext.
30     +   use Data::Dumper;
31     +   my $page = $_[0];
32     +   my $linktype = $_[1];
33     +   if (($linktype eq "title") and (exists $pagestate{$page}{meta}{title})) {
34     +           return $pagestate{$page}{meta}{title};
35     +   } else {
36     +           return undef;
37     +   }
38      }
39      
40      sub preprocess (@) {
41         my %params=@_;
42         $params{pages}="*" unless defined $params{pages};
43     +   $params{linktext} = $config{pagestats_linktext} unless defined $params{linktext};
44         my $style = ($params{style} or 'cloud');
45         
46         my %counts;
47     @@ -78,7 +98,7 @@ sub preprocess (@) {
48                 return "<table class='".(exists $params{class} ? $params{class} : "pageStats")."'>\n".
49                         join("\n", map {
50                                 "<tr><td>".
51     -                           htmllink($params{page}, $params{destpage}, $_, noimageinline => 1).
52     +                           htmllink($params{page}, $params{destpage}, $_, noimageinline => 1, linktext => linktext($_, $params{linktext})).
53                                 "</td><td>".$counts{$_}."</td></tr>"
54                         }
55                         sort { $counts{$b} <=> $counts{$a} } keys %counts).
56     @@ -101,8 +121,8 @@ sub preprocess (@) {
57                         
58                         $res.="<li>" if $style eq 'list';
59                         $res .= "<span class=\"$class\">".
60     -                           htmllink($params{page}, $params{destpage}, $page).
61     -                           "</span>\n";
62     +                                                   htmllink($params{page}, $params{destpage}, $page, linktext => linktext($page, $params{linktext})).
63     +                                                   "</span>\n";
64                         $res.="</li>" if $style eq 'list';
65      
66                 }
67     diff --git a/doc/ikiwiki/directive/pagestats.mdwn b/doc/ikiwiki/directive/pagestats.mdwn
68     index 8d904f5..56970e6 100644
69     --- a/doc/ikiwiki/directive/pagestats.mdwn
70     +++ b/doc/ikiwiki/directive/pagestats.mdwn
71     @@ -37,4 +37,6 @@ links:
72      The optional `class` parameter can be used to control the class
73      of the generated tag cloud `div` or page stats `table`.
74      
75     +The optional `linktext` parameter can be used to control the text that is displayed for each tag. It can be `page` (the name of the page is used) or `title` (the title, according to the [[ikiwiki/directive/meta]] [[ikiwiki/directive]], is used). This option can be set globally in the setup using option `pagestats_linktext`; default is `page`.
76     +
77      [[!meta robots="noindex, follow"]]
78     diff --git a/doc/plugins/pagestats.mdwn b/doc/plugins/pagestats.mdwn
79     index 347e39a..6a72a9a 100644
80     --- a/doc/plugins/pagestats.mdwn
81     +++ b/doc/plugins/pagestats.mdwn
82     @@ -4,3 +4,7 @@
83      This plugin provides the [[ikiwiki/directive/pagestats]]
84      [[ikiwiki/directive]], which can generate stats about how pages link to
85      each other, or display a tag cloud.
86     +
87     +Their is one global option for the setup file:
88     +
89     +* `pagestats_linktext` controls the text that is displayed for each tag. If `page` (the default), the name of the page is used; if `title`, its title (according to the [[ikiwiki/directive/meta]] [[ikiwiki/directive]]) is used.
90 """]]
91
92 -- [[Louis|spalax]]
93
94 > Hello,    
95 > do not accept my patch: it is an ugly hack that works for me, but its too narrow to be merged in IkiWiki:
96
97 >   - it assumes the [[ikiwiki/directive/pagestats]] directive only deals with tags, which is wrong;
98 >   - such a feature (allowing displaying tags using their title), if enabled, should be enabled for the [[plugins/tag]] plugin (and maybe other plugins [[I have in mind|users/spalax]]) as well.
99
100 > I cannot manage to find a solution to my problem that suits me.
101
102 > # My problem
103
104 > On two sites I maintain using IkiWiki, I have tags that:
105
106 > - have special characters in it (like [[ยท|http://en.wikipedia.org/wiki/Interpunct]]) that generate ugly URLs;
107 > - have subtags (e.g. `math/calculus`, `math/algebra`, `physics/mechanic` etc.).
108
109 > That is, having [[ikiwiki/directive/taglink]] or [[ikiwiki/directive/pagestats]] displaying tags using the pagename (that is something derived from the basename of the URL) is not sufficient for me. I would like to be able to display them using their title, their full name (from the `tagbase` parameter), or both.
110
111 > # Solution?
112
113 > A solution would be to provide a `tagtext` config option, set to one of `page` (use pagename), `title` (use [[ikiwiki/directive/meta]] title), `path` (use path, since the tagbase), `pathtitle` (use path, and use title for each of the subtags); or a boolean `display_tagtitle` and `display_tagpath`, which would handle the way tags are displayed.
114
115 > I see at least two drawbacks to this solution:
116
117 > - I do not know what would be the default of these options, not to break backward compatibility: [[ikiwiki/directive/taglink]] would suggest `page`, whereas the footer would suggest `path`.
118 > - The [[ikiwiki/directive/pagestats]] directive would need an optional boolean parameter `tag`, to specify whether to use these options or not.
119
120 > # *My* problem ?
121
122 > I actually wonder if someone else also have this problem: as far as I can see on other sites using IkiWiki and tags, I would not be surprised if others are satisfyed with the current way tags are displayed: I do not remember having seen subtags, or tags in non-English language with weird characters in them.
123
124 > So, I wonder whether this discussion would benefit IkiWiki, or if I should just go on with my hack (or maybe a plugin, but I think it would be quite difficult to do, given that the very same function is used to display tags and to uniquely identify them).
125
126 > -- [[Louis|spalax]]