Add parameter to displaytime to specify that it is a pubdate, and in html5 mode, use time tag.

master
Joey Hess 2010-05-02 13:44:13 -04:00
parent f9e41d19b7
commit 970373548f
8 changed files with 49 additions and 19 deletions

View File

@ -998,10 +998,18 @@ sub abs2rel ($$) {
return $ret; return $ret;
} }
sub displaytime ($;$) { sub displaytime ($;$$) {
# Plugins can override this function to mark up the time to # Plugins can override this function to mark up the time to
# display. # display.
return '<span class="date">'.formattime(@_).'</span>'; my $time=formattime($_[0], $_[1]);
if ($config{html5}) {
return '<time datetime="'.date_3339($_[0]).'"'.
($_[2] ? ' pubdate' : '').
'>'.$time.'</time>';
}
else {
return '<span class="date">'.$time.'</span>';
}
} }
sub formattime ($;$) { sub formattime ($;$) {
@ -1017,6 +1025,16 @@ sub formattime ($;$) {
return decode_utf8(POSIX::strftime($format, localtime($time))); 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 ($) { sub beautify_urlpath ($) {
my $url=shift; my $url=shift;

View File

@ -672,7 +672,7 @@ sub previewcomment ($$$) {
my $template = template("comment.tmpl"); my $template = template("comment.tmpl");
$template->param(content => $preview); $template->param(content => $preview);
$template->param(ctime => displaytime($time)); $template->param(ctime => displaytime($time, undef, 1));
IkiWiki::run_hooks(pagetemplate => sub { IkiWiki::run_hooks(pagetemplate => sub {
shift->(page => $location, shift->(page => $location,

View File

@ -358,7 +358,7 @@ sub preprocess_inline (@) {
$template->param(pageurl => urlto($page, $params{destpage})); $template->param(pageurl => urlto($page, $params{destpage}));
$template->param(inlinepage => $page); $template->param(inlinepage => $page);
$template->param(title => pagetitle(basename($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(mtime => displaytime($pagemtime{$page}, $params{timeformat}));
$template->param(first => 1) if $page eq $list[0]; $template->param(first => 1) if $page eq $list[0];
$template->param(last => 1) if $page eq $list[$#list]; $template->param(last => 1) if $page eq $list[$#list];
@ -500,16 +500,6 @@ sub date_822 ($) {
return $ret; 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 ($$) { sub absolute_urls ($$) {
# sucky sub because rss sucks # sucky sub because rss sucks
my $content=shift; my $content=shift;

View File

@ -43,9 +43,10 @@ sub include_javascript ($;$) {
'" type="text/javascript" charset="utf-8"></script>'; '" type="text/javascript" charset="utf-8"></script>';
} }
sub mydisplaytime ($;$) { sub mydisplaytime ($;$$) {
my $time=shift; my $time=shift;
my $format=shift; my $format=shift;
my $pubdate=shift;
# This needs to be in a form that can be parsed by javascript. # 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 # 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", my $gmtime=decode_utf8(POSIX::strftime("%a, %d %b %Y %H:%M:%S %z",
localtime($time))); localtime($time)));
return '<span class="relativedate" title="'.$gmtime.'">'. my $mid=' class="relativedate" title="'.$gmtime.'">'.
IkiWiki::formattime($time, $format).'</span>'; IkiWiki::formattime($time, $format);
if ($config{html5}) {
return '<time datetime="'.IkiWiki::date_3339($time).'"'.
($pubdate ? ' pubdate' : '').$mid.'</time>';
}
else {
return '<span'.$mid.'</span>';
}
} }
1 1

View File

@ -136,7 +136,7 @@ sub genpage ($$) {
backlinks => $backlinks, backlinks => $backlinks,
more_backlinks => $more_backlinks, more_backlinks => $more_backlinks,
mtime => displaytime($pagemtime{$page}), mtime => displaytime($pagemtime{$page}),
ctime => displaytime($pagectime{$page}), ctime => displaytime($pagectime{$page}, undef, 1),
baseurl => baseurl($page), baseurl => baseurl($page),
html5 => $config{html5}, html5 => $config{html5},
); );

7
debian/changelog vendored
View File

@ -1,3 +1,10 @@
ikiwiki (3.20100502) UNRELEASED; urgency=low
* Add parameter to displaytime to specify that it is a pubdate,
and in html5 mode, use time tag.
-- Joey Hess <joeyh@debian.org> Sun, 02 May 2010 13:22:50 -0400
ikiwiki (3.20100501) unstable; urgency=low ikiwiki (3.20100501) unstable; urgency=low
* TMPL_INCLUDE re-enabled for templates read from the templatedir. * TMPL_INCLUDE re-enabled for templates read from the templatedir.

View File

@ -133,6 +133,9 @@ As a workaround:
> Also, the [[plugins/relativedate]] plugin needs to be updated to > Also, the [[plugins/relativedate]] plugin needs to be updated to
> support relatatizing the contents of time elements. --[[Joey]] > support relatatizing the contents of time elements. --[[Joey]]
> Done and done; in html5 mode it uses the time tag, and even
> adds pubdate when displaying ctimes. --[[Joey]]
## tidy plugin ## tidy plugin
Will reformat html5 to html4. Will reformat html5 to html4.

View File

@ -938,13 +938,16 @@ search for files.
If the directory name is not absolute, ikiwiki will assume it is in If the directory name is not absolute, ikiwiki will assume it is in
the parent directory of the configured underlaydir. the parent directory of the configured underlaydir.
### `displaytime($;$)` ### `displaytime($;$$)`
Given a time, formats it for display. Given a time, formats it for display.
The optional second parameter is a strftime format to use to format the The optional second parameter is a strftime format to use to format the
time. time.
If the third parameter is true, this is the publication time of a page.
(Ie, set the html5 pubdate attribute.)
### `gettext` ### `gettext`
This is the standard gettext function, although slightly optimised. This is the standard gettext function, although slightly optimised.