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