if (! exists $param{type} || ! ref $param{call} || ! exists $param{id}) {
error "hook requires type, call, and id parameters";
}
+
+ return if $param{no_override} && exists $hooks{$param{type}}{$param{id}};
$hooks{$param{type}}{$param{id}}=\%param;
} # }}}
--- /dev/null
+#!/usr/bin/perl
+package IkiWiki::Plugin::shortcut;
+
+use warnings;
+use strict;
+use IkiWiki;
+
+sub import { #{{{
+ hook(type => "checkconfig", id => "shortcut", call => \&checkconfig);
+ hook(type => "preprocess", id => "shortcut", call => \&preprocess_shortcut);
+} #}}}
+
+sub checkconfig () { #{{{
+ # Preprocess the shortcuts page to get all the available shortcuts
+ # defined before other pages are rendered.
+ IkiWiki::preprocess("shortcuts", "shortcuts",
+ readfile(srcfile("shortcuts.mdwn")));
+} # }}}
+
+sub preprocess_shortcut (@) { #{{{
+ my %params=@_;
+
+ if (! defined $params{name} || ! defined $params{url}) {
+ return "[[shortcut missing name or url parameter]]";
+ }
+
+ hook(type => "preprocess", no_override => 1, id => $params{name},
+ call => sub { shortcut_expand($params{name}, $params{url}, @_) });
+
+ return "shortcut $params{name} points to $params{url}";
+} # }}}
+
+sub shortcut_expand ($$@) { #{{{
+ my $name=shift;
+ my $url=shift;
+ my %params=@_;
+
+ # Get params in original order.
+ my @params;
+ while (@_) {
+ my $key=shift;
+ my $value=shift;
+ push @params, $key if ! length $value;
+ }
+
+ # If the shortcuts page changes, all pages that use shortcuts will
+ # need to be updated.
+ add_depends($params{destpage}, "shortcuts");
+
+ my $text=join(" ", @params);
+ my $encoded_text=$text;
+ $encoded_text=~s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
+
+ $url=~s/\%s/$encoded_text/g;
+ return "<a href=\"$url\">$text</a>";
+} #}}}
+
+1
--- /dev/null
+This page is used to control what shortcut links are supported by the wiki.
+
+* [[shortcut name=google url="http://www.google.com/search?q=%s"]]
+* [[shortcut name=wikipedia url="http://en.wikipedia.org/wiki/%s"]]
+* [[shortcut name=debbug url="http://bugs.debian.org/%s"]]
+
+To add a new shortcut, use the "shortcut" preprocessor directive. "%s" in
+the url is replaced by the text of the shortcut.
+ikiwiki (1.30) UNRELEASED; urgency=low
+
+ * Add no_override parameter to hook().
+ * Add a shortcut plugin, inspired by Victor Moral's contributed shortcuts
+ plugin, but featuring a more ikiwiki-ish syntax and with shortcuts that
+ can be configured using a page in wiki.
+
+ -- Joey Hess <joeyh@debian.org> Sun, 15 Oct 2006 14:49:28 -0400
+
ikiwiki (1.29) unstable; urgency=low
* Patch from Paul Tötterman to use CP in the Makefile.
[[template id=plugin name=googlemaps author="Christian Mock"]]
[[tag special-purpose]]
+[[meta title"googlemaps (third-party plugin)"]]
`googlemaps` is a plugin that allows using the [Google Maps API][2]
from ikiwiki.
[[template id=plugin name=img author="Christian Mock"]]
[[tag chrome]]
+[[meta title"img (third-party plugin)"]]
`img` is an enhanced image handling plugin.
[[template id=plugin name=linguas author="Jordà Polo"]]
+[[meta title"linguas (third-party plugin)"]]
Linguas
=======
[[template id=plugin name=shortcuts included=0 author="[[VictorMoral]]"]]
[[tag type/format]]
+[[meta title"shortcuts (third-party plugin)"]]
+
+Note: This plugin is different than the "shortcut" plugin now included in
+ikiwiki. I'm leaving it here in case people prefer how this one works.
+--[[Joey]]
*shortcuts* is a plugin for make external links easy in a ikiwiki page.
It filter the raw source code, searching *wafl expresions* and replacing it
ikiwiki users.
--[[Joey]]
+
+Update: I've added a "shortcut" plugin that works as described above.
+--[[Joey]]
--- /dev/null
+[[template id=plugin name=shortcut included=1 author="[[Joey]]"]]
+[[tag type/format]]
+
+This plugin allows external links to commonly linked to sites to be made
+more easily using shortcuts. Some examples of using shortcuts include:
+
+ \[[google foo]]
+ \[[wikipedia War of 1812]]
+ \[[debbug 12345]]
+
+The available shortcuts are defined on the [[shortcuts]] page in
+the wiki.
Hook into ikiwiki's processing. See the discussion of hooks above.
+Note that in addition to the named parameters described above, a parameter
+named no_override is supported, If it's set to a true value, then this hook
+will not override any existing hook with the same id. This is useful if
+the id can be controled by the user.
+
#### `debug($)`
Logs a debugging message. These are supressed unless verbose mode is turned