]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - IkiWiki/Plugin/relativedate.pm
99265676b7cfd3bde4067e469af1b09bbb99dd51
[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 => "format", id => "relativedate", call => \&format);
11 } # }}}
13 sub getsetup () { #{{{
14         return
15                 plugin => {
16                         safe => 1,
17                         rebuild => 1,
18                 },
19 } #}}}
21 sub format (@) { #{{{
22         my %params=@_;
24         if (! ($params{content}=~s!^(<body>)!$1.include_javascript($params{page})!em)) {
25                 # no </body> tag, probably in preview mode
26                 $params{content}=include_javascript($params{page}, 1).$params{content};
27         }
28         return $params{content};
29 } # }}}
31 sub include_javascript ($;$) { #{{{
32         my $page=shift;
33         my $absolute=shift;
34         
35         return '<script src="'.urlto("ikiwiki.js", $page, $absolute).
36                 '" type="text/javascript" charset="utf-8"></script>'."\n".
37                 '<script src="'.urlto("relativedate.js", $page, $absolute).
38                 '" type="text/javascript" charset="utf-8"></script>';
39 } #}}}
41 1