From 7390a7a0721d9985c88efec1fd0e3a19d0368c82 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 17 Oct 2008 20:47:32 -0400 Subject: relativedate: New javascript-alicious plugin that makes all dates display relative, in a very nice way, if I say so myself. --- IkiWiki/Plugin/inline.pm | 2 ++ IkiWiki/Plugin/relativedate.pm | 41 +++++++++++++++++++++++++++++++++++++++++ IkiWiki/Render.pm | 2 ++ 3 files changed, 45 insertions(+) create mode 100644 IkiWiki/Plugin/relativedate.pm (limited to 'IkiWiki') 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!^()!$1.include_javascript($params{page})!em)) { + # no 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 ''."\n". + ''; +} #}}} + +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), ); -- cgit v1.2.3