• Stars
    star
    195
  • Rank 199,374 (Top 4 %)
  • Language
    PHP
  • License
    GNU General Publi...
  • Created over 13 years ago
  • Updated almost 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A plugin for Jekyll to implement a static-file based comments system

Jekyll::StaticComments

Whilst most people go for a Disqus account, or some similar JS-abusing means of putting comments on their blog, I'm old-fashioned, and like my site to be dead-tree useable. Hence this plugin: it provides a means of associating comments with posts and rendering them all as one big, awesome page.

Quick Start (or "what are all these files for?")

  1. Put the static_comments.rb file in the _plugins directory of your Jekyll site.

  2. Edit the variables at the top of commentsubmit.php, and then place it somewhere suitable in your site.

  3. Modify comment_received.html to your liking (add a YAML front-matter to render it in your site's style, for instance) and then place it alongside commentsubmit.php.

  4. Using comment_template.html as a base, add the appropriate code to your blog post template. Remember to provide an appropriate URL to commentsubmit.php.

  5. Create a _comments directory somewhere in your Jekyll site, and populate it with YAML comments (as produced by commentsubmit.php, or otherwise).

  6. Enjoy a wonderful, spam-free, static-commenting Nirvana.

Technical details

To use StaticComments, you need to have a store of comments; this is a directory, called _comments, which contains all your comments. You can have an arbitrary hierarchy inside this _comments directory (so you can put comments in post-specific directories, if you like), and the _comments directory can be anywhere in your site tree (I put it alongside my _posts directory). The files containing comments can be named anything you like -- every single file within the _comments directory will be read and parsed as a comment.

Each file in _comments represents a single comment, as a YAML hash. The YAML must contain a post_id attribute, which corresponds to the id of the post it is a comment on, but apart from that the YAML fields are anything you want them to be.

The fields in your YAML file will be mapped to fields in a Comment object. There is a new page.comments field, which contains a list of the Comment objects for each post. Iterating through a post and printing the comments is as simple as:

{% for c in page.comments %}
  <a href="{{c.link}}">{{c.nick}}</a>
  <p>
    {{c.content}}
  </p>
  <hr />
{% endfor %}

This, of course, assumes that your YAML comments have the link, nick, and content fields. Your mileage will vary.

The order of the comments list returned in the page.comments array is based on the lexical ordering of the filenames that the comments are stored in. Hence, you can preserve strict date ordering of your comments by ensuring that the filenames are based around the date/time of comment submission.

Of course, the tricky bit in all this is getting the comments from your users into the filesystem. For that, I'm using the commentsubmit.php in this repo, which simply takes all the fields in your comment form, dumps them straight into YAML, and e-mails it to me. However, you can do whatever you like -- save them somewhere on your webserver for you to scp down later, or go the whole hog and have them automatically committed to your git repo and the site regenerated.

E-mailing the comments to you, though, is a fairly natural workflow. You just save the comments out to your _comments directory, then re-generate the site and upload. This provides a natural "moderation" mechanism, at the expense of discouraging wide-ranging "realtime" discussion.

A caveat about Liquid

Never use the word comment by itself as an identifier of any kind (variable, whatever) in your Liquid templates: the language considers it to be the start of a comment (regardless of where it appears) and eats your code. Yes, apparently Liquid really is that stupid. At the very least, you'll need to put a prefix or suffix or something so that Liquid doesn't think you're trying to execute it's comment function.

Still too much dynamic code?

If you like the idea of static comments, but you think that there's still too much dynamic code, then you might like to consider Tomas Carnecky's even-more-static-comments, which uses a special per-post e-mail address to receive comments via a mailto: URL.

Licencing, bug reports, patches, etc

This plugin is licenced under the terms of the GNU GPL version 3. If it works for you, great. If it doesn't, please e-mail me a patch with a description of the bug. Bug reports without patches will probably be ignored unless I'm feeling in a good mood. Particularly bug reports may be publically ridiculed.

More Repositories

1

lvmsync

Synchronise LVM LVs across a network by sending only snapshotted changes
Ruby
369
star
2

action-validator

Tool to validate GitHub Action and Workflow YAML files
Rust
144
star
3

giddyup

Simple web application deployment with "git push"
Ruby
93
star
4

git-version-bump

Track your app's version entirely with git tags
Ruby
47
star
5

nginx

C
32
star
6

email-address-validator

Advanced E-mail address validation library in Ruby
Ruby
16
star
7

vmdksync

Apply VMDK snapshot files
Ruby
14
star
8

isc-dhcp

Mirror of ISC DHCP from https://source.isc.org/git/dhcp.git, plus local patches of my own
C
14
star
9

merkle-hash-tree

A Ruby implementation of a merkle hash tree
Ruby
13
star
10

ruby-snmp-agent

An easily extensible SNMP agent, written entirely in Ruby
Ruby
9
star
11

dns323-firmware-tools

Tools to create and dissect firmware for the DNS-323 and similar NAS boxes
Ruby
9
star
12

sequel-pg-comment

Create PostgreSQL comments within Sequel migrations and schema modification methods
Ruby
8
star
13

rethtool

A ruby wrapper for the SIOCETHTOOL ioctl
Ruby
8
star
14

redmine_issue_dependency_graph

A Redmine plugin to display a graph of relationships between issues
Ruby
8
star
15

evinrude

A Raft engine for Ruby
Ruby
7
star
16

certificate-transparency-client

client for RFC6962 Certificate Transparency log servers
Ruby
5
star
17

typo-guard

Checksum text files before printing for safe and easy re-entry
Ruby
4
star
18

pbuilder

Shell
3
star
19

github-release

Automatically create releases on github from local git tags
Ruby
3
star
20

frankenstein

the modern Prometheus -- eases the task of instrumenting services written in Ruby
Ruby
3
star
21

moby-derp

Tool for securely derping a pod of containers
Ruby
2
star
22

hyperdex-gem

HyperDex bindings for Ruby
C
1
star
23

em-pg-client-helper

Helpful wrapper for em-pg-client
Ruby
1
star
24

rack-logstash

Complete logstash logging for your Rack applications
Ruby
1
star
25

s3blade

An AoE target which stores sectors in an S3-compatible object store
Ruby
1
star
26

marquise-ruby

Ruby bindings for libmarquise
Ruby
1
star
27

puppet-module-shorewall

Shorewall management using Puppet
Puppet
1
star