From 7a1e12675ec5f1ea605d4de06a0b82079073fb20 Mon Sep 17 00:00:00 2001 From: joey Date: Mon, 29 May 2006 05:09:43 +0000 Subject: [PATCH] * Add --timeformat config option to allow changing how dates are displayed. Note that as a side effect, dates will now be displayed using the local timezone, not as GMT. --- IkiWiki.pm | 1 + IkiWiki/Plugin/inline.pm | 2 +- IkiWiki/Render.pm | 14 +++++++++++++- debian/changelog | 8 ++++++++ doc/ikiwiki.setup | 2 ++ doc/todo/{ => done}/strftime.mdwn | 0 doc/usage.mdwn | 5 +++++ ikiwiki | 1 + 8 files changed, 31 insertions(+), 2 deletions(-) rename doc/todo/{ => done}/strftime.mdwn (100%) diff --git a/IkiWiki.pm b/IkiWiki.pm index 5424d435c..ce9542f62 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -42,6 +42,7 @@ sub defaultconfig () { #{{{ adminuser => undef, adminemail => undef, plugin => [qw{inline htmlscrubber}], + timeformat => '%c', } #}}} sub checkconfig () { #{{{ diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 8b67bfa61..6ecdf0d38 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -62,7 +62,7 @@ sub preprocess_inline (@) { #{{{ $template->param(pagelink => htmllink($params{page}, $params{page}, $page)); $template->param(content => get_inline_content($params{page}, $page)) if $params{archive} eq "no"; - $template->param(ctime => scalar(gmtime($pagectime{$page}))); + $template->param(ctime => displaytime($pagectime{$page})); $ret.=$template->output; } diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index df08eb49c..c5922c933 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -202,7 +202,7 @@ sub genpage ($$$) { #{{{ parentlinks => [parentlinks($page)], content => $content, backlinks => [backlinks($page)], - mtime => scalar(gmtime($mtime)), + mtime => displaytime($mtime), styleurl => styleurl($page), ); @@ -223,6 +223,18 @@ sub check_overwrite ($$) { #{{{ } } #}}} +sub displaytime ($) { #{{{ + my $time=shift; + + if ($config{timeformat} eq '%c') { + return scalar(localtime($time)); # optimisation + } + else { + eval q{use POSIX}; + return POSIX::strftime($config{timeformat}, localtime($time)); + } +} #}}} + sub mtime ($) { #{{{ my $file=shift; diff --git a/debian/changelog b/debian/changelog index 10796a63a..f7a381e41 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,11 @@ +ikiwiki (1.5) UNRELEASED; urgency=low + + * Add --timeformat config option to allow changing how dates are displayed. + Note that as a side effect, dates will now be displayed using the local + timezone, not as GMT. + + -- Joey Hess Mon, 29 May 2006 00:50:34 -0400 + ikiwiki (1.4) unstable; urgency=low * Tell HTML::Scrubber to treat "/" as a valid attribute which is its diff --git a/doc/ikiwiki.setup b/doc/ikiwiki.setup index dee4ca1d5..cda524ae1 100644 --- a/doc/ikiwiki.setup +++ b/doc/ikiwiki.setup @@ -50,6 +50,8 @@ use IkiWiki::Setup::Standard { rss => 1, # Include discussion links on all pages? discussion => 1, + # Time format (for strftime) + #timeformat => '%c', # To change the enabled plugins, edit this list #plugin => [qw{pagecount inline brokenlinks search smiley # htmlscrubber}], diff --git a/doc/todo/strftime.mdwn b/doc/todo/done/strftime.mdwn similarity index 100% rename from doc/todo/strftime.mdwn rename to doc/todo/done/strftime.mdwn diff --git a/doc/usage.mdwn b/doc/usage.mdwn index c0fab5232..011cf53a2 100644 --- a/doc/usage.mdwn +++ b/doc/usage.mdwn @@ -177,6 +177,11 @@ These options configure the wiki. Enables or disables "Discussion" links from being added to the header of every page. The links are enabled by default. +* --timeformat format + + Specify how to display the time or date. The format string is passed to the + strftime(3) function. + * --verbose Be vebose about what is being done. diff --git a/ikiwiki b/ikiwiki index 3ea6b7aa0..61b66374d 100755 --- a/ikiwiki +++ b/ikiwiki @@ -37,6 +37,7 @@ sub getconfig () { #{{{ "svnrepo" => \$config{svnrepo}, "svnpath" => \$config{svnpath}, "adminemail=s" => \$config{adminemail}, + "timeformat=s" => \$config{timeformat}, "exclude=s@" => sub { $config{wiki_file_prune_regexp}=qr/$config{wiki_file_prune_regexp}|$_[1]/; }, -- 2.26.2