2 package IkiWiki::Plugin::relativedate;
5 no warnings 'redefine';
12 add_underlay("javascript");
13 hook(type => "getsetup", id => "relativedate", call => \&getsetup);
14 hook(type => "format", id => "relativedate", call => \&format);
17 sub getsetup () { #{{{
28 if (! ($params{content}=~s!^(<body>)!$1.include_javascript($params{page})!em)) {
29 # no </body> tag, probably in preview mode
30 $params{content}=include_javascript($params{page}, 1).$params{content};
32 return $params{content};
35 sub include_javascript ($;$) { #{{{
39 return '<script src="'.urlto("ikiwiki.js", $page, $absolute).
40 '" type="text/javascript" charset="utf-8"></script>'."\n".
41 '<script src="'.urlto("relativedate.js", $page, $absolute).
42 '" type="text/javascript" charset="utf-8"></script>';
45 sub IkiWiki::displaytime ($;$) { #{{{
49 # This needs to be in a form that can be parsed by javascript.
50 # Being fairly human readable is also nice, as it will be exposed as the title
51 # if javascript is not available.
52 my $gmtime=decode_utf8(POSIX::strftime("%a, %d %b %Y %H:%M:%S %z", gmtime($time)));
54 return '<span class="date" title="'.$gmtime.'">'.
55 IkiWiki::formattime($time, $format).'</span>';