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/ikiwiki.js", $page, $absolute).
41 '" type="text/javascript" charset="utf-8"></script>'."\n".
42 '<script src="'.urlto("ikiwiki/relativedate.js", $page, $absolute).
43 '" type="text/javascript" charset="utf-8"></script>';
46 sub mydisplaytime ($;$$) {
51 # This needs to be in a form that can be parsed by javascript.
52 # (Being fairly human readable is also nice, as it will be exposed
53 # as the title if javascript is not available.)
54 my $lc_time=POSIX::setlocale(&POSIX::LC_TIME);
55 POSIX::setlocale(&POSIX::LC_TIME, "C");
56 my $gmtime=decode_utf8(POSIX::strftime("%a, %d %b %Y %H:%M:%S %z",
58 POSIX::setlocale(&POSIX::LC_TIME, $lc_time);
60 my $mid=' class="relativedate" title="'.$gmtime.'">'.
61 IkiWiki::formattime($time, $format);
64 return '<time datetime="'.IkiWiki::date_3339($time).'"'.
65 ($pubdate ? ' pubdate="pubdate"' : '').$mid.'</time>';
68 return '<span'.$mid.'</span>';