Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to Disqus module #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 44 additions & 9 deletions rstblog/modules/disqus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = '%s'; // required: replace example with your forum shortname
Expand All @@ -34,19 +43,45 @@ def get_disqus(context):
/* * * 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';
dsq.src = ('https:' == document.location.protocol ? 'https://' : '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, )
""" % (var_shortname, '\n '.join(vars), )

if not context['config'].get('disqus', True):
disqus_txt='' # "<h1>DISQUS DEFEATED</h1>"

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 = """
<script type="text/javascript">
var disqus_shortname = '%s'; // required: replace example with your forum shortname

/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var cnt = document.createElement('script'); cnt.type = 'text/javascript'; cnt.async = true;
cnt.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + disqus_shortname + '.disqus.com/count.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(cnt);
})();
</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, )

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