diff options
author | Joey Hess <joey@kodama.kitenet.net> | 2008-10-17 20:47:32 -0400 |
---|---|---|
committer | Joey Hess <joey@kodama.kitenet.net> | 2008-10-17 20:47:32 -0400 |
commit | 7390a7a0721d9985c88efec1fd0e3a19d0368c82 (patch) | |
tree | 5573d9a86849bb3d180ad26132e8f1abf6fdd53c /IkiWiki | |
parent | 9a62836d288fbced42b04a172baf52063ef71c61 (diff) |
relativedate: New javascript-alicious plugin that makes all dates display relative, in a very nice way, if I say so myself.
Diffstat (limited to 'IkiWiki')
-rw-r--r-- | IkiWiki/Plugin/inline.pm | 2 | ||||
-rw-r--r-- | IkiWiki/Plugin/relativedate.pm | 41 | ||||
-rw-r--r-- | IkiWiki/Render.pm | 2 |
3 files changed, 45 insertions, 0 deletions
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 6d88c2f15..536d7cd02 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -316,7 +316,9 @@ sub preprocess_inline (@) { #{{{ $template->param(pageurl => urlto(bestlink($params{page}, $page), $params{destpage})); $template->param(title => pagetitle(basename($page))); $template->param(ctime => displaytime($pagectime{$page}, $params{timeformat})); + $template->param(ctime_raw => scalar localtime($pagectime{$page})); $template->param(mtime => displaytime($pagemtime{$page}, $params{timeformat})); + $template->param(mtime_raw => scalar localtime($pagemtime{$page})); $template->param(first => 1) if $page eq $list[0]; $template->param(last => 1) if $page eq $list[$#list]; diff --git a/IkiWiki/Plugin/relativedate.pm b/IkiWiki/Plugin/relativedate.pm new file mode 100644 index 000000000..99265676b --- /dev/null +++ b/IkiWiki/Plugin/relativedate.pm @@ -0,0 +1,41 @@ +#!/usr/bin/perl +package IkiWiki::Plugin::relativedate; + +use warnings; +use strict; +use IkiWiki 2.00; + +sub import { #{{{ + add_underlay("javascript"); + hook(type => "format", id => "relativedate", call => \&format); +} # }}} + +sub getsetup () { #{{{ + return + plugin => { + safe => 1, + rebuild => 1, + }, +} #}}} + +sub format (@) { #{{{ + my %params=@_; + + if (! ($params{content}=~s!^(<body>)!$1.include_javascript($params{page})!em)) { + # no </body> tag, probably in preview mode + $params{content}=include_javascript($params{page}, 1).$params{content}; + } + return $params{content}; +} # }}} + +sub include_javascript ($;$) { #{{{ + my $page=shift; + my $absolute=shift; + + return '<script src="'.urlto("ikiwiki.js", $page, $absolute). + '" type="text/javascript" charset="utf-8"></script>'."\n". + '<script src="'.urlto("relativedate.js", $page, $absolute). + '" type="text/javascript" charset="utf-8"></script>'; +} #}}} + +1 diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index bc997ffb0..8385c1aff 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -109,7 +109,9 @@ sub genpage ($$) { #{{{ backlinks => $backlinks, more_backlinks => $more_backlinks, mtime => displaytime($pagemtime{$page}), + mtime_raw => scalar localtime($pagemtime{$page}), ctime => displaytime($pagectime{$page}), + ctime_raw => scalar localtime($pagectime{$page}), baseurl => baseurl($page), ); |