underlay plugin, a command-line interface for add_underlay()
[ikiwiki] / doc / plugins / contrib / underlay.mdwn
1 [[!template id=plugin name=underlay author="[[Simon_McVittie|smcv]]"]]
2 [[!tag type/useful]]
3
4 This plugin adds an `add_underlays` option to the `.setup` file.
5 Its value is a list of underlay directories whose content is added to the wiki.
6
7 Multiple underlays are normally set up automatically by other plugins (for
8 instance, the smiley images used by [[plugins/smileys]]), but they can also be
9 used as a way to pull in external files that you don't want in revision control,
10 like photos or software releases.
11
12 Directories in `add_underlays` should usually be absolute. If relative, they're
13 interpreted as relative to the parent directory of the basewiki underlay, which
14 is probably not particularly useful in this context.
15
16     #!/usr/bin/perl
17     package IkiWiki::Plugin::underlay;
18     # Copyright © 2008 Simon McVittie <http://smcv.pseudorandom.co.uk/>
19     # Licensed under the GNU GPL, version 2, or any later version published by the
20     # Free Software Foundation
21
22     use warnings;
23     use strict;
24     use IkiWiki 2.00;
25
26     sub import {
27         hook(type => "getsetup", id => "underlay",  call => \&getsetup);
28         hook(type => "checkconfig", id => "underlay", call => \&checkconfig);
29     }
30
31     sub getsetup () {
32         return
33                 plugin => {
34                         safe => 0,
35                         rebuild => undef,
36                 },
37                 add_underlays => {
38                         type => "string",
39                         default => [],
40                         description => "extra underlay directories to add",
41                         advanced => 1,
42                         safe => 0,
43                         rebuild => 1,
44                 },
45     }
46
47     sub checkconfig () {
48         return unless exists $config{add_underlays};
49
50         foreach my $dir (@{$config{add_underlays}}) {
51                 add_underlay($dir);
52         }
53     }
54
55     1;