summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/relativedate.pm
blob: 2895f6d57ecf84876ed0be1de8d07254ab52ca9f (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::relativedate;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 2.00;
  6. sub import { #{{{
  7. add_underlay("javascript");
  8. hook(type => "getsetup", id => "relativedate", call => \&getsetup);
  9. hook(type => "format", id => "relativedate", call => \&format);
  10. } # }}}
  11. sub getsetup () { #{{{
  12. return
  13. plugin => {
  14. safe => 1,
  15. rebuild => 1,
  16. },
  17. } #}}}
  18. sub format (@) { #{{{
  19. my %params=@_;
  20. if (! ($params{content}=~s!^(<body>)!$1.include_javascript($params{page})!em)) {
  21. # no </body> tag, probably in preview mode
  22. $params{content}=include_javascript($params{page}, 1).$params{content};
  23. }
  24. return $params{content};
  25. } # }}}
  26. sub include_javascript ($;$) { #{{{
  27. my $page=shift;
  28. my $absolute=shift;
  29. return '<script src="'.urlto("ikiwiki.js", $page, $absolute).
  30. '" type="text/javascript" charset="utf-8"></script>'."\n".
  31. '<script src="'.urlto("relativedate.js", $page, $absolute).
  32. '" type="text/javascript" charset="utf-8"></script>';
  33. } #}}}
  34. 1