Skip to content
Browse files

Add disqus comments to doc compiler

  • Loading branch information...
1 parent 5a00403 commit 6dda2bfbde2db2b727a5ea96b8b2ce397064684e @choptastic choptastic committed
Showing with 63 additions and 6 deletions.
  1. +7 −6 COMPILE_DOCS
  2. +1 −0 Makefile
  3. +40 −0 doc/add_disqus.pl
  4. +15 −0 doc/disqus.html
View
13 COMPILE_DOCS
@@ -1,19 +1,20 @@
COMPILING THE NITROGEN DOCUMENTATION
-Compiling the documentation uses Org-mode for Emacs.
+compiling the documentation uses Org-mode for Emacs and a simple Perl script for adding Disqus comments.
-Editing the HTML is not recommended, as the org-mode compiler just overwrites all HTML anyway.
+Editing the HTML is not recommended, as the org-mode compiler just overwrites all HTML anyway. Instead, edit the org-mode files found in doc/org-mode.
-Instead, edit the org-mode files found in doc/org-mode.
-
-Make sure you have emacs installed, with the htmlize[1] (version 1.34 or later), erlang-mode, and org-mode installed.
+Make sure you have emacs installed, with htmlize (version 1.34 or later), erlang-mode, and org-mode installed.
On Ubuntu, these packages can all be installed with:
sudo apt-get install emacs erlang-mode org-mode emacs-goodies-el
-Once this is done, you can compile the docs from the command line with:
+Then you can compile the docs from the command line with
$ make docs
+
+
+Also worth noting is that the Disqus comment injection script expects perl to be in the PATH
View
1 Makefile
@@ -8,5 +8,6 @@ clean:
docs:
./make_docs.el
+ @(cd doc;perl add_disqus.pl)
doc: docs
View
40 doc/add_disqus.pl
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+
+use strict;
+
+
+my $raw_inject = &read_file("disqus.html");
+my @files = `find html/* | grep \\.html\$`;
+
+for my $file (@files) {
+ chomp($file);
+ print "Injecting Disqus code into $file...";
+ my $to_inject = $raw_inject;
+ $to_inject =~ s/<page-identifier>/$file/g;
+ my $contents = &read_file($file);
+ if($contents =~ /<div id="disqus_thread">/) {
+ print "already done\n";
+ }else{
+ $contents =~ s!</div>[\s\n]*</body>!</div>$to_inject</body>!g;
+ &write_file($file,$contents);
+ print "done\n";
+ }
+}
+
+sub write_file
+{
+ my ($filename,$contents) = @_;
+ open my $fh, ">$filename" or die "error opening $filename: $!";
+ print $fh $contents;
+ close $fh;
+}
+
+
+sub read_file
+{
+ my ($filename) = @_;
+ open my $fh, "<$filename" or die "error opening $filename: $!";
+ my $contents = do { local $/; <$fh> };
+ close $fh;
+ return $contents;
+}
View
15 doc/disqus.html
@@ -0,0 +1,15 @@
+<div id="disqus_thread"></div>
+<script type="text/javascript">
+ /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
+ var disqus_shortname = 'nitrogenproject'; // required: replace example with your forum shortname
+ var disqus_identifier = '<page-identifier>'; //This will be replaced with the path part of the url
+
+ /* * * 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>

0 comments on commit 6dda2bf

Please sign in to comment.
Something went wrong with that request. Please try again.