From f36080ae026d630c180e4a73709d09ca779a0c2e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 16 Oct 2008 18:20:16 -0400 Subject: aggregate: Avoid bug that caused immediate expiration of items with a date in the future. --- IkiWiki/Plugin/aggregate.pm | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/aggregate.pm b/IkiWiki/Plugin/aggregate.pm index 26c5cc9ae..c18784e8b 100644 --- a/IkiWiki/Plugin/aggregate.pm +++ b/IkiWiki/Plugin/aggregate.pm @@ -625,6 +625,10 @@ sub add_page (@) { #{{{ # Store it in pagectime for expiry code to use also. $IkiWiki::pagectime{$guid->{page}}=$mtime; } + else { + # Dummy value for expiry code. + $IkiWiki::pagectime{$guid->{page}}=time; + } } #}}} sub htmlescape ($) { #{{{ -- cgit v1.2.3 From 79b376f9912891a8748fcbb4580969e4dbf7fc75 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 17 Oct 2008 20:28:18 -0400 Subject: Add an underlay for javascript, and add ikiwiki.js containing some utility code. * Add an underlay for javascript, and add ikiwiki.js containing some utility code. * toggle: Stop embedding the full toggle code on each page using it, and move it to toggle.js in the javascript underlay. --- IkiWiki/Plugin/attachment.pm | 7 +++-- IkiWiki/Plugin/toggle.pm | 69 ++++++++--------------------------------- debian/changelog | 9 ++++++ doc/plugins/write.mdwn | 29 +++++++++++++++++ po/ikiwiki.pot | 16 +++++----- underlays/javascript/ikiwiki.js | 37 ++++++++++++++++++++++ underlays/javascript/toggle.js | 29 +++++++++++++++++ 7 files changed, 129 insertions(+), 67 deletions(-) create mode 100644 underlays/javascript/ikiwiki.js create mode 100644 underlays/javascript/toggle.js (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/attachment.pm b/IkiWiki/Plugin/attachment.pm index dcac3e820..6c1df488a 100644 --- a/IkiWiki/Plugin/attachment.pm +++ b/IkiWiki/Plugin/attachment.pm @@ -6,6 +6,7 @@ use strict; use IkiWiki 2.00; sub import { #{{{ + add_underlay("javascript"); hook(type => "getsetup", id => "attachment", call => \&getsetup); hook(type => "checkconfig", id => "attachment", call => \&checkconfig); hook(type => "formbuilder_setup", id => "attachment", call => \&formbuilder_setup); @@ -104,10 +105,10 @@ sub formbuilder_setup (@) { #{{{ $form->tmpl_param("field-upload" => ''); $form->tmpl_param("field-link" => ''); - # Add the javascript from the toggle plugin; - # the attachments interface uses it to toggle visibility. + # Add the toggle javascript; the attachments interface uses + # it to toggle visibility. require IkiWiki::Plugin::toggle; - $form->tmpl_param("javascript" => $IkiWiki::Plugin::toggle::javascript); + $form->tmpl_param("javascript" => IkiWiki::Plugin::toggle::include_javascript($params{page}, 1)); # Start with the attachments interface toggled invisible, # but if it was used, keep it open. if ($form->submitted ne "Upload Attachment" && diff --git a/IkiWiki/Plugin/toggle.pm b/IkiWiki/Plugin/toggle.pm index 610d38e3a..657d8d3c2 100644 --- a/IkiWiki/Plugin/toggle.pm +++ b/IkiWiki/Plugin/toggle.pm @@ -5,61 +5,8 @@ use warnings; use strict; use IkiWiki 2.00; -# Here's the javascript that makes this possible. A key feature is the use -# of css to hide toggleables, to avoid any flashing on page load. The css -# is only emitted after the javascript tests that it's going to be able to -# show the toggleables. -our $javascript=<<'EOF'; - -EOF - sub import { #{{{ + add_underlay("javascript"); hook(type => "getsetup", id => "toggle", call => \&getsetup); hook(type => "preprocess", id => "toggle", call => \&preprocess_toggle); @@ -121,12 +68,22 @@ sub format (@) { #{{{ if ($params{content}=~s!(
\s*)
!$1!g) { $params{content}=~s/
//g; - if (! ($params{content}=~s!^!$javascript!m)) { + if (! ($params{content}=~s!^()!$1.include_javascript($params{page})!em)) { # no tag, probably in preview mode - $params{content}=$javascript.$params{content}; + $params{content}=include_javascript($params{page}, 1).$params{content}; } } return $params{content}; } # }}} +sub include_javascript ($;$) { #{{{ + my $page=shift; + my $absolute=shift; + + return ''."\n". + ''; +} #}}} + 1 diff --git a/debian/changelog b/debian/changelog index b93da0aae..66d108e9e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +ikiwiki (2.68) UNRELEASED; urgency=low + + * Add an underlay for javascript, and add ikiwiki.js containing some utility + code. + * toggle: Stop embedding the full toggle code on each page using it, and + move it to toggle.js in the javascript underlay. + + -- Joey Hess Fri, 17 Oct 2008 20:11:02 -0400 + ikiwiki (2.67) unstable; urgency=low * remove: Avoid $_ breakage. (Stupid, stupid perl.) diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn index 1b78f5900..daf70c8e2 100644 --- a/doc/plugins/write.mdwn +++ b/doc/plugins/write.mdwn @@ -847,3 +847,32 @@ to a hash containing all the config items. They should also implement a By the way, to parse a ikiwiki setup file and populate `%config`, a program just needs to do something like: `use IkiWiki::Setup; IkiWiki::Setup::load($filename)` + +### Javascript + +Some plugins use javascript to make ikiwiki look a bit more web-2.0-ish. + +All javascript code should be put in `.js` files in the `javascript` +underlay, and plugins using those files can enable use of the underlay by +calling `add_underlay("javascript");` in their `import` function. + +You'll have to arrange for `'."\n". + ''; +} #}}} + +1 diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm index bc997ffb0..8385c1aff 100644 --- a/IkiWiki/Render.pm +++ b/IkiWiki/Render.pm @@ -109,7 +109,9 @@ sub genpage ($$) { #{{{ 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), ); diff --git a/debian/changelog b/debian/changelog index 66d108e9e..908eb1f53 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,6 +4,8 @@ ikiwiki (2.68) UNRELEASED; urgency=low 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 Fri, 17 Oct 2008 20:11:02 -0400 diff --git a/doc/plugins/ddate.mdwn b/doc/plugins/ddate.mdwn index e82760d88..741606a6e 100644 --- a/doc/plugins/ddate.mdwn +++ b/doc/plugins/ddate.mdwn @@ -1,5 +1,6 @@ [[!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)`. diff --git a/doc/plugins/prettydate.mdwn b/doc/plugins/prettydate.mdwn index 9a67f5dca..11ad4252f 100644 --- a/doc/plugins/prettydate.mdwn +++ b/doc/plugins/prettydate.mdwn @@ -1,5 +1,5 @@ [[!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, diff --git a/doc/plugins/relativedate.mdwn b/doc/plugins/relativedate.mdwn new file mode 100644 index 000000000..ecbdf68bf --- /dev/null +++ b/doc/plugins/relativedate.mdwn @@ -0,0 +1,16 @@ +[[!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: + + Fri Oct 17 18:36:13 EDT 2008 diff --git a/doc/plugins/type/date.mdwn b/doc/plugins/type/date.mdwn new file mode 100644 index 000000000..eae1226da --- /dev/null +++ b/doc/plugins/type/date.mdwn @@ -0,0 +1 @@ +These plugins control how ikiwiki displays dates. diff --git a/po/ikiwiki.pot b/po/ikiwiki.pot index 6853df153..2d213a799 100644 --- a/po/ikiwiki.pot +++ b/po/ikiwiki.pot @@ -8,7 +8,7 @@ msgid "" 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 \n" "Language-Team: LANGUAGE \n" @@ -172,9 +172,9 @@ msgid "automatic index generation" 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 "" @@ -318,11 +318,11 @@ 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 "" @@ -780,59 +780,59 @@ msgstr "" msgid "

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 "" diff --git a/templates/inlinepage.tmpl b/templates/inlinepage.tmpl index ffcb897a8..3f640fcdd 100644 --- a/templates/inlinepage.tmpl +++ b/templates/inlinepage.tmpl @@ -5,9 +5,9 @@ - + - + @@ -28,14 +28,14 @@

-Posted +Posted Tags: - + diff --git a/templates/page.tmpl b/templates/page.tmpl index f2f9c34cc..7456e9e41 100644 --- a/templates/page.tmpl +++ b/templates/page.tmpl @@ -22,7 +22,7 @@ -/ +/ @@ -74,7 +74,7 @@
Tags: - +
@@ -83,13 +83,13 @@ Tags: - +
diff --git a/underlays/javascript/relativedate.js b/underlays/javascript/relativedate.js new file mode 100644 index 000000000..c5e62b3cc --- /dev/null +++ b/underlays/javascript/relativedate.js @@ -0,0 +1,70 @@ +// 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"); +} -- cgit v1.2.3 From 02ec92c6cb0cfb86fb9a0b65addbd8c0934869c7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 17 Oct 2008 21:21:07 -0400 Subject: make relativedate work for the dates on the recentchanges page Having a always current relative date on recentchanges is very, very nice. --- IkiWiki/Plugin/recentchanges.pm | 1 + templates/change.tmpl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/recentchanges.pm b/IkiWiki/Plugin/recentchanges.pm index eb23b184b..d25c7abff 100644 --- a/IkiWiki/Plugin/recentchanges.pm +++ b/IkiWiki/Plugin/recentchanges.pm @@ -173,6 +173,7 @@ sub store ($$$) { #{{{ $template->param( %$change, commitdate => displaytime($change->{when}, "%X %x"), + commitdate_raw => scalar localtime($change->{when}), wikiname => $config{wikiname}, ); IkiWiki::run_hooks(pagetemplate => sub { diff --git a/templates/change.tmpl b/templates/change.tmpl index 4a99cf5ff..3a1086cf0 100644 --- a/templates/change.tmpl +++ b/templates/change.tmpl @@ -24,7 +24,7 @@
Commit type:

Date:
- +
-- cgit v1.2.3 From 745dc1c62f46bacda60d01283145b5baa0adfea1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 17 Oct 2008 21:29:05 -0400 Subject: add missing getsetup hook --- IkiWiki/Plugin/relativedate.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/relativedate.pm b/IkiWiki/Plugin/relativedate.pm index 99265676b..2895f6d57 100644 --- a/IkiWiki/Plugin/relativedate.pm +++ b/IkiWiki/Plugin/relativedate.pm @@ -7,6 +7,7 @@ use IkiWiki 2.00; sub import { #{{{ add_underlay("javascript"); + hook(type => "getsetup", id => "relativedate", call => \&getsetup); hook(type => "format", id => "relativedate", call => \&format); } # }}} -- cgit v1.2.3 From fdb5da46b0122d9cb4b2611526c6c955478a80cf Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 17 Oct 2008 21:49:55 -0400 Subject: Patch for anchor-based change permalinks in recent changes feed from JasonBlevins --- IkiWiki/Plugin/recentchanges.pm | 3 +++ templates/change.tmpl | 2 ++ 2 files changed, 5 insertions(+) (limited to 'IkiWiki/Plugin') diff --git a/IkiWiki/Plugin/recentchanges.pm b/IkiWiki/Plugin/recentchanges.pm index d25c7abff..d0e4176ff 100644 --- a/IkiWiki/Plugin/recentchanges.pm +++ b/IkiWiki/Plugin/recentchanges.pm @@ -115,6 +115,8 @@ sub store ($$$) { #{{{ my $change=shift; my $page="$config{recentchangespage}/change_".titlepage($change->{rev}); + my $baseurl = IkiWiki::baseurl(); + my $permalink="$baseurl$config{recentchangespage}/#change-".titlepage($change->{rev}); # Optimisation to avoid re-writing pages. Assumes commits never # change (or that any changes are not important). @@ -175,6 +177,7 @@ sub store ($$$) { #{{{ commitdate => displaytime($change->{when}, "%X %x"), commitdate_raw => scalar localtime($change->{when}), wikiname => $config{wikiname}, + permalink => $permalink, ); IkiWiki::run_hooks(pagetemplate => sub { shift->(page => $page, destpage => $page, diff --git a/templates/change.tmpl b/templates/change.tmpl index 3a1086cf0..6647dfbca 100644 --- a/templates/change.tmpl +++ b/templates/change.tmpl @@ -3,6 +3,8 @@ [[!meta authorurl=""""""]] [[!meta title="""change to on """]] +[[!meta permalink=""]] +