From 956ad2aedc3a33ccb35750a49ed23534a3857a93 Mon Sep 17 00:00:00 2001 From: Marcin Wielgoszewski Date: Mon, 14 Jan 2013 00:28:21 -0500 Subject: [PATCH] improvements to disqus functions * add option to embed count.js for easy adding of comment counts to posts * per post configuration / override --- rstblog/modules/disqus.py | 53 ++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 9 deletions(-) diff --git a/rstblog/modules/disqus.py b/rstblog/modules/disqus.py index cd6ee67..6636829 100644 --- a/rstblog/modules/disqus.py +++ b/rstblog/modules/disqus.py @@ -19,13 +19,22 @@ @jinja2.contextfunction def get_disqus(context): - var_shortname=context['builder'].config.root_get('modules.disqus.shortname', 'YOUR-DISQUS-SHORTNAME') + var_shortname = context['builder'].config.root_get('modules.disqus.shortname', 'YOUR-DISQUS-SHORTNAME') + + vars = [] + + if context['config'].get('disqus_id', context['config'].get('post_id', None)): + vars.append("var disqus_identifier = '%s';" % ( + context['config'].get('disqus_id', # fall back to post_id if None + context['config'].get('post_id', None)), )) + + if context['config'].get('disqus_url', None): + vars.append("var disqus_url = '%s';" % (context['config'].get('disqus_url'), )) - var_developer='' if context['builder'].config.root_get('modules.disqus.developer', False): - var_developer='var disqus_developer = 1;' - - disqus_txt=""" + vars.append("var disqus_developer = 1;") + + disqus_txt = """
blog comments powered by Disqus -""" % ( var_shortname, var_developer, ) +""" % (var_shortname, '\n '.join(vars), ) if not context['config'].get('disqus', True): - disqus_txt='' # "

DISQUS DEFEATED

" - + disqus_txt = '' + + return jinja2.Markup(disqus_txt.encode('utf-8')) + + +@jinja2.contextfunction +def get_disqus_count(context): + var_shortname = context['builder'].config.root_get('modules.disqus.shortname', 'YOUR-DISQUS-SHORTNAME') + disqus_txt = """ + + +blog comments powered by Disqus +""" % (var_shortname, ) + + if not context['config'].get('disqus', True): + disqus_txt = '' + return jinja2.Markup(disqus_txt.encode('utf-8')) def setup(builder): builder.jinja_env.globals['get_disqus'] = get_disqus + builder.jinja_env.globals['get_disqus_count'] = get_disqus_count +