]> sipb.mit.edu Git - ikiwiki.git/commitdiff
meta plugin: script support
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Tue, 25 Jan 2011 09:28:52 +0000 (10:28 +0100)
committerJoey Hess <joey@kitenet.net>
Mon, 28 Mar 2011 17:08:20 +0000 (13:08 -0400)
(cherry picked from commit 44c5b27f88fdbfb4fdd061f600039e490eaeff92)

IkiWiki/Plugin/meta.pm
doc/ikiwiki/directive/meta.mdwn

index 1a9f94a124d766687da1daeac391cf8b479a4cec..eebe3460f07a42ab2841aadcb08190fe02ae566f 100644 (file)
@@ -179,6 +179,17 @@ sub preprocess (@) {
                        '" title="'.encode_entities($title).
                        "\" type=\"text/css\" />", $page, $destpage);
        }
+       elsif ($key eq 'script') {
+               my $defer=exists $params{defer} ? ' defer="defer"' : '';
+               my $async=exists $params{async} ? ' async="async"' : '';
+               my $js=bestlink($page, $value.".js");
+               if (! length $js) {
+                       error gettext("script not found");
+               }
+               push @{$metaheaders{$page}}, scrub('<script src="'.urlto($js, $page).
+                       '"' . $defer . $async . ' type="text/javascript" />',
+                       $page, $destpage);
+       }
        elsif ($key eq 'openid') {
                my $delegate=0; # both by default
                if (exists $params{delegate}) {
index 50aaf66be46244148c7cf6c29e4b9c7e9005c3aa..9c2147264d75b35ddc4381179c369261d782214b 100644 (file)
@@ -82,6 +82,17 @@ Supported fields:
   [[!iki plugins/htmlscrubber desc=htmlscrubber]] plugin is enabled,
   since it can be used to insert unsafe content.
 
+* script
+
+  Adds a script to a page. The script is treated as a wiki link to
+  a `.js` file in the wiki, so it cannot be used to add links to external
+  scripts. The optional `defer` and `async` keywords can be used to set
+  the corresponding HTML4 and HTML5 script options. Example:
+
+       \[[!meta script=somescript defer async]]
+
+  The tag is subject to scrubbing as with the stylesheet and link fields.
+
 * openid
 
   Adds html &lt;link&gt; tags to perform OpenID delegation to an external