blackhole://nilFM

comments

Introducing comments, an unimaginatively named plugin for static site generators, using the power of the Django framework and iframes to add some interactivity and community to an otherwise static site.

The premise is simple: add dynamic content to a static site using iframes. iframes are "webpages within webpages," which allows you to add dynamic content to a static site simply by specifying the URL of the dynamic content. By providing the comment system as a Django app and using a helper script to initialize thread pages within the Django app from the static site generator, we can acheieve the best of both worlds: the speed, security, and reliability of a static site, and the instant response and dynamic storage of the Django app.

In practice, I would have the Django server hosting the comment system at /app/comments/ on this server, and when I enable comments on a post in my static site generator, it would run a script that generates a new thread in the Django app. Then, with comments enabled, the static site generator uses the timestamp marker of the blog post as the primary key of the comment thread and embeds an iframe at the bottom of the post pointing to /app/comments/somekey/.

The comment thread itself is a simple singly-linked-list, with its primary key and a pointer to the first comment in the thread. Each comment has, in addition to its clerical data (author, date/time, email, and content), a flag for hiding the comment (soft delete is nice for linked lists), and a pointer to the next comment in the thread. When the browser requests the comment thread from the django server, it goes through the list for the thread, building an array of comments from the visible ones in the thread, and then when it reaches the end of the list, it builds the page, with the new comment form at the bottom.

Modifing the threads and hiding/deleting the comments is easy with the builtin Django admin interface. You can choose a thread and follow the comments using the Change directive on the pointer fields to open a record for the next element, and either delete it for real and re-link the list manually or just mark it hidden and not have to do any cleanup.

In conclusion, this system makes it easy to tweak any static site generator into a more full-featured platform and less of a walled garden, with minimal resources on server and client, and straightforward management. The code is simple enough that more features can be added without much trouble if you wanted anything fancier.