1 [[!tag plugins/meta patch]]
3 I'd like to define [[plugins/meta]] values to apply across all pages
4 site-wide unless the pages define their own: default values for meta
5 definitions essentially.
7 Here's a patch to achieve this (also in the "defaultmeta" branch of
8 my github ikiwiki fork):
10 diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
11 index b229592..3132257 100644
12 --- a/IkiWiki/Plugin/meta.pm
13 +++ b/IkiWiki/Plugin/meta.pm
14 @@ -13,6 +13,7 @@ sub import {
15 hook(type => "needsbuild", id => "meta", call => \&needsbuild);
16 hook(type => "preprocess", id => "meta", call => \&preprocess, scan => 1);
17 hook(type => "pagetemplate", id => "meta", call => \&pagetemplate);
18 + hook(type => "scan", id => "meta", call => \&scan);
22 @@ -302,6 +303,15 @@ sub match {
28 + my $page = $params{page};
29 + foreach my $type (map { s/^meta_//; $_ } grep /^meta_/, keys %config) {
30 + $pagestate{$page}{meta}{$type} = $config{"meta_$type"}
31 + unless defined $pagestate{$page}{meta}{$type};
35 package IkiWiki::PageSpec;
37 sub match_title ($$;@) {
38 diff --git a/doc/ikiwiki/directive/meta.mdwn b/doc/ikiwiki/directive/meta.mdwn
39 index 000f461..200c4b2 100644
40 --- a/doc/ikiwiki/directive/meta.mdwn
41 +++ b/doc/ikiwiki/directive/meta.mdwn
42 @@ -12,6 +12,12 @@ also specifies some additional sub-parameters.
43 The field values are treated as HTML entity-escaped text, so you can include
44 a quote in the text by writing `"` and so on.
46 +You can also define site-wide defaults for meta values by including them
47 +in your setup file, e.g.
49 + meta_copyright => "Copyright 2007 by Joey Hess",
50 + meta_license => "GPL v2+",
58 > This doesn't support multiple-argument meta directives like
59 > `link=x rel=y`, or meta directives with special side-effects like
62 > The first could be solved (if you care) by a syntax like this:
65 > { copyright => "© me" },
66 > { link => "about:blank", rel => "silly", },
69 > The second could perhaps be solved by invoking `meta::preprocess` from within
70 > `scan` (which might be a simplification anyway), although this is complicated
71 > by the fact that some (but not all!) meta headers are idempotent.