• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 11 years ago
  • Updated almost 7 years ago

Reviews

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

Repository Details

External comments for static HTML pages, a lightweight self-hosted disqus alternative.

External Comments

This is an open source commenting system, allowing you to include comments on your static website(s) without the privacy concerns of using an external system such as disqus.

Embedding comments is as simple as including a couple of small javascript files, along with a CSS file for styling.

Features:

  • Multiple backends for storage:
    • Redis
    • SQlite
    • Adding new backends is simple.
  • Markdown formatting of comments.
  • Support for threaded discussion.
    • You can limit the depth of discussions, to a given depth.
    • Or leave the defaults in-place to allow arbitrarily nested replies.
  • Anti-spam plugins:
    • Three simple plugins included as a demonstration.
    • The sample plugins block hyperlinks in comment-author names, bodies which reference viagra, and any remote IPs which have been locally blacklisted.
  • Simplicity
    • The code is small enough to easily understand and extend for your custom needs, but functional as-is.
  • Degrades gracefully when Javascript is disabled
    • No white boxes, empty spaces, or error-messages.

Anti-features:

  • There is no administrative panel to edit/delete comments.
    • This requires manual intervention in the back-end.
  • Commenters do not get their details remembered.
    • Nor can they receive emails on replies to their comments.

Run-time (client-side) dependencies:

  • jQuery
  • mustache.js
    • Included in this repository.

This server was originally written for a server optimization guide but since it seemed like a generally-useful piece of code it was moved into its own repository.

Contents

The Comment Server

The comment server exports a public API allowing the javascript on your (static) pages to add comments, and retrieve those comments which already exist. It is written in Ruby using the sinatra, framework.

There are two choices for storing the actual comment data:

Adding new backends should be straight-forward, and pull-requests are welcome for MySQL, CouchDB, etc.

Comment Server API

The server implements the following two API methods:

  • GET /comments/ID
    • This retrieves the comments associated with the given ID.
    • The return value is an array of hashes.
    • The hashes have keys such as author, body & ip.
  • POST /comments/ID
    • Adds a new comment to the collection for the given ID.
    • The submission should have the fields author and body.
    • Optionally the submission might contain the field email.
      • If an email is stored a Gravitar field will be present in the retrieval, but the actual email address will not be sent back to avoid a privacy leak.
    • Optionally the submission might contain a parent field.
      • This is used to support nested comments.
      • There are no limits on the number of nested comments.

Comment Server Dependencies

These dependencies were tested on a Debian GNU/Linux stable machine, but are a good starting point for other distributions:

apt-get install ruby ruby-json ruby-sinatra ruby-redcarpet ruby-uuidtools ruby-rack-test

For storage you get to choose between one of these two alternatives:

apt-get install libsqlite3-ruby

Or

apt-get install ruby-redis

Comment Server Deployment

Deploying the server involves two steps:

  • Actually launching the server, via systemd, runit, or similar.
  • Configuring your webserver to proxy to it.

To launch the comment server you'll run one of these two commands, depending on which storage back-end you prefer to use:

 $ ./server/comments.rb --storage=redis  --storage-args=127.0.0.1
 $ ./server/comments.rb --storage=sqlite --storage-args=/tmp/foo.db

The server will bind to 127.0.0.1:9393 by default, so you'll need to setup a virtual host in nginx/apache which will forward connections to that instance.

For nginx this would look something like this:

server {
  listen          80;
  server_name     comments.example.com;
  location / {
    proxy_pass        http://127.0.0.1:9393;
    proxy_redirect    off;
    proxy_set_header  X-Forwarded-For $remote_addr;
  }
}

Client-Side Setup

To allow comments upon your static site you must update your page(s) to include the appropriate javascript libraries, and the CSS.

For basic usage you'll be adding this to the <head> of your HTML:

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="/js/mustache.js" type="text/javascript"></script>
<script src="/js/e-comments.js" type="text/javascript"></script>

<script type="text/javascript">
  $( document ).ready(function() {
    discussion( "http://server.name/comments/COMMENT_ID" );
});
</script>

At the place you wish your comments to be displayed you'll add:

<div id="comments"></div>

Advanced Usage

The example above configured the display of comments with the defaults, but the discussion() method actually accepts two arguments:

  • The URL of the comment-server you've got running, including a discussion ID.
  • An optional hash of parameters, to customize behaviour.

The discussion will require a unique key, which will be specified as an URL. For example your home-page might include this:

    discussion( "http://comments.example.com/comments/home" );

Your about page this:

    discussion( "http://comments.example.com/comments/about" );

This will ensure that each page will have a distinct discussion-thread upon it.

The second parameter, which is optional, allows things to be customized. Valid options for this hash include:

  • comments
    • The ID of the <div> in which comments will be inserted.
    • The default will be comments, as documented above.
  • max_depth
    • This should be an integer holding the maximum thread-depth permitted.
    • The default value is 0, which allows an unlimited thread-depth.
  • threading
    • A boolean to control whether threading is enabled/disabled.
    • The default value is true.
  • comment_template
    • The ID of a script-div which contains a template for comment-formatting.
  • reply_template
    • The ID of a script-div which contains a template for the "add comment" form.

If you wished to disable threading, allowing only a flat discussion hierarchy, you'd use this:

 discussion( "http://comments.example.com/comments/about",
             { threading: false });

If you wished to allow comments, but stop arbitrary nesting:

 discussion( "http://comments.example.com/comments/about",
             { threading: true, max_depth: 2 });

Theming

You could customize the formatting of comments, and the comment-submission form via CSS, however you might prefer to replace the presentation with something entirely different.

To allow this we use mustache.js templates for:

  • The display of the individual comments.
  • The display of the reply-form.

You can hide templates for both of these things inside your static HTML-files and cause them to be used by specifing their IDs like so:

    discussion( "http://localhost:9393/comments/id",
                { comment_template: '#comment_template',
                  reply_template: '#reply_form'} );

This would require your HTML-page to contain something like this:

<script id="comment_template" type="x-tmpl-mustache">
 <div class="comment">
 <div class="link"><a href="#comment_{{ id }}">#{{ id }}</a></div>
 ..
</script>

NOTE: You can find the default templates which are used inside the e-comments.js file.

Replacing the template entirely allows you to display different data, for example you might wish to show the thread-level of each comment. This could be achived by adding the following to the comment-template:

 Depth:{{#depth}}{{ uuid }}{{/depth}}

I'm open to pull-requests adding more formatting options, if you have something you think would be useful. (Similarly any improvements to the presentation of comments by default would be appreciated.)

Alternative Systems

Running Locally

Providing you have the dependencies installed you can run the same demo locally:

  • Launch the comment-server in one terminal.
    • ./server/comments.rb --storage=sqlite --storage-args=/tmp/foo.db
    • The file /tmp/foo.db will be created, and used to store your comments.
  • Start a local HTTP server in clients in another:
    • cd client ; python -m SimpleHTTPServer
  • Open your browser:

This local demo works because the demo.html file is configured to access comments at http://localhost:9393/. In a real deployment you'd hide the comment-server behind a reverse proxy and access it via a public name such as comments.example.com.

Steve

More Repositories

1

sysadmin-util

Tools for Linux/Unix sysadmins.
Perl
949
star
2

bookmarks.public

A template for self-hosted bookmarks using HTML & jQuery.
JavaScript
662
star
3

tunneller

Allow internal services, running on localhost, to be accessed over the internet..
Go
474
star
4

simple.vm

Simple virtual machine which interprets bytecode.
C
459
star
5

deployr

A simple golang application to automate the deployment of software releases.
Go
334
star
6

gobasic

A BASIC interpreter written in golang.
Go
325
star
7

go.vm

A simple virtual machine - compiler & interpreter - written in golang
Go
322
star
8

simple-vpn

A simple VPN allowing mesh-like communication between nodes, over websockets
Go
284
star
9

monkey

An interpreted language written in Go
Go
272
star
10

sysbox

sysadmin/scripting utilities, distributed as a single binary
Go
218
star
11

esp8266

Collection of projects for the WeMos Mini D1
C++
165
star
12

kilua

A minimal text-editor with lua scripting.
C++
160
star
13

sos

Simple Object Storage (I wish I could call it Steve's Simple Storage, or S3 ;)
Go
150
star
14

github-action-publish-binaries

Publish binaries when new releases are made.
Shell
137
star
15

evalfilter

A bytecode-based virtual machine to implement scripting/filtering support in your golang project.
Go
117
star
16

rss2email

Convert RSS feeds to emails
Go
112
star
17

cpmulator

Golang CP/M emulator for zork, Microsoft BASIC, Turbo Pascal, Wordstar, lighthouse-of-doom, etc
Go
97
star
18

lighthouse-of-doom

A simple text-based adventure game
C
95
star
19

linux-security-modules

A place to store my toy linux-security modules.
C
90
star
20

marionette

Something like puppet, for the localhost only.
Go
85
star
21

kpie

Simple devilspie-like program for window manipulation, with Lua.
C
79
star
22

foth

Tutorial-style FORTH implementation written in golang
Go
78
star
23

dhcp.io

Dynamic DNS - Via Redis, Perl, and Amazon Route53.
Perl
68
star
24

templer

A modular extensible static-site-generator written in perl.
Perl
63
star
25

overseer

A golang-based remote protocol tester for testing sites & service availability
Go
62
star
26

assembler

Basic X86-64 assembler, written in golang
Go
61
star
27

math-compiler

A simple intel/AMD64 assembly-language compiler for mathematical operations
Go
60
star
28

node-reverse-proxy.js

A reverse HTTP-proxy in node.js
JavaScript
54
star
29

webmail

A golang webmail server.
Go
52
star
30

dotfiles

Yet another dotfile-repository
Emacs Lisp
49
star
31

github2mr

Export all your github repositories to a form suitable for 'myrepos' to work with.
Go
46
star
32

puppet-summary

The Puppet Summary is a web interface providing reporting features for Puppet, it replaces the Puppet Dashboard project
Go
46
star
33

org-worklog

A template for maintaining a work-log, via org-mode.
42
star
34

rss2hook

POST to webhook(s) when new feed-items appear.
Go
37
star
35

tweaked.io

The code behind http://tweaked.io/
JavaScript
36
star
36

pam_pwnd

A PAM module to test passwords against previous leaks at haveibeenpwned.com
C
35
star
37

critical

A simple/minimal TCL interpreter, written in golang
Go
34
star
38

alphavet

A golang linter to detect functions not in alphabetical order
Go
32
star
39

dns-api-go

The code behind https://dns-api.org/
Go
31
star
40

markdownshare.com

The code which was previously used at http://markdownshare.com/
Perl
29
star
41

github-action-tester

Run tests when pull-requests are opened, or commits pushed.
Shell
26
star
42

bfcc

BrainFuck Compiler Challenge
Go
22
star
43

maildir-tools

Golang-based utility which can be used for scripting Maildir things, and also as a basic email client
Go
22
star
44

purppura

A server for receiving and processing alerts & events.
Go
21
star
45

cpm-dist

A curated collection of CP/M software
C
20
star
46

implant

Simple utility for embedding files/resources inside golang binaries
Go
20
star
47

chronicle2

Chronicle is a simple blog compiler, written in Perl with minimal dependencies.
Perl
20
star
48

z80-examples

Z80 assembly-language programs.
Makefile
19
star
49

dns-api.org

The code which was previously used at https://dns-api.org/
Perl
19
star
50

yal

Yet another lisp interpreter
Go
16
star
51

ephemeris

A static blog-compiler
Go
15
star
52

markdownshare

The code behind https://markdownshare.com/
Go
15
star
53

aws-utils

A small collection of AWS utilities, packaged as a single standalone binary.
Go
14
star
54

z80retroshield

Arduino library for driving the Z80 retro-shield.
Shell
13
star
55

predis

A redis-server written in Perl.
Perl
12
star
56

github-action-build

Build a project, creating artifacts
Shell
12
star
57

webserver-attacks

Identify attacks against webservers via simple rules
Perl
12
star
58

Device-Osram-Lightify

Interface to the Osram Lightify system
Perl
12
star
59

labeller

Script label addition/removal for gmail/gsuite email.
Go
10
star
60

da-serverspec

ServerSpec.org configuration for the Debian-Administration cluster.
Ruby
10
star
61

docker-api-gateway

Trivial API-gateway for docker, via HAProxy
Go
10
star
62

http2xmpp

HTTP to XMPP (jabber) bridge.
Perl
9
star
63

nanoexec

Trigger commands over a nanomsg queue
C
9
star
64

go-experiments

Repository containing experiments as I learn about golang
Go
9
star
65

golang-metrics

Automatic submission of system metrics to graphite, for golang applications
Go
8
star
66

pass

password-store distribution, with plugins.
Shell
8
star
67

ms-lite

A collection of plugins for a qpsmtpd-powered virtual-host aware SMTP system.
Perl
8
star
68

remotehttp

Magic wrapper to deny HTTP-requests to to "local" resources.
Go
8
star
69

dashboard

Redis & node.js powered dashboard skeleton
JavaScript
8
star
70

Buffalo-220-NAS

Installing NFS on a Buffalo 220 NAS device
Shell
8
star
71

asql

A toy utility to process Apache log files via SQL.
Perl
7
star
72

knownfs

A FUSE-based filesystem that exports ~/.ssh/known_hosts
Go
7
star
73

mpd-web

Simple HTTP view of an MPD server
Go
7
star
74

DockerFiles

Container for various dockerfiles.
Shell
6
star
75

yawns

Yet another weblog/news site
Perl
6
star
76

org-diary

Easily maintain a simple work-log / journal with the use of org-mode
Emacs Lisp
6
star
77

cidr_match.js

A simple module to test whether a given IPv4 address is within a particular CIDR range.
JavaScript
6
star
78

mod_writable

Disallow serving writable files under Apache 2.4.x
C
5
star
79

mod_blacklist

A simple Apache module to blacklist remote hosts.
C
5
star
80

arduino-mega-z80-simplest

The simplest possible project combining an Arduino Mega and a Zilog Z80 processor
C++
4
star
81

turtle

A simple turtle-implementation, using FORTH as a scripting-language
Go
4
star
82

purple

A simplified version of mauvealert
Perl
3
star
83

subcommands

Easy subcommand handling for a golang based command-line application
Go
3
star
84

runme

A quick hack for running commands from README.md files
Go
3
star
85

thyme

A simple package-building system, using docker
Perl
2
star
86

httpd

Simple golang HTTP server
Go
2
star
87

edinburgh.io

Open pub database
JavaScript
2
star
88

lexing-parsing-linting-stuffs

Code to go with my talk
Python
2
star
89

run-directory

A simple application inspired by `run-parts`.
Go
2
star
90

Redis--SQLite

Redis-Compatible module which writes to SQLite
Perl
2
star
91

devopswithdocker.com

Repository created for the Helsinki University course.
Dockerfile
2
star
92

aws-list

Export a dump of all running EC2 instances, along with AMI details, AMI age, etc, etc.
1
star
93

WebService--Amazon--Route53--Caching

Perl module to cache the results of WebService::Amazon::Route53
Perl
1
star
94

calibre-plugins

A small collection of calibre-plugins.
Python
1
star
95

org-tag-cloud

Easily maintain a tag-cloud of org-mode tags.
Emacs Lisp
1
star
96

headerfile

Parse files with simple key:value headers, easily.
Go
1
star
97

z80-cpm-scripting-interpreter

A trivial I/O language, with repl, written in z80 assembler to run under CP/M.
Makefile
1
star
98

Test--RemoteServer

The Perl module Test::RemoteServer
Perl
1
star