give up and just inline the patch again
[ikiwiki] / 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
40     diff --git a/IkiWiki/Plugin/meta.pm b/IkiWiki/Plugin/meta.pm
41     index 6fe9cda..c4079fd 100644
42     --- a/IkiWiki/Plugin/meta.pm
43     +++ b/IkiWiki/Plugin/meta.pm
44     @@ -13,6 +13,7 @@ sub import {
45         hook(type => "needsbuild", id => "meta", call => \&needsbuild);
46         hook(type => "preprocess", id => "meta", call => \&preprocess, scan => 1);
47         hook(type => "pagetemplate", id => "meta", call => \&pagetemplate);
48     +   hook(type => "scan", id => "meta", call => \&scan);
49      }
50      
51      sub getsetup () {
52     @@ -305,6 +306,17 @@ sub match {
53         }
54      }
55      
56     +sub scan() {
57     +   my %params = @_;
58     +   my $page = $params{page};
59     +   if($config{"meta_defaults"}) {
60     +           foreach my $default (@{$config{"meta_defaults"}}) {
61     +                   preprocess(%$default, page => $page,
62     +                           destpage => $page, preview => 0);
63     +           }
64     +   }
65     +}
66     +
67      package IkiWiki::PageSpec;
68      
69      sub match_title ($$;@) {
70     diff --git a/IkiWiki/Setup.pm b/IkiWiki/Setup.pm
71     index 8a25ecc..e4d50c9 100644
72     --- a/IkiWiki/Setup.pm
73     +++ b/IkiWiki/Setup.pm
74     @@ -51,7 +51,13 @@ sub merge ($) {
75                                         $config{$c}=$setup{$c};
76                                 }
77                                 else {
78     -                                   $config{$c}=[map { IkiWiki::possibly_foolish_untaint($_) } @{$setup{$c}}]
79     +                                   $config{$c}=[map {
80     +                                           if(ref $_ eq 'HASH') {
81     +                                                   $_
82     +                                           } else {
83     +                                                   IkiWiki::possibly_foolish_untaint($_)
84     +                                           }
85     +                                   } @{$setup{$c}}];
86                                 }
87                         }
88                         elsif (ref $setup{$c} eq 'HASH') {
89     diff --git a/doc/ikiwiki/directive/meta.mdwn b/doc/ikiwiki/directive/meta.mdwn
90     index 000f461..8d34ee4 100644
91     --- a/doc/ikiwiki/directive/meta.mdwn
92     +++ b/doc/ikiwiki/directive/meta.mdwn
93     @@ -12,6 +12,16 @@ also specifies some additional sub-parameters.
94      The field values are treated as HTML entity-escaped text, so you can include
95      a quote in the text by writing `&quot;` and so on.
96      
97     +You can also define site-wide defaults for meta values by including them
98     +in your setup file. The key used is `meta_defaults` and the value is a list
99     +of hashes, one per meta directive. e.g.:
100     +
101     +   meta_defaults = [
102     +           { copyright => "Copyright 2007 by Joey Hess" },
103     +           { license   => "GPL v2+" },
104     +           { link => "somepage", rel => "site entrypoint", },
105     +   ],
106     +
107      Supported fields:
108      
109      * title
110
111  -- [[Jon]]