1 I sometimes want to inline things with the complete date and time, and
2 sometimes need only the date. I know about the prettydate plugin that
3 already makes the time a bit "nicer" to read, but sometimes I just
6 Here's a patch to add a DATE parameter for use in templates as
7 controlled by a Tdateformat setting in the setup.
9 I explicitly did not edit any date-related plugins, (for fear of
10 breaking them as I don't use them so I wouldn't be testing them). But
11 it occurs to me that it might be correct to not touch them anyway,
12 (since things like prettydate are really more concerned with changing
13 the presentation of the time, not the date).
15 I also didn't edit the sample setup file, (since I'm just using a git
16 repository setup on my local /usr/share/perl5/IkiWiki directory
17 here). But, ah, now that I look, I do see that there's a "real" git
18 repository advertised with the ikiwiki source. I'll have to start
19 using that for future patches, (so let me know if you want me to
20 regenerate this one against that).
24 From 325d208d8dc8016a377bb7c923a51af2bd3355b0 Mon Sep 17 00:00:00 2001
25 From: Carl Worth <cworth@cworth.org>
26 Date: Tue, 3 Jul 2007 11:39:03 -0700
27 Subject: [PATCH] Allow DATE as a template parameter (with format controlled by dateformat setting)
30 IkiWiki.pm | 12 +++++++++++-
31 Plugin/inline.pm | 1 +
32 2 files changed, 12 insertions(+), 1 deletions(-)
34 diff --git a/IkiWiki.pm b/IkiWiki.pm
35 index cd42e8d..ebf0474 100644
38 @@ -16,7 +16,7 @@ use vars qw{%config %links %oldlinks %pagemtime %pagectime %pagecase
39 use Exporter q{import};
40 our @EXPORT = qw(hook debug error template htmlpage add_depends pagespec_match
41 bestlink htmllink readfile writefile pagetype srcfile pagename
42 - displaytime will_render gettext urlto targetpage
43 + displaytime displaydate will_render gettext urlto targetpage
44 %config %links %renderedfiles %pagesources %destsources);
45 our $VERSION = 2.00; # plugin interface version, next is ikiwiki version
46 our $version="2.1";my $installdir="/usr";
47 @@ -70,6 +70,7 @@ sub defaultconfig () {
48 plugin => [qw{mdwn inline htmlscrubber passwordauth openid signinedit
49 lockedit conditional}],
55 @@ -447,6 +448,15 @@ sub displaytime ($) {
56 $config{timeformat}, localtime($time)));
59 +sub displaydate ($) {
62 + # strftime doesn't know about encodings, so make sure
63 + # its output is properly treated as utf8
64 + return decode_utf8(POSIX::strftime(
65 + $config{dateformat}, localtime($time)));
68 sub beautify_url ($) {
71 diff --git a/Plugin/inline.pm b/Plugin/inline.pm
72 index 8f6ab51..7bd6147 100644
73 --- a/Plugin/inline.pm
74 +++ b/Plugin/inline.pm
75 @@ -148,6 +148,7 @@ sub preprocess_inline (@) {
76 $template->param(pageurl => urlto(bestlink($params{page}, $page), $params{destpage}));
77 $template->param(title => pagetitle(basename($page)));
78 $template->param(ctime => displaytime($pagectime{$page}));
79 + $template->param(date => displaydate($pagectime{$page}));
82 my $file = $pagesources{$page};