Add threaded discussions to cgit with disqus

While it provides an efficient, organized web front-end for your personal git repositories, the cgit application is missing a few of the more sparkling features found at github–notably, a comments/discussion system. Enter: disqus.

Disqus is a Javascript-injected, centralized discussion system that is gaining traction with blogs and other CMS-based sites as of late. One of its chief benefits is the centralization; one account links you to all of the discussions you have participated in within various venues. Another benefit of the system is that it is entirely client-side. What this means for cgit integration is that we won’t need to go mucking about in the cgit source code–we can simply use one of its inherent features, the inclusion of a header HTML file, to tie disqus to it.

First, build an HTML file to fire off a document URL comparison that decides whether or not the current page warrants the injection of the disqus platform (be sure to replace REPLACE-WITH-YOUR-DISQUS-SHORTNAME in the code below):

<script type="text/javascript">
window.onload = function() {
	if((window.location.href.match(/\/tree\/.*[?&]id=/)
		&& document.querySelector('table.blob'))
		|| window.location.href.match(/\/commit\/.*[?&]id=(?!.+&ss=1$)/))
	{
		var d = document.createElement('div');
		d.id = 'disqus_thread';
		document.querySelector('div.content').appendChild(d);
		var disqus_shortname = 'REPLACE-WITH-YOUR-DISQUS-SHORTNAME';
		var dsq = document.createElement('script');
		dsq.type = 'text/javascript';
		dsq.async = true;
		dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
		document.body.appendChild(dsq);
	}
};
</script>

The code above will only inject the disqus platform on version-specific commit summaries and individual file views. (Without the version specificity, there would be no “hard” context to tie the discussion thread to.) It also prevents the platform from being injected on side-by-side diffs, since this would lead to two different contexts for discussions about the same file version/commit.

To include this newly-fashioned header in your cgit system, add the following line to your cgitrc file (with the appropriate path, of course):

header=/path/to/your.html

That’s it! The next time you visit a version-specific commit or file in your cgit system, the disqus comment thread should be injected at the bottom of the page.

Caveat: Currently, disqus has problems serving its script over HTTPS. If you’re serving cgit over HTTPS (and I am), you will unfortunately be plagued by content security mismatches. They claim that they have already fixed disqus to work over HTTPS, but I have experienced the opposite.

Posts to resume shortly

I’ve migrated the blog back over to my VPS, as my hosting provider has been trying to blame me for the poor performance of my scripts on their hosting platform. I’ve got everything running on my VPS machine now (and I do mean everything) thanks to nginx, php5-fpm, and 752MB of RAM (of which I am only using 49% on average).

I’ve got some posts in the hopper that I will be releasing soon that deal with easy SSL redirection for nginx, adding a discussion system to the cgit git web interface, and a method for forking PHP processes on servers where the pcntl functions are unavailable.

What’s My Status v1.2 released

My WordPress microblog feed widget recently went through another update. This time around, I’ve added the ability to filter out replies and re-posts (“retweets” in Twitter lingo, “redents” in identi.ca speak) from your activity feed. Pick up the new version from the WordPress plugins site.

What’s My Status? v1.1 released

My microblogging feed widget for WordPress, What’s My Status?, has been updated. The plugin now uses curl for its main retrieval mechanism, with standard URL fopen as the fallback. Additionally, the Reset cache command has been fixed. You can grab the plugin for yourself over at the wordpress.org site.

bulkRename v2.0 released

I’ve converted my bulk file renaming utility from VB.NET to C# and made use of a command line arguments parsing library so that it will accept folders and regex patterns with spaces in them. It behaves a bit weird if you don’t encapsulate your arguments in quotation marks (“) or if you forgo the use of an equals sign (=) between the parameter flag and its argument, but those are small concessions to make.

You can download v2.0 to use yourself. Read More →

Page 1 of 1112345...10...Last »