From: Jonathon Anderson Date: Fri, 25 Jan 2013 05:42:23 +0000 (+0300) Subject: Provide a UUID in edittemplate templates. X-Git-Tag: 3.20140916~43^2~6 X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/commitdiff_plain/7aa10a2952a0d0ee8543f575966f7e4a780c993c Provide a UUID in edittemplate templates. I want to make GUIDs for my RSS feeds that don't change when I move pages around. To that end, I've used UUID::Tiny to generate a version 4 (random) UUID that is presented in a `uuid` variable in the template. At that point, you can do something like this: [[!meta guid="urn:uuid:"]] --- diff --git a/IkiWiki/Plugin/edittemplate.pm b/IkiWiki/Plugin/edittemplate.pm index e3ce5e3d9..6e8c256da 100644 --- a/IkiWiki/Plugin/edittemplate.pm +++ b/IkiWiki/Plugin/edittemplate.pm @@ -139,6 +139,14 @@ sub filltemplate ($$) { $template->param(name => $page); + eval { + require UUID::Tiny; + UUID::Tiny->import(':std'); + my $uuid; + $uuid = create_uuid_as_string(UUID_V4()); + $template->param(uuid => $uuid); + }; + return $template->output; } diff --git a/doc/ikiwiki/directive/edittemplate.mdwn b/doc/ikiwiki/directive/edittemplate.mdwn index a6f301dd3..151fd203a 100644 --- a/doc/ikiwiki/directive/edittemplate.mdwn +++ b/doc/ikiwiki/directive/edittemplate.mdwn @@ -27,8 +27,14 @@ something like: Details: The template page can also contain [[!cpan HTML::Template]] directives, -like other ikiwiki [[templates]]. Currently only one variable is -set: `` is replaced with the name of the page being -created. +like other ikiwiki [[templates]]. + +Two variables might be set: + +* `` is replaced with the name of the page being + created. + +* `` is replaced with a version 4 (random) UUID. + (Requires the `UUID::Tiny` Perl module.) [[!meta robots="noindex, follow"]]