From 6dda2bfbde2db2b727a5ea96b8b2ce397064684e Mon Sep 17 00:00:00 2001 From: Jesse Gumm Date: Fri, 31 Aug 2012 19:49:37 -0500 Subject: [PATCH] Add disqus comments to doc compiler --- COMPILE_DOCS | 13 +++++++------ Makefile | 1 + doc/add_disqus.pl | 40 ++++++++++++++++++++++++++++++++++++++++ doc/disqus.html | 15 +++++++++++++++ 4 files changed, 63 insertions(+), 6 deletions(-) create mode 100755 doc/add_disqus.pl create mode 100644 doc/disqus.html diff --git a/COMPILE_DOCS b/COMPILE_DOCS index c7b9a3ac..e55187fc 100644 --- a/COMPILE_DOCS +++ b/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 diff --git a/Makefile b/Makefile index f6795dad..46fb9dcc 100755 --- a/Makefile +++ b/Makefile @@ -8,5 +8,6 @@ clean: docs: ./make_docs.el + @(cd doc;perl add_disqus.pl) doc: docs diff --git a/doc/add_disqus.pl b/doc/add_disqus.pl new file mode 100755 index 00000000..1fcca2d9 --- /dev/null +++ b/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//$file/g; + my $contents = &read_file($file); + if($contents =~ /
/) { + print "already done\n"; + }else{ + $contents =~ s!
[\s\n]*!$to_inject!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; +} diff --git a/doc/disqus.html b/doc/disqus.html new file mode 100644 index 00000000..3af237b8 --- /dev/null +++ b/doc/disqus.html @@ -0,0 +1,15 @@ +
+ + +comments powered by Disqus