rebuild not needed
[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                 },
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         if ($template->query(name => "extrafooter")) {
33                 my $value=$template->param("extrafooter");
34                 $value.=mirrorlist($params{page});
35                 $template->param(extrafooter => $value);
36         }
37 }
38
39 sub mirrorlist ($) {
40         my $page=shift;
41         return "<p>".
42                 (keys %{$config{mirrorlist}} > 1 ? gettext("Mirrors") : gettext("Mirror")).
43                 ": ".
44                 join(", ",
45                         map { 
46                                 qq{<a href="}.
47                                 $config{mirrorlist}->{$_}."/".urlto($page, "").
48                                 qq{">$_</a>}
49                         } keys %{$config{mirrorlist}}
50                 ).
51                 "</p>";
52 }
53
54 1