]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - doc/todo/Option_linktext_for_pagestats_directive.mdwn
fad813a39fef619b1e0c6428935fe16cf0d7438c
[git.ikiwiki.info.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]]).
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.
7 Here is a [[patch]], for both code and documentation.
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 """]]
92 -- [[Louis|spalax]]