]> sipb.mit.edu Git - ikiwiki.git/blob - doc/todo/allow_site-wide_meta_definitions.mdwn
make it more generic?
[ikiwiki.git] / doc / todo / allow_site-wide_meta_definitions.mdwn
1 [[!tag plugins/meta patch]]
2 [[!template id=gitbranch branch=jon/defaultmeta author="[[Jon]]"]]
3
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.
7
8     <snip old patch, see below for latest>
9
10 -- [[Jon]]
11
12 > This doesn't support multiple-argument meta directives like
13 > `link=x rel=y`, or meta directives with special side-effects like
14 > `updated`.
15 >
16 > The first could be solved (if you care) by a syntax like this:
17 >
18 >     meta_defaults => [
19 >         { copyright => "© me" },
20 >         { link => "about:blank", rel => "silly", },
21 >     ]
22 >
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.
26
27 > --[[smcv]]
28
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.
32 >> 
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!
38
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
42 >>> problems.
43 >>>
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
47 >>> a list.)
48 >>> 
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.
52 >>>
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... 
58 >>>
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]] 
62
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"};
73      }
74      
75      sub getsetup () {
76     @@ -305,6 +307,15 @@ sub match {
77         }
78      }
79      
80     +sub scan() {
81     +   my %params = @_;
82     +   my $page = $params{page};
83     +   foreach my $default (@{$config{"meta_defaults"}}) {
84     +           preprocess(%$default, page => $page,
85     +                   destpage => $page, preview => 0);
86     +   }
87     +}
88     +
89      package IkiWiki::PageSpec;
90      
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};
98                                 }
99                                 else {
100     -                                   $config{$c}=[map { IkiWiki::possibly_foolish_untaint($_) } @{$setup{$c}}]
101     +                                   $config{$c}=[map {
102     +                                           if(ref $_ eq 'HASH') {
103     +                                                   $_
104     +                                           } else {
105     +                                                   IkiWiki::possibly_foolish_untaint($_)
106     +                                           }
107     +                                   } @{$setup{$c}}];
108                                 }
109                         }
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 `&quot;` and so on.
118      
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.:
122     +
123     +   meta_defaults = [
124     +           { copyright => "Copyright 2007 by Joey Hess" },
125     +           { license   => "GPL v2+" },
126     +           { link => "somepage", rel => "site entrypoint", },
127     +   ],
128     +
129      Supported fields:
130      
131      * title
132
133 -- [[Jon]]
134
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
138 >> basis.
139 >> 
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.
144 >> 
145 >> Not useful are permalink, date, stylesheet (you already have a global
146 >> stylesheet), link, redir, and guid.
147 >>
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.
151 >>
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.
154 >>> --[[Joey]] 
155 >>
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.
159 >>
160 >> Is this merge-worthy?
161
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);
171      }
172      
173      sub getsetup () {
174     @@ -302,6 +303,15 @@ sub match {
175         }
176      }
177      
178     +sub scan() {
179     +   my %params = @_;
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};
184     +   }
185     +}
186     +
187      package IkiWiki::PageSpec;
188      
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 `&quot;` and so on.
197      
198     +You can also define site-wide defaults for meta values by including them
199     +in your setup file, e.g.
200     +
201     +   meta_copyright => "Copyright 2007 by Joey Hess",
202     +   meta_license   => "GPL v2+",
203     +
204      Supported fields:
205      
206      * title
207
208 -- [[Jon]]
209
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]]
214
215 >>>> Ping :) Hi.  [[Joey]], would you consider this patch for the next
216 >>>> ikiwiki release? -- [[Jon]]
217
218 >>> For this to work with websetup and --dumpsetup, it needs to define the
219 >>> `meta_*` settings in the getsetup function.
220 >>>> 
221 >>>> I think this will be problematic with the current implementation of this
222 >>>> patch. The datatype here is an array of hash references, with each hash
223 >>>> having a variable (and arbitrary) number of key/value pairs.  I can't
224 >>>> think of an intuitive way of implementing a way of editing such a
225 >>>> datatype in the web interface, let alone registering the option in
226 >>>> getsetup.
227 >>>> 
228 >>>> Perhaps a limited set of defined meta values could be exposed via
229 >>>> websetup (the obvious ones: author, copyright, license, etc.) -- [[Jon]]
230 >>>
231 >>> I also have some concerns about both these patches, since both throw
232 >>> a lot of redundant data at meta, which then stores it in a very redundant
233 >>> way. Specifically, meta populates a per-page `%metaheaders` hash
234 >>> as well as storing per-page metadata in `%pagestate`. So, if you have
235 >>> a wiki with 10 thousand pages, and you add a 1k site-wide license text,
236 >>> that will bloat the memory usage of ikiwiki by in excess of 2
237 >>> megabytes. It will also cause ikiwiki to write a similar amount more data
238 >>> to its state file which has to be loaded back in each
239 >>> run.
240 >>>
241 >>> Seems that this could be managed much more efficiently by having
242 >>> meta special-case the site-wide settings, not store them in these
243 >>> per-page data structures, and just make them be used if no per-page
244 >>> metadata of the given type is present. --[[Joey]]
245 >>>> 
246 >>>> that should be easy enough to do. I will work on a patch. -- [[Jon]]