Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #21 from mdda/master

Added a Disqus module
  • Loading branch information...
commit 12e310592b14ffeafeac6aac973942947638c303 2 parents 80ca142 + 8bf4982
@mitsuhiko authored
View
2  rstblog/builder.py
@@ -177,7 +177,7 @@ class BuildError(ValueError):
class Builder(object):
- default_ignores = ('.*', '_*', 'config.yml', 'Makefile', 'README')
+ default_ignores = ('.*', '_*', 'config.yml', 'Makefile', 'README', '*.conf', )
default_programs = {
'*.rst': 'rst'
}
View
52 rstblog/modules/disqus.py
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+"""
+ rstblog.modules.disqus
+ ~~~~~~~~~~~~~~~~~~~~~~
+
+ Implements disqus element if asked for.
+
+ To use this, include ``disqus`` in the list of modules in your ``config.yml`` file,
+ and add a configuration variable to match your settings : ``disqus.shortname``
+
+ To set developer mode on the site, set ``disqus.developer=1`` in your ``config.yml`` file.
+
+ To prevent comments on a particular page, set ``disqus = no`` in the page's YAML preamble.
+
+ :copyright: (c) 2012 by Martin Andrews.
+ :license: BSD, see LICENSE for more details.
+"""
+import jinja2
+
+@jinja2.contextfunction
+def get_disqus(context):
+ var_shortname=context['builder'].config.root_get('modules.disqus.shortname', 'YOUR-DISQUS-SHORTNAME')
+
+ var_developer=''
+ if context['builder'].config.root_get('modules.disqus.developer', False):
+ var_developer='var disqus_developer = 1;'
+
+ disqus_txt="""
+<div id="disqus_thread"></div>
+<script type="text/javascript">
+ var disqus_shortname = '%s'; // required: replace example with your forum shortname
+ %s
+
+ /* * * DON'T EDIT BELOW THIS LINE * * */
+ (function() {
+ var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
+ dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
+ (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
+ })();
+</script>
+<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
+<a href="http://disqus.com" class="dsq-brlink">blog comments powered by <span class="logo-disqus">Disqus</span></a>
+""" % ( var_shortname, var_developer, )
+
+ if not context['config'].get('disqus', True):
+ disqus_txt='' # "<h1>DISQUS DEFEATED</h1>"
+
+ return jinja2.Markup(disqus_txt.encode('utf-8'))
+
+
+def setup(builder):
+ builder.jinja_env.globals['get_disqus'] = get_disqus
View
4 rstblog/templates/rst_display.html
@@ -18,4 +18,8 @@
<a href="{{ link_to('tag', tag=tag) }}">{{ tag }}</a>
{%- endfor %}
{% endif %}
+
+ {% if 'disqus' in config.active_modules %}
+ {{ get_disqus() }}
+ {% endif %}
{% endblock %}
Please sign in to comment.
Something went wrong with that request. Please try again.