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!^(\s*</body[^>]*>)!include_javascript($params{page}).$1!em)) {
30 # no <body> tag, probably in preview mode
31 $params{content}=$params{content}.include_javascript(undef);
33 return $params{content};
36 sub include_javascript ($) {
39 return '<script src="'.urlto("ikiwiki/ikiwiki.js", $from).
40 '" type="text/javascript" charset="utf-8"></script>'."\n".
41 '<script src="'.urlto("ikiwiki/relativedate.js", $from).
42 '" type="text/javascript" charset="utf-8"></script>';
45 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 $lc_time=POSIX::setlocale(&POSIX::LC_TIME);
54 POSIX::setlocale(&POSIX::LC_TIME, "C");
55 my $gmtime=decode_utf8(POSIX::strftime("%a, %d %b %Y %H:%M:%S %z",
57 POSIX::setlocale(&POSIX::LC_TIME, $lc_time);
59 my $mid=' class="relativedate" title="'.$gmtime.'">'.
60 IkiWiki::formattime($time, $format);
63 return '<time datetime="'.IkiWiki::date_3339($time).'"'.
64 ($pubdate ? ' pubdate="pubdate"' : '').$mid.'</time>';
67 return '<span'.$mid.'</span>';