]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/relativedate.pm
po plugin: implement linking specification in one of the main cases
[git.ikiwiki.info.git] / IkiWiki / Plugin / relativedate.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::relativedate;
4 use warnings;
5 use strict;
6 use IkiWiki 2.00;
8 sub import { #{{{
9         add_underlay("javascript");
10         hook(type => "getsetup", id => "relativedate", call => \&getsetup);
11         hook(type => "format", id => "relativedate", call => \&format);
12 } # }}}
14 sub getsetup () { #{{{
15         return
16                 plugin => {
17                         safe => 1,
18                         rebuild => 1,
19                 },
20 } #}}}
22 sub format (@) { #{{{
23         my %params=@_;
25         if (! ($params{content}=~s!^(<body>)!$1.include_javascript($params{page})!em)) {
26                 # no </body> tag, probably in preview mode
27                 $params{content}=include_javascript($params{page}, 1).$params{content};
28         }
29         return $params{content};
30 } # }}}
32 sub include_javascript ($;$) { #{{{
33         my $page=shift;
34         my $absolute=shift;
35         
36         return '<script src="'.urlto("ikiwiki.js", $page, $absolute).
37                 '" type="text/javascript" charset="utf-8"></script>'."\n".
38                 '<script src="'.urlto("relativedate.js", $page, $absolute).
39                 '" type="text/javascript" charset="utf-8"></script>';
40 } #}}}
42 1