Hi, I want to add tags to some pages automatically (generating album images and want to tag all generated pages). I managed to do so in following way:
IkiWiki::Plugin::tag::preprocess_tag(
page => $viewer,
destpage => $params{destpage},
map { ($_ => 1) } @tags,
);
This works, however if some tag does not exist, it is not created. I tracked it so far that I found that the Render.pm's method gen_autofile() is not called , so it is most likely that I need to somehow trigger Render.pm's refresh()...but how can I do it?
BTW: The code is modified album plugin that is in my git
(If you want to branch from my version of album, please add my git repo as a remote and merge or cherry-pick the album4 branch: pasting from my gitweb seems to have given you some incorrect UTF-8.)
The problem you have here is that for this plugin, the correct order for IkiWiki to do things is quite subtle. Am I right in thinking that the feature you want goes something like this?
preprocess_albumimage
runs twice: once in the scan stage, and once in the render stage. In the render stage, it's too late to add tags, because tags are a special form of ?wikilinks, and wikilinks have to be added during the scan stage to work correctly.The part of
preprocess_albumimage
after the linereturn unless defined wantarray;
only runs in the render stage, which is too late. You'd need to set up the tags further up: just after the calls toIkiWiki::Plugin::meta::preprocess
would be a good place.I would also suggest checking for
IkiWiki::Plugin::tag->can('preprocess_tag')
, like I do for meta - if you do that, you won't need to force the tag plugin to be loaded.Unfortunately, I'm still not sure that this is fully correct. Pages are scanned in a random order. If the
\[[!album]]
is scanned before a "viewer" page, then everything is fine: the tags are present when the "viewer" is scanned. However, if the "viewer" is scanned first, then it will get the tags that the\[[!album]]
had in the previous IkiWiki run (if any), which are still in the index, because the\[[!album]]
hasn't been re-scanned yet...Are you sure this form of the feature is what you want? You'll end up with a lot of pages with those tags. If it's what you want, it might be clearer how it works if you changed the syntax to something like this, perhaps?
Another possible syntax would be to have the feature be more like this:
which I think removes the ordering problems? If you go this route, you'd want to either add e.g.
[[!tag holiday hawaii]]
to the generated viewer page increate_viewer
, or add atag
parameter to\[[!albumimage]]
that's a shortcut for the tag directive, in the same way that author is a shortcut for[[!meta author]]
).The purpose of the "shortcut" parameters in
\[[!albumimage]]
, like title, author and date, is that I eventually want to add a specialized CGI interface to this plugin so you can edit all the images of an album in one go; when I add that, it'll probably only be able to process something as machine-readable as\[[!albumimage]]
.