| 1 | package IkiWiki::Plugin::disqus; | ||
| 2 | use warnings; | ||
| 3 | use strict; | ||
| 4 | |||
| 5 | use IkiWiki 3.00; | ||
| 6 | |||
| 7 | our $VERSION = '0.01'; | ||
| 8 | |||
| 9 | sub import { | ||
| 10 | # template hook | ||
| 11 | hook( type => 'pagetemplate', id => 'disqus', call => \&disqus_comments ); | ||
| 12 | } | ||
| 13 | |||
| 14 | # Template params: | ||
| 15 | # DISQUS_COMMENTS : full discus comments | ||
| 16 | # DISQUS_COUNT : count link | ||
| 17 | sub disqus_comments { | ||
| 18 | my %args = @_; | ||
| 19 | |||
| 20 | $args{template}->param('DISQUS' => 1); | ||
| 21 | |||
| 22 | # Only place the disqus code on the blog page itself. This means | ||
| 23 | # that the disqus code will not appear when a post is embedded in | ||
| 24 | # the index or tag pages. | ||
| 25 | if ($args{page} eq $args{destpage}) { | ||
| 26 | my $shortname = $config{'disqus_shortname'}; | ||
| 27 | my $identifier = $args{destpage}; | ||
| 28 | my $url = urlto($args{destpage}, 'index', '1'); | ||
| 29 | |||
| 30 | foreach my $pattern (@{ $config{disqus_skip_patterns } }) { | ||
| 31 | if ($identifier =~ $pattern) { | ||
| 32 | return ''; | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | my $jscript =<<DISQUSCOMMENTS; | ||
| 37 | <div id="disqus_thread"></div> | ||
| 38 | <script type="text/javascript"> | ||
| 39 | var disqus_shortname = '$shortname'; // required: replace example with your forum shortname | ||
| 40 | var discus_identifier = '$identifier'; | ||
| 41 | var disqus_url = '$url'; | ||
| 42 | |||
| 43 | (function() { | ||
| 44 | var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; | ||
| 45 | dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; | ||
| 46 | (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); | ||
| 47 | })(); | ||
| 48 | </script> | ||
| 49 | <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> | ||
| 50 | <a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a> | ||
| 51 | DISQUSCOMMENTS | ||
| 52 | |||
| 53 | $args{template}->param('DISQUS_COMMENTS' => $jscript) | ||
| 54 | } | ||
| 55 | else { | ||
| 56 | # this is not the page but an embedded page. | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | 1; | ||
| 61 | |||
| 62 | __END__ |