]> sipb.mit.edu Git - ikiwiki.git/blob - doc/plugins/tag/discussion.mdwn
use shortcut with mdwn disabled
[ikiwiki.git] / doc / plugins / tag / discussion.mdwn
1 I'd like to modify this plugin such that the tag pages are automatically created and populated with a list of relevant posts. The content of the tag page is simply `"\[[!inline pages="link(tag/$tag)"]]`. The tag plugin will have to determine whether a page for the given tag already exists, and if not use that Markdown fragment to  generate it.
2
3 There are clearly many ways to do this, but any opinions on which is the cleanest?
4
5 --Ben
6
7 It might work to use the 'change' hook, since that's called at the very end
8 of `refresh()`. The hook could add the tag pages and re-run `refresh()`,
9 taking appropriate care to avoid looping forever.
10
11 --[[Joey]]
12
13 Thanks. That works fine.
14
15 --Ben
16
17 @Ben: could you publish the code for that?
18
19 --David Riebenbauer <davrieb@htu.tugraz.at>
20
21 AOLMODE=true echo "I too would really like this feature, which would make cgi free life much 
22 better" --[[DavidBremner]]
23
24 Please make the actual text used a template some way or another. I may want `map` instead of `inline`. --[[madduck]]
25
26 ---
27
28 I have create a patch to tag.pm for add the option for auto create tag pages.
29 A new setting is used to enable or disable auto-create tag pages, `tag_autocreate`.
30 The new tag file is created during the preprocess phase. 
31 The new tag file is then complied during the change phase.
32
33         --- tag.pm      2009-02-06 10:26:03.000000000 -0700
34         +++ tag_new.pm  2009-02-06 12:17:19.000000000 -0700
35         @@ -14,6 +14,7 @@
36                         hook(type => "preprocess", id => "tag", call => \&preprocess_tag, scan => 1);
37                         hook(type => "preprocess", id => "taglink", call => \&preprocess_taglink, scan => 1);
38                         hook(type => "pagetemplate", id => "tag", call => \&pagetemplate);
39         +       hook(type => "change", id => "tag", call => \&change);
40          }
41          
42          sub getopt () {
43         @@ -36,6 +37,36 @@
44                                                         safe => 1,
45                                                         rebuild => 1,
46                                         },
47         +               tag_autocreate => {
48         +                       type => "boolean",
49         +                       example => 0,
50         +                       description => "Auto-create the new tag pages, uses autotagpage.tmpl ",
51         +                       safe => 1,
52         +                       rebulid => 1,
53         +               },
54         +}
55         +
56         +my $autocreated_page = 0;
57         +
58         +sub gen_tag_page($)    {
59         +       my $tag=shift;
60         +
61         +       my $tag_file=$tag.'.'.$config{default_pageext};
62         +       return if (-f $config{srcdir}.$tag_file);
63         +
64         +       my $template=template("autotagpage.tmpl");
65         +       $template->param(tag => $tag);
66         +       writefile($tag_file, $config{srcdir}, $template->output);
67         +       $autocreated_page = 1;
68         +
69         +       if ($config{rcs}) {
70         +               IkiWiki::disable_commit_hook();
71         +               IkiWiki::rcs_add($tag_file);
72         +               IkiWiki::rcs_commit_staged(
73         +                       gettext("Automatic tag page generation"),
74         +                       undef, undef);
75         +               IkiWiki::enable_commit_hook();
76         +       }
77          }
78          
79          sub tagpage ($) {
80         @@ -47,6 +78,10 @@
81                                         $tag=~y#/#/#s; # squash dups
82                         }
83          
84         +       if (defined $config{tag_autocreate} && $config{tag_autocreate} ) {
85         +               gen_tag_page($tag);
86         +       }
87         +
88                         return $tag;
89          }
90          
91         @@ -125,4 +160,18 @@
92                         }
93          }
94          
95         +sub change(@) {
96         +       return unless($autocreated_page);
97         +       $autocreated_page = 0;
98         +
99         +       # This refresh/saveindex is to complie the autocreated tag pages
100         +       IkiWiki::refresh();
101         +       IkiWiki::saveindex();
102         +
103         +       # This refresh/saveindex is to fix the Tags link
104         +       # With out this additional refresh/saveindex the tag link displays ?tag
105         +       IkiWiki::refresh();
106         +       IkiWiki::saveindex();
107         +}
108         +
109
110
111 This uses a template called `autotagpage.tmpl`, here is my template file:
112
113     \[[!inline pages="link(<TMPL_VAR TAG>)" archive="yes"]]
114
115
116 A quirk I have not figured out is during the `sub change`, see my comments in the code.
117 I am not sure if that is the best way to handle it.
118
119 [[!tag patch]]
120 -- Jeremy Schultz <jeremy.schultz@uleth.ca>
121