]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/relativedate.pm
po plugin: implemented po_link_to=negotiated
[ikiwiki.git] / IkiWiki / Plugin / relativedate.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::relativedate;
3
4 use warnings;
5 use strict;
6 use IkiWiki 2.00;
7
8 sub import { #{{{
9         add_underlay("javascript");
10         hook(type => "getsetup", id => "relativedate", call => \&getsetup);
11         hook(type => "format", id => "relativedate", call => \&format);
12 } # }}}
13
14 sub getsetup () { #{{{
15         return
16                 plugin => {
17                         safe => 1,
18                         rebuild => 1,
19                 },
20 } #}}}
21
22 sub format (@) { #{{{
23         my %params=@_;
24
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 } # }}}
31
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 } #}}}
41
42 1