$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];
--- /dev/null
+#!/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!^(<body>)!$1.include_javascript($params{page})!em)) {
+ # no </body> 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 '<script src="'.urlto("ikiwiki.js", $page, $absolute).
+ '" type="text/javascript" charset="utf-8"></script>'."\n".
+ '<script src="'.urlto("relativedate.js", $page, $absolute).
+ '" type="text/javascript" charset="utf-8"></script>';
+} #}}}
+
+1
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),
);
code.
* toggle: Stop embedding the full toggle code on each page using it, and
move it to toggle.js in the javascript underlay.
+ * relativedate: New javascript-alicious plugin that makes all dates display
+ relative, in a very nice way, if I say so myself.
-- Joey Hess <joeyh@debian.org> Fri, 17 Oct 2008 20:11:02 -0400
[[!template id=plugin name=ddate author="[[Joey]]"]]
[[!tag type/fun]]
+[[!tag type/date]]
Enables use of Discordian dates. `--timeformat` can be used to change
the date format; see `ddate(1)`.
[[!template id=plugin name=prettydate author="[[Joey]]"]]
-[[!tag type/format]]
+[[!tag type/date]]
Enabling this plugin changes the dates displayed on pages in the wiki to
a format that is nice and easy to read. Examples: "late Wednesday evening,
--- /dev/null
+[[!template id=plugin name=prettydate author="[[Joey]]"]]
+[[!tag type/date]]
+
+This plugin lets dates be displayed in relative form. Examples: "2 days ago",
+"1 month and 3 days ago", "30 minutes ago". Hovering over the date will
+cause a tooltip to pop up with the absolute date.
+
+This only works in browsers with javascript enabled; other browsers will
+show the absolute date instead. Also, this plugin can be used with other
+plugins like [[prettydate]] that change how the absolute date is displayed.
+
+If this plugin is enabled, you may also add relative dates to pages in the
+wiki, by using html elements in the "date" class. For example, this will
+display as a relative date:
+
+ <span class="date">Fri Oct 17 18:36:13 EDT 2008</span>
--- /dev/null
+These plugins control how ikiwiki displays dates.
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2008-10-17 20:11-0400\n"
+"POT-Creation-Date: 2008-10-17 20:39-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
msgstr ""
#: ../IkiWiki/Plugin/brokenlinks.pm:33 ../IkiWiki/Plugin/editpage.pm:261
-#: ../IkiWiki/Plugin/inline.pm:327 ../IkiWiki/Plugin/opendiscussion.pm:26
+#: ../IkiWiki/Plugin/inline.pm:329 ../IkiWiki/Plugin/opendiscussion.pm:26
#: ../IkiWiki/Plugin/orphans.pm:37 ../IkiWiki/Render.pm:79
-#: ../IkiWiki/Render.pm:149
+#: ../IkiWiki/Render.pm:151
msgid "discussion"
msgstr ""
msgid "nonexistant template %s"
msgstr ""
-#: ../IkiWiki/Plugin/inline.pm:335 ../IkiWiki/Render.pm:83
+#: ../IkiWiki/Plugin/inline.pm:337 ../IkiWiki/Render.pm:83
msgid "Discussion"
msgstr ""
-#: ../IkiWiki/Plugin/inline.pm:572
+#: ../IkiWiki/Plugin/inline.pm:574
msgid "RPC::XML::Client not found, not pinging"
msgstr ""
msgid "<p class=\"error\">Error: %s exited nonzero (%s)"
msgstr ""
-#: ../IkiWiki/Render.pm:253
+#: ../IkiWiki/Render.pm:255
#, perl-format
msgid ""
"symlink found in srcdir path (%s) -- set allow_symlinks_before_srcdir to "
"allow this"
msgstr ""
-#: ../IkiWiki/Render.pm:277 ../IkiWiki/Render.pm:302
+#: ../IkiWiki/Render.pm:279 ../IkiWiki/Render.pm:304
#, perl-format
msgid "skipping bad filename %s"
msgstr ""
-#: ../IkiWiki/Render.pm:284
+#: ../IkiWiki/Render.pm:286
#, perl-format
msgid "%s has multiple possible source pages"
msgstr ""
-#: ../IkiWiki/Render.pm:360
+#: ../IkiWiki/Render.pm:362
#, perl-format
msgid "removing old page %s"
msgstr ""
-#: ../IkiWiki/Render.pm:400
+#: ../IkiWiki/Render.pm:402
#, perl-format
msgid "scanning %s"
msgstr ""
-#: ../IkiWiki/Render.pm:405
+#: ../IkiWiki/Render.pm:407
#, perl-format
msgid "rendering %s"
msgstr ""
-#: ../IkiWiki/Render.pm:426
+#: ../IkiWiki/Render.pm:428
#, perl-format
msgid "rendering %s, which links to %s"
msgstr ""
-#: ../IkiWiki/Render.pm:447
+#: ../IkiWiki/Render.pm:449
#, perl-format
msgid "rendering %s, which depends on %s"
msgstr ""
-#: ../IkiWiki/Render.pm:486
+#: ../IkiWiki/Render.pm:488
#, perl-format
msgid "rendering %s, to update its backlinks"
msgstr ""
-#: ../IkiWiki/Render.pm:498
+#: ../IkiWiki/Render.pm:500
#, perl-format
msgid "removing %s, no longer rendered by %s"
msgstr ""
-#: ../IkiWiki/Render.pm:522
+#: ../IkiWiki/Render.pm:524
#, perl-format
msgid "ikiwiki: cannot render %s"
msgstr ""
<TMPL_IF NAME="AUTHOR">
<span class="author">
<TMPL_IF NAME="AUTHORURL">
-<a href="<TMPL_VAR NAME=AUTHORURL>"><TMPL_VAR NAME=AUTHOR></a>
+<a href="<TMPL_VAR AUTHORURL>"><TMPL_VAR AUTHOR></a>
<TMPL_ELSE>
-<TMPL_VAR NAME=AUTHOR>
+<TMPL_VAR AUTHOR>
</TMPL_IF>
</span>
</TMPL_IF>
<div class="inlinefooter">
<span class="pagedate">
-Posted <TMPL_VAR CTIME>
+Posted <span class="date" title="<TMPL_VAR CTIME_RAW>"><TMPL_VAR CTIME></span>
</span>
<TMPL_IF NAME="TAGS">
<span class="tags">
Tags:
<TMPL_LOOP NAME="TAGS">
-<TMPL_VAR NAME=LINK>
+<TMPL_VAR LINK>
</TMPL_LOOP>
</span>
</TMPL_IF>
<span>
<span class="parentlinks">
<TMPL_LOOP NAME="PARENTLINKS">
-<a href="<TMPL_VAR NAME=URL>"><TMPL_VAR NAME=PAGE></a>/
+<a href="<TMPL_VAR URL>"><TMPL_VAR PAGE></a>/
</TMPL_LOOP>
</span>
<span class="title">
<div class="tags">
Tags:
<TMPL_LOOP NAME="TAGS">
-<TMPL_VAR NAME=LINK>
+<TMPL_VAR LINK>
</TMPL_LOOP>
</div>
</TMPL_IF>
<div id="backlinks">
Links:
<TMPL_LOOP NAME="BACKLINKS">
-<a href="<TMPL_VAR NAME=URL>"><TMPL_VAR NAME=PAGE></a>
+<a href="<TMPL_VAR URL>"><TMPL_VAR PAGE></a>
</TMPL_LOOP>
<TMPL_IF NAME="MORE_BACKLINKS">
<span class="popup">...
<span class="balloon">
<TMPL_LOOP NAME="MORE_BACKLINKS">
-<a href="<TMPL_VAR NAME=URL>"><TMPL_VAR NAME=PAGE></a>
+<a href="<TMPL_VAR URL>"><TMPL_VAR PAGE></a>
</TMPL_LOOP>
</span>
</span>
</TMPL_IF>
<div class="pagedate">
-Last edited <TMPL_VAR NAME=MTIME>
-<!-- Created <TMPL_VAR NAME=CTIME> -->
+Last edited <span class="date" title="<TMPL_VAR MTIME_RAW>"><TMPL_VAR MTIME></span>
+<!-- Created <TMPL_VAR CTIME> -->
</div>
</div><!-- #pageinfo -->
<TMPL_IF EXTRAFOOTER><TMPL_VAR EXTRAFOOTER></TMPL_IF>
-<!-- from <TMPL_VAR NAME=WIKINAME> -->
+<!-- from <TMPL_VAR WIKINAME> -->
</div><!-- .pagefooter #footer -->
</body>
--- /dev/null
+// Causes html elements in the 'date' and 'pagedate' classes to be displayed
+// as relative dates. The date is parsed from the title attribute, or from
+// the element content.
+
+var dateElements;
+
+hook("onload", getDates);
+
+function getDates() {
+ dateElements = getElementsByClass('date');
+ for (var i = 0; i < dateElements.length; i++) {
+ var elt = dateElements[i];
+ var title = elt.attributes.title;
+ var d = new Date(title ? title.value : elt.innerHTML);
+ if (! isNaN(d)) {
+ dateElements[i].date=d;
+ elt.title=elt.innerHTML;
+ }
+ }
+
+ showDates();
+}
+
+function showDates() {
+ for (var i = 0; i < dateElements.length; i++) {
+ var elt = dateElements[i];
+ var d = elt.date;
+ if (! isNaN(d)) {
+ elt.innerHTML=relativeDate(d);
+ }
+ }
+ setTimeout(showDates,30000); // keep updating every 30s
+}
+
+var timeUnits = new Array;
+timeUnits['minute'] = 60;
+timeUnits['hour'] = timeUnits['minute'] * 60;
+timeUnits['day'] = timeUnits['hour'] * 24;
+timeUnits['month'] = timeUnits['day'] * 30;
+timeUnits['year'] = timeUnits['day'] * 364;
+var timeUnitOrder = ['year', 'month', 'day', 'hour', 'minute'];
+
+function relativeDate(date) {
+ var now = new Date();
+ var offset = date.getTime() - now.getTime();
+ var seconds = Math.round(Math.abs(offset) / 1000);
+
+ var ret = "";
+ var shown = 0;
+ for (i = 0; i < timeUnitOrder.length; i++) {
+ var unit = timeUnitOrder[i];
+ if (seconds >= timeUnits[unit]) {
+ var num = Math.floor(seconds / timeUnits[unit]);
+ seconds -= num * timeUnits[unit];
+ if (ret)
+ ret += "and ";
+ ret += num + " " + unit + (num > 1 ? "s" : "") + " ";
+
+ if (++shown == 2)
+ break;
+ }
+ else if (shown)
+ break;
+ }
+
+ if (! ret)
+ ret = "less than a minute "
+
+ return ret + (offset < 0 ? "ago" : "from now");
+}