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 <snip old patch, see below for latest>
12 > This doesn't support multiple-argument meta directives like
13 > `link=x rel=y`, or meta directives with special side-effects like
16 > The first could be solved (if you care) by a syntax like this:
19 > { copyright => "© me" },
20 > { link => "about:blank", rel => "silly", },
23 > The second could perhaps be solved by invoking `meta::preprocess` from within
24 > `scan` (which might be a simplification anyway), although this is complicated
25 > by the fact that some (but not all!) meta headers are idempotent.
29 >> Thanks for your comment. I've revised the patch to use the config syntax
30 >> you suggest. I need to perform some more testing to make sure I've
31 >> addressed the issues you highlight.
33 >> I had to patch part of IkiWiki core, the merge routine in Setup, because
34 >> the use of `possibly_foolish_untaint` was causing the hashrefs at the deep
35 >> end of the data structure to be converted into strings. The specific change
36 >> I've made may not be acceptable, though -- I'd appreciate someone providing
37 >> some feedback on that hunk!
39 diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
40 index 6fe9cda..2f8c098 100644
41 --- a/IkiWiki/Plugin/meta.pm
42 +++ b/IkiWiki/Plugin/meta.pm
43 @@ -13,6 +13,8 @@ sub import {
44 hook(type => "needsbuild", id => "meta", call => \&needsbuild);
45 hook(type => "preprocess", id => "meta", call => \&preprocess, scan => 1);
46 hook(type => "pagetemplate", id => "meta", call => \&pagetemplate);
47 + hook(type => "scan", id => "meta", call => \&scan)
48 + if $config{"meta_defaults"};
52 @@ -305,6 +307,15 @@ sub match {
58 + my $page = $params{page};
59 + foreach my $default (@{$config{"meta_defaults"}}) {
60 + preprocess(%$default, page => $page,
61 + destpage => $page, preview => 0);
65 package IkiWiki::PageSpec;
67 sub match_title ($$;@) {
68 diff --git a/IkiWiki/Setup.pm b/IkiWiki/Setup.pm
69 index 8a25ecc..e4d50c9 100644
70 --- a/IkiWiki/Setup.pm
71 +++ b/IkiWiki/Setup.pm
72 @@ -51,7 +51,13 @@ sub merge ($) {
73 $config{$c}=$setup{$c};
76 - $config{$c}=[map { IkiWiki::possibly_foolish_untaint($_) } @{$setup{$c}}]
78 + if(ref $_ eq 'HASH') {
81 + IkiWiki::possibly_foolish_untaint($_)
86 elsif (ref $setup{$c} eq 'HASH') {
87 diff --git a/doc/ikiwiki/directive/meta.mdwn b/doc/ikiwiki/directive/meta.mdwn
88 index 000f461..8d34ee4 100644
89 --- a/doc/ikiwiki/directive/meta.mdwn
90 +++ b/doc/ikiwiki/directive/meta.mdwn
91 @@ -12,6 +12,16 @@ also specifies some additional sub-parameters.
92 The field values are treated as HTML entity-escaped text, so you can include
93 a quote in the text by writing `"` and so on.
95 +You can also define site-wide defaults for meta values by including them
96 +in your setup file. The key used is `meta_defaults` and the value is a list
97 +of hashes, one per meta directive. e.g.:
100 + { copyright => "Copyright 2007 by Joey Hess" },
101 + { license => "GPL v2+" },
102 + { link => "somepage", rel => "site entrypoint", },
111 >> Ok, I've had a bit of a think about this. There are currently 15 supported
112 >> meta fields. Of these: title, licence, copyright, author, authorurl,
113 >> and robots might make sense to define globally and override on a per-page
116 >> Less so, description (due to its impact on map); openid (why would
117 >> someone want more than one URI to act as an openid endpoint to the same
118 >> place?); updated. I can almost see why someone might want to set a global
119 >> updated value. Almost.
121 >> Not useful are permalink, date, stylesheet (you already have a global
122 >> stylesheet), link, redir, and guid.
124 >> In other words, the limitations of my first patch that [[smcv]] outlined
125 >> are only relevant to defined fields that you wouldn't want to specify a
126 >> global default for anyway.
128 >> Due to this, and the added complexity of the second patch (having to adjust
129 >> `IkiWiki/Setup.pm`), I think the first patch makes more sense. I've thus
130 >> reverted to it here.
132 >> Is this merge-worthy?
134 diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
135 index b229592..3132257 100644
136 --- a/IkiWiki/Plugin/meta.pm
137 +++ b/IkiWiki/Plugin/meta.pm
138 @@ -13,6 +13,7 @@ sub import {
139 hook(type => "needsbuild", id => "meta", call => \&needsbuild);
140 hook(type => "preprocess", id => "meta", call => \&preprocess, scan => 1);
141 hook(type => "pagetemplate", id => "meta", call => \&pagetemplate);
142 + hook(type => "scan", id => "meta", call => \&scan);
146 @@ -302,6 +303,15 @@ sub match {
152 + my $page = $params{page};
153 + foreach my $type (map { s/^meta_//; $_ } grep /^meta_/, keys %config) {
154 + $pagestate{$page}{meta}{$type} = $config{"meta_$type"}
155 + unless defined $pagestate{$page}{meta}{$type};
159 package IkiWiki::PageSpec;
161 sub match_title ($$;@) {
162 diff --git a/doc/ikiwiki/directive/meta.mdwn b/doc/ikiwiki/directive/meta.mdwn
163 index 000f461..200c4b2 100644
164 --- a/doc/ikiwiki/directive/meta.mdwn
165 +++ b/doc/ikiwiki/directive/meta.mdwn
166 @@ -12,6 +12,12 @@ also specifies some additional sub-parameters.
167 The field values are treated as HTML entity-escaped text, so you can include
168 a quote in the text by writing `"` and so on.
170 +You can also define site-wide defaults for meta values by including them
171 +in your setup file, e.g.
173 + meta_copyright => "Copyright 2007 by Joey Hess",
174 + meta_license => "GPL v2+",
182 >>> Merry Christmas/festive season/happy new year folks. I've been away from
183 >>> ikiwiki for the break, and now I've returned to watching recentchanges.
184 >>> Hopefully I'll be back in the mix soon, too. In the meantime, Joey, have
185 >>> you had a chance to look at this yet? -- [[Jon]]