summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/mirrorlist.pm
blob: 92be7913efaf871929d8c3e0746191888aa1f513 (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. section => "web",
  16. },
  17. mirrorlist => {
  18. type => "string",
  19. example => {},
  20. description => "list of mirrors",
  21. safe => 1,
  22. rebuild => 1,
  23. },
  24. }
  25. sub pagetemplate (@) {
  26. my %params=@_;
  27. my $template=$params{template};
  28. if ($template->query(name => "extrafooter") &&
  29. keys %{$config{mirrorlist}} > 0) {
  30. my $value=$template->param("extrafooter");
  31. $value.=mirrorlist($params{page});
  32. $template->param(extrafooter => $value);
  33. }
  34. }
  35. sub mirrorlist ($) {
  36. my $page=shift;
  37. return "<p>".
  38. (keys %{$config{mirrorlist}} > 1 ? gettext("Mirrors") : gettext("Mirror")).
  39. ": ".
  40. join(", ",
  41. map {
  42. qq{<a href="}.
  43. $config{mirrorlist}->{$_}."/".urlto($page, "").
  44. qq{">$_</a>}
  45. } keys %{$config{mirrorlist}}
  46. ).
  47. "</p>";
  48. }
  49. 1