store filename in holding dir in linkpage form
[ikiwiki] / IkiWiki / Plugin / mirrorlist.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::mirrorlist;
3
4 use warnings;
5 use strict;
6 use IkiWiki 3.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                         section => "web",
19                 },
20                 mirrorlist => {
21                         type => "string",
22                         example => {},
23                         description => "list of mirrors",
24                         safe => 1,
25                         rebuild => 1,
26                 },
27 }
28
29 sub pagetemplate (@) {
30         my %params=@_;
31         my $template=$params{template};
32         
33         if ($template->query(name => "extrafooter") &&
34             keys %{$config{mirrorlist}} > 0) {
35                 my $value=$template->param("extrafooter");
36                 $value.=mirrorlist($params{page});
37                 $template->param(extrafooter => $value);
38         }
39 }
40
41 sub mirrorlist ($) {
42         my $page=shift;
43         return ($config{html5} ? '<nav id="mirrorlist">' : '<div>').
44                 (keys %{$config{mirrorlist}} > 1 ? gettext("Mirrors") : gettext("Mirror")).
45                 ": ".
46                 join(", ",
47                         map { 
48                                 qq{<a href="}.
49                                 $config{mirrorlist}->{$_}."/".urlto($page, "").
50                                 qq{">$_</a>}
51                         } keys %{$config{mirrorlist}}
52                 ).
53                 ($config{html5} ? '</nav>' : '</div>');
54 }
55
56 1