]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/commitdiff
Provide a UUID in edittemplate templates.
authorJonathon Anderson <anderbubble@gmail.com>
Fri, 25 Jan 2013 05:42:23 +0000 (08:42 +0300)
committerSimon McVittie <smcv@debian.org>
Mon, 1 Sep 2014 07:54:37 +0000 (08:54 +0100)
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:<TMPL_VAR uuid>"]]

IkiWiki/Plugin/edittemplate.pm
doc/ikiwiki/directive/edittemplate.mdwn

index e3ce5e3d97437392c681f20f6c3a23b0b9690790..6e8c256da3fdca36addcf8a12a767a6c90d68019 100644 (file)
@@ -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;
 }
 
index a6f301dd3c5906548fcdfd3853dd33937abe96d7..151fd203ac4e124ccc42fdaf36eca8ee08aab13a 100644 (file)
@@ -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: `<TMPL_VAR name>` is replaced with the name of the page being
-created.
+like other ikiwiki [[templates]].
+
+Two variables might be set:
+
+* `<TMPL_VAR name>` is replaced with the name of the page being
+  created.
+  
+* `<TMPL_VAR uuid>` is replaced with a version 4 (random) UUID.
+  (Requires the `UUID::Tiny` Perl module.)
 
 [[!meta robots="noindex, follow"]]