From 970373548fda77223ebbeb6aadbdbe4884b67cef Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 2 May 2010 13:44:13 -0400 Subject: [PATCH] Add parameter to displaytime to specify that it is a pubdate, and in html5 mode, use time tag. --- IkiWiki.pm | 22 ++++++++++++++++++++-- IkiWiki/Plugin/comments.pm | 2 +- IkiWiki/Plugin/inline.pm | 12 +----------- IkiWiki/Plugin/relativedate.pm | 15 ++++++++++++--- IkiWiki/Render.pm | 2 +- debian/changelog | 7 +++++++ doc/bugs/html5_support.mdwn | 3 +++ doc/plugins/write.mdwn | 5 ++++- 8 files changed, 49 insertions(+), 19 deletions(-) diff --git a/IkiWiki.pm b/IkiWiki.pm index ed57710bb..c428de77f 100644 --- a/IkiWiki.pm +++ b/IkiWiki.pm @@ -998,10 +998,18 @@ sub abs2rel ($$) { return $ret; } -sub displaytime ($;$) { +sub displaytime ($;$$) { # Plugins can override this function to mark up the time to # display. - return ''.formattime(@_).''; + my $time=formattime($_[0], $_[1]); + if ($config{html5}) { + return ''; + } + else { + return ''.$time.''; + } } sub formattime ($;$) { @@ -1017,6 +1025,16 @@ sub formattime ($;$) { return decode_utf8(POSIX::strftime($format, localtime($time))); } +sub date_3339 ($) { + my $time=shift; + + my $lc_time=POSIX::setlocale(&POSIX::LC_TIME); + POSIX::setlocale(&POSIX::LC_TIME, "C"); + my $ret=POSIX::strftime("%Y-%m-%dT%H:%M:%SZ", gmtime($time)); + POSIX::setlocale(&POSIX::LC_TIME, $lc_time); + return $ret; +} + sub beautify_urlpath ($) { my $url=shift; diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm index f7dc99dca..02f1d9301 100644 --- a/IkiWiki/Plugin/comments.pm +++ b/IkiWiki/Plugin/comments.pm @@ -672,7 +672,7 @@ sub previewcomment ($$$) { my $template = template("comment.tmpl"); $template->param(content => $preview); - $template->param(ctime => displaytime($time)); + $template->param(ctime => displaytime($time, undef, 1)); IkiWiki::run_hooks(pagetemplate => sub { shift->(page => $location, diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm index 95fe90312..2df59f414 100644 --- a/IkiWiki/Plugin/inline.pm +++ b/IkiWiki/Plugin/inline.pm @@ -358,7 +358,7 @@ sub preprocess_inline (@) { $template->param(pageurl => urlto($page, $params{destpage})); $template->param(inlinepage => $page); $template->param(title => pagetitle(basename($page))); - $template->param(ctime => displaytime($pagectime{$page}, $params{timeformat})); + $template->param(ctime => displaytime($pagectime{$page}, $params{timeformat}, 1)); $template->param(mtime => displaytime($pagemtime{$page}, $params{timeformat})); $template->param(first => 1) if $page eq $list[0]; $template->param(last => 1) if $page eq $list[$#list]; @@ -500,16 +500,6 @@ sub date_822 ($) { return $ret; } -sub date_3339 ($) { - my $time=shift; - - my $lc_time=POSIX::setlocale(&POSIX::LC_TIME); - POSIX::setlocale(&POSIX::LC_TIME, "C"); - my $ret=POSIX::strftime("%Y-%m-%dT%H:%M:%SZ", gmtime($time)); - POSIX::setlocale(&POSIX::LC_TIME, $lc_time); - return $ret; -} - sub absolute_urls ($$) { # sucky sub because rss sucks my $content=shift; diff --git a/IkiWiki/Plugin/relativedate.pm b/IkiWiki/Plugin/relativedate.pm index 7e615f7f1..fe8ef0901 100644 --- a/IkiWiki/Plugin/relativedate.pm +++ b/IkiWiki/Plugin/relativedate.pm @@ -43,9 +43,10 @@ sub include_javascript ($;$) { '" type="text/javascript" charset="utf-8">'; } -sub mydisplaytime ($;$) { +sub mydisplaytime ($;$$) { my $time=shift; my $format=shift; + my $pubdate=shift; # This needs to be in a form that can be parsed by javascript. # Being fairly human readable is also nice, as it will be exposed @@ -53,8 +54,16 @@ sub mydisplaytime ($;$) { my $gmtime=decode_utf8(POSIX::strftime("%a, %d %b %Y %H:%M:%S %z", localtime($time))); - return ''. - IkiWiki::formattime($time, $format).''; + my $mid=' class="relativedate" title="'.$gmtime.'">'. + IkiWiki::formattime($time, $format); + + if ($config{html5}) { + return '