summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/meta.pm
blob: 15a8bad845f08e389bbc656ff518947ff175c6b9 (plain)
  1. #!/usr/bin/perl
  2. # Ikiwiki metadata plugin.
  3. package IkiWiki::Plugin::meta;
  4. use warnings;
  5. use strict;
  6. use IkiWiki;
  7. my %meta;
  8. my %title;
  9. sub import { #{{{
  10. IkiWiki::hook(type => "preprocess", id => "meta",
  11. call => \&preprocess);
  12. IkiWiki::hook(type => "pagetemplate", id => "meta",
  13. call => \&pagetemplate);
  14. } # }}}
  15. sub preprocess (@) { #{{{
  16. if (! @_) {
  17. return "";
  18. }
  19. my %params=@_;
  20. my $key=shift;
  21. my $value=$params{$key};
  22. delete $params{$key};
  23. my $page=$params{page};
  24. delete $params{page};
  25. delete $params{destpage};
  26. eval q{use CGI 'escapeHTML'};
  27. if ($key eq 'link') {
  28. if (%params) {
  29. $meta{$page}='' unless exists $meta{$page};
  30. $meta{$page}.="<link href=\"".escapeHTML($value)."\" ".
  31. join(" ", map { escapeHTML("$_=\"$params{$_}\"") } keys %params).
  32. " />\n";
  33. }
  34. else {
  35. # hidden WikiLink
  36. push @{$IkiWiki::links{$page}}, $value;
  37. }
  38. }
  39. elsif ($key eq 'title') {
  40. $title{$page}=escapeHTML($value);
  41. }
  42. else {
  43. $meta{$page}='' unless exists $meta{$page};
  44. $meta{$page}.="<meta name=\"".escapeHTML($key)."\" content=\"".escapeHTML($value)."\" />\n";
  45. }
  46. return "";
  47. } # }}}
  48. sub pagetemplate (@) { #{{{
  49. my %params=@_;
  50. my $page=$params{page};
  51. my $template=$params{template};
  52. $template->param(meta => $meta{$page})
  53. if exists $meta{$page} && $template->query(name => "meta");
  54. $template->param(title => $title{$page})
  55. if exists $title{$page} && $template->query(name => "title");
  56. } # }}}
  57. 1