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);
15 inject(name => "IkiWiki::displaytime", call => \&mydisplaytime);
29 if (! ($params{content}=~s!^(<body[^>]*>)!$1.include_javascript($params{page})!em)) {
30 # no </body> tag, probably in preview mode
31 $params{content}=include_javascript($params{page}, 1).$params{content};
33 return $params{content};
36 sub include_javascript ($;$) {
40 return '<script src="'.urlto("ikiwiki.js", $page, $absolute).
41 '" type="text/javascript" charset="utf-8"></script>'."\n".
42 '<script src="'.urlto("relativedate.js", $page, $absolute).
43 '" type="text/javascript" charset="utf-8"></script>';
46 sub mydisplaytime ($;$) {
50 # This needs to be in a form that can be parsed by javascript.
51 # Being fairly human readable is also nice, as it will be exposed
52 # as the title if javascript is not available.
53 my $gmtime=decode_utf8(POSIX::strftime("%a, %d %b %Y %H:%M:%S %z",
56 return '<span class="relativedate" title="'.$gmtime.'">'.
57 IkiWiki::formattime($time, $format).'</span>';