summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/meta.pm
blob: 41d096e0ea9cdd440eac14325112d643981944d2 (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. eval q{use CGI 'escapeHTML'};
  26. if ($key eq 'link') {
  27. if (%params) {
  28. $meta{$page}='' unless exists $meta{$page};
  29. $meta{$page}.="<link href=\"".escapeHTML($value)."\" ".
  30. join(" ", map { escapeHTML("$_=\"$params{$_}\"") } keys %params).
  31. " />\n";
  32. }
  33. else {
  34. # hidden WikiLink
  35. push @{$IkiWiki::links{$page}}, $value;
  36. }
  37. }
  38. elsif ($key eq 'title') {
  39. $title{$page}=escapeHTML($value);
  40. }
  41. else {
  42. $meta{$page}='' unless exists $meta{$page};
  43. $meta{$page}.="<meta name=\"".escapeHTML($key)."\" content=\"".escapeHTML($value)."\" />\n";
  44. }
  45. return "";
  46. } # }}}
  47. sub pagetemplate ($$) { #{{{
  48. my $page=shift;
  49. my $template=shift;
  50. $template->param(meta => $meta{$page}) if exists $meta{$page};
  51. $template->param(title => $title{$page}) if exists $title{$page};
  52. } # }}}
  53. 1