response
[ikiwiki.git] / IkiWiki / Plugin / mirrorlist.pm
blobf54d94ad52366110e29f20575672bcd0fcc4413c
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::mirrorlist;
4 use warnings;
5 use strict;
6 use IkiWiki 3.00;
8 sub import {
9 hook(type => "getsetup", id => "mirrorlist", call => \&getsetup);
10 hook(type => "pagetemplate", id => "mirrorlist", call => \&pagetemplate);
13 sub getsetup () {
14 return
15 plugin => {
16 safe => 1,
17 rebuild => 1,
18 section => "web",
20 mirrorlist => {
21 type => "string",
22 example => {},
23 description => "list of mirrors",
24 safe => 1,
25 rebuild => 1,
29 sub pagetemplate (@) {
30 my %params=@_;
31 my $template=$params{template};
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);
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}}
53 ($config{html5} ? '</nav>' : '</div>');