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 >>> Well, re that hunk, taint checking is currently disabled, but
40 >>> if the perl bug that disallows it is fixed and it is turned back on,
41 >>> the hash values will remain tainted, which will probably lead to
44 >>> I'm also leery of using such a complex data structure in config.
45 >>> The websetup plugin would be hard pressed to provide a UI for such a
46 >>> data structure. (It lacks even UI for a single hash ref yet, let alone
49 >>> Also, it seems sorta wrong to have two so very different syntaxes to
50 >>> represent the same meta data. A user without a lot of experience will
51 >>> be hard pressed to map from a directive to this in the setup file.
53 >>> All of which leads me to think the setup file could just contain
54 >>> a text that could hold meta directives. Which generalizes really to
55 >>> a text that contains any directives, and is, perhaps appended to the
56 >>> top of every page. Which nearly generalizes to the sidebar plugin,
57 >>> or perhaps something more general than that...
59 >>> However, excessive generalization is the root of all evil, so
60 >>> I'm not necessarily saying that's a good idea. Indeed, my memory
61 >>> concerns below invalidate this idea pretty well. --[[Joey]]
63 diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
64 index 6fe9cda..2f8c098 100644
65 --- a/IkiWiki/Plugin/meta.pm
66 +++ b/IkiWiki/Plugin/meta.pm
67 @@ -13,6 +13,8 @@ sub import {
68 hook(type => "needsbuild", id => "meta", call => \&needsbuild);
69 hook(type => "preprocess", id => "meta", call => \&preprocess, scan => 1);
70 hook(type => "pagetemplate", id => "meta", call => \&pagetemplate);
71 + hook(type => "scan", id => "meta", call => \&scan)
72 + if $config{"meta_defaults"};
76 @@ -305,6 +307,15 @@ sub match {
82 + my $page = $params{page};
83 + foreach my $default (@{$config{"meta_defaults"}}) {
84 + preprocess(%$default, page => $page,
85 + destpage => $page, preview => 0);
89 package IkiWiki::PageSpec;
91 sub match_title ($$;@) {
92 diff --git a/IkiWiki/Setup.pm b/IkiWiki/Setup.pm
93 index 8a25ecc..e4d50c9 100644
94 --- a/IkiWiki/Setup.pm
95 +++ b/IkiWiki/Setup.pm
96 @@ -51,7 +51,13 @@ sub merge ($) {
97 $config{$c}=$setup{$c};
100 - $config{$c}=[map { IkiWiki::possibly_foolish_untaint($_) } @{$setup{$c}}]
102 + if(ref $_ eq 'HASH') {
105 + IkiWiki::possibly_foolish_untaint($_)
110 elsif (ref $setup{$c} eq 'HASH') {
111 diff --git a/doc/ikiwiki/directive/meta.mdwn b/doc/ikiwiki/directive/meta.mdwn
112 index 000f461..8d34ee4 100644
113 --- a/doc/ikiwiki/directive/meta.mdwn
114 +++ b/doc/ikiwiki/directive/meta.mdwn
115 @@ -12,6 +12,16 @@ also specifies some additional sub-parameters.
116 The field values are treated as HTML entity-escaped text, so you can include
117 a quote in the text by writing `"` and so on.
119 +You can also define site-wide defaults for meta values by including them
120 +in your setup file. The key used is `meta_defaults` and the value is a list
121 +of hashes, one per meta directive. e.g.:
124 + { copyright => "Copyright 2007 by Joey Hess" },
125 + { license => "GPL v2+" },
126 + { link => "somepage", rel => "site entrypoint", },
135 >> Ok, I've had a bit of a think about this. There are currently 15 supported
136 >> meta fields. Of these: title, licence, copyright, author, authorurl,
137 >> and robots might make sense to define globally and override on a per-page
140 >> Less so, description (due to its impact on map); openid (why would
141 >> someone want more than one URI to act as an openid endpoint to the same
142 >> place?); updated. I can almost see why someone might want to set a global
143 >> updated value. Almost.
145 >> Not useful are permalink, date, stylesheet (you already have a global
146 >> stylesheet), link, redir, and guid.
148 >> In other words, the limitations of my first patch that [[smcv]] outlined
149 >> are only relevant to defined fields that you wouldn't want to specify a
150 >> global default for anyway.
152 >>> I generally agree with this. It is *possible* that meta would have a new
153 >>> field added, that takes parameters and make sense to use globally.
156 >> Due to this, and the added complexity of the second patch (having to adjust
157 >> `IkiWiki/Setup.pm`), I think the first patch makes more sense. I've thus
158 >> reverted to it here.
160 >> Is this merge-worthy?
162 diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
163 index b229592..3132257 100644
164 --- a/IkiWiki/Plugin/meta.pm
165 +++ b/IkiWiki/Plugin/meta.pm
166 @@ -13,6 +13,7 @@ sub import {
167 hook(type => "needsbuild", id => "meta", call => \&needsbuild);
168 hook(type => "preprocess", id => "meta", call => \&preprocess, scan => 1);
169 hook(type => "pagetemplate", id => "meta", call => \&pagetemplate);
170 + hook(type => "scan", id => "meta", call => \&scan);
174 @@ -302,6 +303,15 @@ sub match {
180 + my $page = $params{page};
181 + foreach my $type (map { s/^meta_//; $_ } grep /^meta_/, keys %config) {
182 + $pagestate{$page}{meta}{$type} = $config{"meta_$type"}
183 + unless defined $pagestate{$page}{meta}{$type};
187 package IkiWiki::PageSpec;
189 sub match_title ($$;@) {
190 diff --git a/doc/ikiwiki/directive/meta.mdwn b/doc/ikiwiki/directive/meta.mdwn
191 index 000f461..200c4b2 100644
192 --- a/doc/ikiwiki/directive/meta.mdwn
193 +++ b/doc/ikiwiki/directive/meta.mdwn
194 @@ -12,6 +12,12 @@ also specifies some additional sub-parameters.
195 The field values are treated as HTML entity-escaped text, so you can include
196 a quote in the text by writing `"` and so on.
198 +You can also define site-wide defaults for meta values by including them
199 +in your setup file, e.g.
201 + meta_copyright => "Copyright 2007 by Joey Hess",
202 + meta_license => "GPL v2+",
210 >>> Merry Christmas/festive season/happy new year folks. I've been away from
211 >>> ikiwiki for the break, and now I've returned to watching recentchanges.
212 >>> Hopefully I'll be back in the mix soon, too. In the meantime, Joey, have
213 >>> you had a chance to look at this yet? -- [[Jon]]
215 >>>> Ping :) Hi. [[Joey]], would you consider this patch for the next
216 >>>> ikiwiki release? -- [[Jon]]
218 >>> For this to work with websetup and --dumpsetup, it needs to define the
219 >>> `meta_*` settings in the getsetup function.
221 >>> I also have some concerns about both these patches, since both throw
222 >>> a lot of redundant data at meta, which then stores it in a very redundant
223 >>> way. Specifically, meta populates a per-page `%metaheaders` hash
224 >>> as well as storing per-page metadata in `%pagestate`. So, if you have
225 >>> a wiki with 10 thousand pages, and you add a 1k site-wide license text,
226 >>> that will bloat the memory usage of ikiwiki by in excess of 2
227 >>> megabytes. It will also cause ikiwiki to write a similar amount more data
228 >>> to its state file which has to be loaded back in each
231 >>> Seems that this could be managed much more efficiently by having
232 >>> meta special-case the site-wide settings, not store them in these
233 >>> per-page data structures, and just make them be used if no per-page
234 >>> metadata of the given type is present. --[[Joey]]
236 >>>> Thanks for the review - these are all valid points. I'll get working
237 >>>> on a revised patch. -- [[Jon]]