summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/mirrorlist.pm
blob: d0a6107efe8baa6cadd540eb710f5f8f422c6778 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::mirrorlist;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 3.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. keys %{$config{mirrorlist}} > 0) {
  29. my $value=$template->param("extrafooter");
  30. $value.=mirrorlist($params{page});
  31. $template->param(extrafooter => $value);
  32. }
  33. }
  34. sub mirrorlist ($) {
  35. my $page=shift;
  36. return "<p>".
  37. (keys %{$config{mirrorlist}} > 1 ? gettext("Mirrors") : gettext("Mirror")).
  38. ": ".
  39. join(", ",
  40. map {
  41. qq{<a href="}.
  42. $config{mirrorlist}->{$_}."/".urlto($page, "").
  43. qq{">$_</a>}
  44. } keys %{$config{mirrorlist}}
  45. ).
  46. "</p>";
  47. }
  48. 1