]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/relativedate.pm
relativedate: New javascript-alicious plugin that makes all dates display relative...
[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 => "format", id => "relativedate", call => \&format);
11 } # }}}
12
13 sub getsetup () { #{{{
14         return
15                 plugin => {
16                         safe => 1,
17                         rebuild => 1,
18                 },
19 } #}}}
20
21 sub format (@) { #{{{
22         my %params=@_;
23
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 } # }}}
30
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 } #}}}
40
41 1