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/Plugin/relativedate.pm | |
parent | 9a62836d288fbced42b04a172baf52063ef71c61 (diff) | |
download | ikiwiki-7390a7a0721d9985c88efec1fd0e3a19d0368c82.tar ikiwiki-7390a7a0721d9985c88efec1fd0e3a19d0368c82.tar.gz |
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/Plugin/relativedate.pm')
-rw-r--r-- | IkiWiki/Plugin/relativedate.pm | 41 |
1 files changed, 41 insertions, 0 deletions
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 |