Disqus on Ghost

More adventures into self-hosting Ghost. I have Disqus up and running again, all the comments are still there. Since Disqus was based on URL, and the URL didn't change, everything just started working once the Disqus universal code was added. I did run into the same problem as I did with the security.txt file (which is the reason I'm documenting this).

The section of code I need to add this to is post.hbs in /var/www/ghost/versions/1.23.1/content/themes/casper/ (1.23.1 is the version number, and will change). So, like the location for security.txt, this will change every time Ghost is updated.

Another short script, that you can either run on a cron job, every update, etc. fixes this. I reused the same first few lines to enumerate and move into the version directories. Then I test to see if the word "disqus" is in post.hbs, if it is, we've already fixed this file, skip it. If not, backup post.hbs, and then the real magic happens.

sed '/{{content}}/ r /home/ubuntu/disqus_universal.txt' $dir/post.hbs.bak > $dir/post.hbs: Sed finds "{{content}}" in post.hbs.bak and, directly after that, adds the content of the file "disqus_universal.txt", directing the output into post.hbs.

disqus_universal.txt contains, of course, the universal embed code.


for f in /var/www/ghost/versions/*; do
    if [ -d ${f} ]; then
		# echo $f
		# echo $dir
		if grep -q disqus $dir/post.hbs; then
			echo "Disqus already set in $dir"
			echo "Provisioning Disqus in $dir/post.hbs"
            mv $dir/post.hbs $dir/post.hbs.bak
            sed '/{{content}}/ r /home/ubuntu/disqus_universal.txt' $dir/post.hbs.bak > $dir/post.hbs


Infosec analyst, lover of passwords, and owner of a giant goofy puppy.

Read More
Disqus on Ghost
Share this