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.
3 There are clearly many ways to do this, but any opinions on which is the cleanest?
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.
13 Thanks. That works fine.
17 @Ben: could you publish the code for that?
19 --David Riebenbauer <davrieb@htu.tugraz.at>
21 AOLMODE=true echo "I too would really like this feature, which would make cgi free life much
22 better" --[[DavidBremner]]
24 Please make the actual text used a template some way or another. I may want `map` instead of `inline`. --[[madduck]]
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.
33 --- tag.pm 2009-02-06 10:26:03.000000000 -0700
34 +++ tag_new.pm 2009-02-06 12:17:19.000000000 -0700
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);
50 + description => "Auto-create the new tag pages, uses autotagpage.tmpl ",
56 +my $autocreated_page = 0;
58 +sub gen_tag_page($) {
61 + my $tag_file=$tag.'.'.$config{default_pageext};
62 + return if (-f $config{srcdir}.$tag_file);
64 + my $template=template("autotagpage.tmpl");
65 + $template->param(tag => $tag);
66 + writefile($tag_file, $config{srcdir}, $template->output);
67 + $autocreated_page = 1;
70 + IkiWiki::disable_commit_hook();
71 + IkiWiki::rcs_add($tag_file);
72 + IkiWiki::rcs_commit_staged(
73 + gettext("Automatic tag page generation"),
75 + IkiWiki::enable_commit_hook();
81 $tag=~y#/#/#s; # squash dups
84 + if (defined $config{tag_autocreate} && $config{tag_autocreate} ) {
96 + return unless($autocreated_page);
97 + $autocreated_page = 0;
99 + # This refresh/saveindex is to complie the autocreated tag pages
100 + IkiWiki::refresh();
101 + IkiWiki::saveindex();
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();
111 This uses a template called `autotagpage.tmpl`, here is my template file:
113 \[[!inline pages="link(<TMPL_VAR TAG>)" archive="yes"]]
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.
120 -- Jeremy Schultz <jeremy.schultz@uleth.ca>