The Sphinx-based document project I'm working on integrates Disqus as a 
comment engine. It was pretty easy to do (or seemed to be, anyway). First I 
set up the Disqus account which I won't go into here, short of saying that 
you need to have the "disqus shortname" established, so you need to know 
where you're docs are going to get posted. After doing that, I did these 
two things:

(a) I forked a local version of the theme I wanted to use, and then put 
this macro into the theme's "layout.html" template:

{% macro comments() %}
    <!-- Disqus comments inclusion -->
    <div id="disqus_thread"></div>
    <script type="text/javascript">
    /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * 
* */
    var disqus_shortname = 'my-disqus-shortname-here'; // required: replace 
example with your forum shortname
    {% trans pagename=pagename|e %}var disqus_identifier = '{{ pagename 
}}';{% endtrans %}
    /* * * 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">comments powered by 
<span class="logo-disqus">Disqus</span></a>
{% endmacro %}

(b) Then, I inserted a call to this macro inside the theme's "content" 
block:

        {% block body %}{% endblock %}
        {%- if not internal_build and (pagename != 'index') %}
          <hr/>
          {{ comments() }}
        {%- endif %}

Note that the if condition switches on two things: first off, the pagename 
!= index condition makes sure not to put the comment block on the doc's 
main page, second, the "internal_build" condition gets set on the build 
command line with "-A internal_build=true" when I'm doing internal builds. 
This prevents me jamming the comment stuff onto pages that sit behind our 
firewall where the disqus site can't see them.

You can probably do this by not necessarily using the blunt hammer of 
forking an entire theme... you could probably have just a local 
"comment.html" template or something that inherits from !layout.html, and 
then adds the comment in an appropriate template block (like maybe {% 
footer %}?)

If you do it that way, then you probably want to invoke super() in the 
block first to make sure you get the stuff you inherit from the theme's 
template, and then put in your own commenting stuff.

--
Viktor

-- 
You received this message because you are subscribed to the Google Groups 
"sphinx-dev" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sphinx-dev/-/H4ikboQd8LcJ.
To post to this group, send email to sphinx-dev@googlegroups.com.
To unsubscribe from this group, send email to 
sphinx-dev+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sphinx-dev?hl=en.

Reply via email to