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