move plugin toggles to before config setting again
[ikiwiki] / IkiWiki / Plugin / mirrorlist.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::mirrorlist;
3
4 use warnings;
5 use strict;
6 use IkiWiki 2.00;
7
8 sub import { #{{{
9         hook(type => "getsetup", id => "mirrorlist", call => \&getsetup);
10         hook(type => "pagetemplate", id => "mirrorlist", call => \&pagetemplate);
11 } # }}}
12
13 sub getsetup () { #{{{
14         return
15                 plugin => {
16                         safe => 1,
17                         rebuild => 1,
18                 },
19                 mirrorlist => {
20                         type => "string",
21                         example => {},
22                         description => "list of mirrors",
23                         safe => 1,
24                         rebuild => 1,
25                 },
26 } #}}}
27
28 sub pagetemplate (@) { #{{{
29         my %params=@_;
30         my $template=$params{template};
31         
32         $template->param(extrafooter => mirrorlist($params{page}))
33                 if $template->query(name => "extrafooter");
34 } # }}}
35
36 sub mirrorlist ($) { #{{{
37         my $page=shift;
38         return "<p>".
39                 (keys %{$config{mirrorlist}} > 1 ? gettext("Mirrors") : gettext("Mirror")).
40                 ": ".
41                 join(", ",
42                         map { 
43                                 qq{<a href="}.
44                                 $config{mirrorlist}->{$_}."/".urlto($page, "").
45                                 qq{">$_</a>}
46                         } keys %{$config{mirrorlist}}
47                 ).
48                 "</p>";
49 } # }}}
50
51 1