]> sipb.mit.edu Git - ikiwiki.git/commitdiff
insert flattr javascript via sanitize, not format hook
authorJoey Hess <joey@kitenet.net>
Thu, 12 Aug 2010 21:19:20 +0000 (17:19 -0400)
committerJoey Hess <joey@kitenet.net>
Thu, 12 Aug 2010 21:19:20 +0000 (17:19 -0400)
This makes the javascript be added to rss feeds, which allows the buttons
to be displayed by aggregators. At least, if the aggregator does not
sanitize javascript.

IkiWiki/Plugin/flattr.pm

index 3aee1eb93320eb1f0631eb58b39b50137c7f17bc..9cf9dfb138ae74a3333ae102f3ffba44ab4a3952 100644 (file)
@@ -8,7 +8,7 @@ use IkiWiki 3.00;
 sub import {
        hook(type => "getsetup", id => "flattr", call => \&getsetup);
        hook(type => "preprocess", id => "flattr", call => \&preprocess);
-       hook(type => "format", id => "flattr", call => \&format);
+       hook(type => "sanitize", id => "flattr", call => \&sanitize, last => 1);
 }
 
 sub getsetup () {
@@ -54,17 +54,16 @@ sub preprocess (@) {
                '</a>';
 }
 
-sub format (@) {
+sub sanitize (@) {
        my %params=@_;
 
        # Add flattr's javascript to pages with flattr buttons.
        if ($flattr_pages{$params{page}}) {
-               if (! ($params{content}=~s!^(<body[^>]*>)!$1.flattrjs()!em)) {
-                       # no <body> tag, probably in preview mode
-                       $params{content}=flattrjs().$params{content};
-               }
+               return flattrjs().$params{content};
+       }
+       else {
+               return $params{content};
        }
-       return $params{content};
 }
 
 my $js_cached;