#598415 Duplicated <script/> element for ikiwiki.js

#598415#5
Date:
2010-09-28 20:39:58 UTC
From:
To:
Hi,

If both relativedate and toggle plugins are enabled and features of both
plugins are used on a wiki page, a <script> tag for ikiwiki.js is rendered
twice in the generated HTML for the page.

Looks like both plugins inject the <script> tags directly to the HTML using
format() hook. Of course they know nothing if another plugin has already
re-wrote the HTML document with the same content they are about to write, thus
a duplicate <script> tag is added to the HTML document.

I guess more elegant solution would be if IkiWiki provided a framework for this
kind of stuff. Plugins would be able to register external resources they
require (i.e. JavaScript files and style sheets). IkiWiki would guarantee that
each named resource identified by type of the resource (JS or CSS) and file
name would get rendered inside the <head> tag only once using the correct tag
for the resource type (<script/> for JS and <link/> for CSS). Besides Perl
code that handles page rendering, this would probably require some changes to
the default templates and that might break some custom templates, though.

Disclaimer: Personally, I'd love this kind of feature for other reasons also. I
want to include some 3rd party JavaScript code on all the pages in my IkiWiki
installation. I don't want to create and maintain a fork of the upstream page
template just to insert a couple of <script> tags in <head>. Currently I solve
this dilemma by utilizing an ugly hack involving dynamic JavaScript loading
inside a <script> tag embedded in sidebar.mdwn. I'd prefer writing an IkiWiki
plugin that could tell IkiWiki to include proper <script> tags for my
JavaScript files in the <head> of the default IkiWiki templates using method
described earlier. I don't want to write a plugin that does ugly format()
things like relativedate and toggle currently do, either ;)

Regards,
Tuomas Jormola