2 package IkiWiki::Plugin::shortcut;
9 hook(type => "checkconfig", id => "shortcut", call => \&checkconfig);
10 hook(type => "preprocess", id => "shortcut", call => \&preprocess_shortcut);
13 sub checkconfig () { #{{{
14 # Preprocess the shortcuts page to get all the available shortcuts
15 # defined before other pages are rendered.
16 IkiWiki::preprocess("shortcuts", "shortcuts",
17 readfile(srcfile("shortcuts.mdwn")));
20 sub preprocess_shortcut (@) { #{{{
23 if (! defined $params{name} || ! defined $params{url}) {
24 return "[[shortcut missing name or url parameter]]";
27 hook(type => "preprocess", no_override => 1, id => $params{name},
28 call => sub { shortcut_expand($params{name}, $params{url}, @_) });
30 return "shortcut $params{name} points to $params{url}";
33 sub shortcut_expand ($$@) { #{{{
38 # Get params in original order.
43 push @params, $key if ! length $value;
46 # If the shortcuts page changes, all pages that use shortcuts will
48 add_depends($params{destpage}, "shortcuts");
50 my $text=join(" ", @params);
51 my $encoded_text=$text;
52 $encoded_text=~s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
54 $url=~s/\%s/$encoded_text/g;
55 return "<a href=\"$url\">$text</a>";