Skip to content

Commit

Permalink
Github for comments
Browse files Browse the repository at this point in the history
New blog post
  • Loading branch information
dwilliamson committed Apr 21, 2017
1 parent d7cde23 commit d7f1f58
Show file tree
Hide file tree
Showing 47 changed files with 2,846 additions and 323 deletions.
1 change: 0 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ tag = "tags"
[params]
author = "Don Williamson"
description = "Don Williamson, Consultant Game Technology Programmer/Director of Celtoys"
disqusShortname = "gazoo"
twitter = "Donzanoid"
github = "dwilliamson"
github2 = "Celtoys"
Expand Down
Binary file added content/img/GithubComments/DisqusLoadLog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/img/GithubComments/DisqusLoadLogHigh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/img/GithubComments/LoadLog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/img/GithubComments/LoadLogHigh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
172 changes: 172 additions & 0 deletions content/post/github-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
+++
date = "2017-04-21T20:30:00+01:00"
draft = false
title = "Replacing Disqus with Github Comments"
tags = [ "blog" ]
ghcommentid = 1
+++

I've been considering removing comments from this blog for a while; mainly because the site doesn't
trigger much discussion and I didn't like keeping the overhead of [Disqus](https://disqus.com/)
around. After looking into Disqus load-time behaviour I was pretty shocked what I was forcing
on people loading the site (although you really should be using the likes of [Privacy Badger](https://www.eff.org/privacybadger) and [uBlock Origin](https://github.com/gorhill/uBlock)).

<!--more-->

This post is Hugo-specific but the very little code required can be adapted to any website.

##### What's Wrong with Disqus?

This is a typical request log with Disqus *enabled*:

<center>[![d](/img/GithubComments/DisqusLoadLog.png)](/img/GithubComments/DisqusLoadLogHigh.png)</center>

This is the same request log with Disqus *disabled*:

<center>[![d](/img/GithubComments/LoadLog.png)](/img/GithubComments/LoadLogHigh.png)</center>

<center>***WAT!?***</center>

Relevant points are:

* Load-time goes from 6 seconds to 2 seconds.
* There are 105 network requests vs. 16.
* There are a lot of non-relevant requests going through to networks that will be tracking your movements.

Among the networks you can find:

* `disqus.com` - Obviously!
* `google-analytics.com` - Multiple requests; no idea who's capturing your movements.
* `connect.facebook.net` - If you're logged into Facebook, they know you visit this site.
* `accounts.google.com` - Google will also map your visits to this site with any of your Google accounts.
* `pippio.com` - LiveRamp identify mapping for harvesting your details for commercial gain.
* `bluekai.com` - Identity tracking for marketing campaigns.
* `crwdcntrl.net` - Pretty suspect site listed as referenced by viruses and spyware.
* `exelator.com` - More identity and movement tracking site which even has a virus named after it!
* `doubleclick.net` - We all know this one: ad services and movement tracking, owned by Google.
* `tag.apxlv.net` - Very shady and [tricky to pin-point an owner](https://better.fyi/trackers/apxlv.com/) as they obsfuscate their domain (I didn't even know this was a thing!). Adds a tracking pixel to your site.
* `adnxs.com` - More tracking garbage, albeit slightly [more prolific](https://www.theguardian.com/technology/2012/apr/23/adnxs-tracking-trackers-cookies-web-monitoring).
* `adsymptotic.com` - Advertising and tracking that suppposedly uses machine learning.
* `rlcdn.com` - Obsfuscated advertising/tracking from Rapleaf.
* `adbrn.com` - *"Deliver a personalized customer journey across devices, channels and platforms with Adbrain customer ID mapping technology."*
* `nexac.com` - Oracle's Datalogix, their own tracking and behavioural pattern rubbish.
* `tapad.com` - OK, I cant't be bothered to search to look this up anymore.
* `liadm.com` - More? Oh, ok, then...
* `sohern.com` - Yup. Tracking.
* `demdex.net` - Tracking. From Adobe.
* `bidswitch.net` - I'll give you one guess...
* `agkn.com` - ...
* `mathtag.com` - Curious name, maybe it's... no. It's tracking you.

I can't visit many of these sites because I have them blocked in uBlock Origin so information was
gleaned from google crawl results of the webpages and 3rd parties. Needless to say, it's a pretty disgusting insight into how certain free products turn you into
the product. What's more worrying are the services that go to lengths to hide who they are and
what their purposes are for tracking your movements.

Anyway. Delete it. I'm sorry for poisoning this site with these networks. Foward to better things...

##### Using Github for Comments

I was discussing removing Disqus with others and [@HarryDenholm](https://twitter.com/HarryDenholm)
mentioned that a friend managed to get comments on their Github-hosted static blog using Pull Requests. I thought this was pretty genius and wanted to figure out if I could do something
similar for Hugo on external sites.

The answer came from the [Github Issue API](https://developer.github.com/v3/issues/). The process is quite simple and is already active on this blog post:

1. For each blog post you make, open an Issue on some repo on Github. The Issue for this post is [here](https://github.com/dwilliamson/donw.io/issues/1).
2. All comments are posted directly on Github.
3. Add some Javascript to your site that reads Github's JSON description of the Issue comments and displays them.

The benefits are immediate:

* There is zero tracking of you as a reader to this website. Github themselves only see network read requests from unnamed IPs.
* All comments are written in [Markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet), allowing inline code, images, lists and formatting.
* You can use Github's notifications to informed of responses; you don't even have to visit this site to read and contribute to discussion.
* Although somewhat superflous, you can also integrate [Github Reactions](https://developer.github.com/v3/reactions/) (maybe useful on larger sites).

You don't need an API key to read Github JSON data; it's free for all to access. The comments for
this post can be read as JSON [here](https://api.github.com/repos/dwilliamson/donw.io/issues/1/comments). The first comment looks like:

```json
{
"url": "https://api.github.com/repos/dwilliamson/donw.io/issues/comments/295004846",
"html_url": "https://github.com/dwilliamson/donw.io/issues/1#issuecomment-295004846",
"issue_url": "https://api.github.com/repos/dwilliamson/donw.io/issues/1",
"id": 295004846,
"user": {
"login": "dwilliamson",
"id": 1532903,
"avatar_url": "https://avatars3.githubusercontent.com/u/1532903?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/dwilliamson",
"html_url": "https://github.com/dwilliamson",
"followers_url": "https://api.github.com/users/dwilliamson/followers",
"following_url": "https://api.github.com/users/dwilliamson/following{/other_user}",
"gists_url": "https://api.github.com/users/dwilliamson/gists{/gist_id}",
"starred_url": "https://api.github.com/users/dwilliamson/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/dwilliamson/subscriptions",
"organizations_url": "https://api.github.com/users/dwilliamson/orgs",
"repos_url": "https://api.github.com/users/dwilliamson/repos",
"events_url": "https://api.github.com/users/dwilliamson/events{/privacy}",
"received_events_url": "https://api.github.com/users/dwilliamson/received_events",
"type": "User",
"site_admin": false
},
"created_at": "2017-04-18T22:39:16Z",
"updated_at": "2017-04-18T22:39:16Z",
"body": "This is a comment"
},
```

The first step is to add a new template to your partials directory that reads and displays Github
comments (`comments.html`). Here's the code I use:

```js
var url = "https://github.com/dwilliamson/donw.io/issues/" + {{ $.Params.ghcommentid }}
var api_url = "https://api.github.com/repos/dwilliamson/donw.io/issues/" + {{ $.Params.ghcommentid }} + "/comments"

$(document).ready(function () {
$.ajax(api_url, {
headers: {Accept: "application/vnd.github.v3.html+json"},
dataType: "json",
success: function(comments) {
$("#gh-comments-list").append("Visit the <b><a href='" + url + "'>Github Issue</a></b> to comment on this post");
$.each(comments, function(i, comment) {

var date = new Date(comment.created_at);

var t = "<div id='gh-comment'>";
t += "<img src='" + comment.user.avatar_url + "' width='24px'>";
t += "<b><a href='" + comment.user.html_url + "'>" + comment.user.login + "</a></b>";
t += " posted at ";
t += "<em>" + date.toUTCString() + "</em>";
t += "<div id='gh-comment-hr'></div>";
t += comment.body_html;
t += "</div>";
$("#gh-comments-list").append(t);
});
},
error: function() {
$("#gh-comments-list").append("Comments are not open for this post yet.");
}
});
});
```

This can then be invoked from your blog post html:

```
{{ partial "comments.html" . }}
```

The variables it references need to be added to the header of your html page. In this case it's
the single variable `ghcommentid` which is set to the number of the Issue used for comments.

##### Summary

There's nothing more beyond that. Technically, you could actually write your blog posts as Github
Issues themselves and forgo the need for a blog engine. But that seems too much like using a system
in ways it was never intended to be used.

This website is managed on Github as [dwilliamson/donw.io](https://github.com/dwilliamson/donw.io).
It contains the complete code for using Github for your comments.
31 changes: 30 additions & 1 deletion public/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -836,4 +836,33 @@ margin-bottom:2em!important;
.pagination {
margin:4em 0 6em!important;
}
}
}


#gh-comments {
text-align: center;
}

#gh-comment {
text-align: left;
color:#FFF;
background-color:#272822;
border:1px solid #b3b3b3;
margin:2.5em 0;
padding:10px;
}

#gh-comment-hr {
border-top: inset 1px white;
margin: 8px 0px;
}

#gh-comment p {
margin:0px;
}

#gh-comment img {
display: inline;
vertical-align: middle;
margin: 2px 10px 2px 2px;
}
Binary file added public/img/GithubComments/DisqusLoadLog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/GithubComments/DisqusLoadLogHigh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/GithubComments/LoadLog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/GithubComments/LoadLogHigh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 35 additions & 41 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,31 @@

<article class="li post">
<header class="post-header">
<h3 class="post-title"><a href="http://donw.io/post/github-comments/">Replacing Disqus with Github Comments</a></h3>
<p class="post-time"><time datetime="2017-04-21T20:30:00&#43;01:00">April 21, 2017</time></p>
</header>

<section class="post-excerpt">
<p><p>I&rsquo;ve been considering removing comments from this blog for a while; mainly because the site doesn&rsquo;t
trigger much discussion and I didn&rsquo;t like keeping the overhead of <a href="https://disqus.com/">Disqus</a>
around. After looking into Disqus load-time behaviour I was pretty shocked what I was forcing
on people loading the site (although you really should be using the likes of <a href="https://www.eff.org/privacybadger">Privacy Badger</a> and <a href="https://github.com/gorhill/uBlock">uBlock Origin</a>).</p>
</p>
</section>

<footer class="post-footer">
<span>


&nbsp;&nbsp;<i class="fa fa-tag"></i>
blog

</span>
</footer>
</article>

<article class="li post">
<header class="post-header">
<h3 class="post-title"><a href="http://donw.io/post/frustum-point-extraction/">Three Methods to Extract Frustum Points</a></h3>
<p class="post-time"><time datetime="2016-10-23T19:14:32&#43;01:00">October 23, 2016</time></p>
</header>
Expand All @@ -85,8 +110,6 @@ <h3 class="post-title"><a href="http://donw.io/post/frustum-point-extraction/">T
<footer class="post-footer">
<span>

<a href="http://donw.io/post/frustum-point-extraction/#comments"><i class="fa fa-comment"></i> Comments</a>


&nbsp;&nbsp;<i class="fa fa-tag"></i>
math
Expand All @@ -109,8 +132,6 @@ <h3 class="post-title"><a href="http://donw.io/post/packed-circle-radius/">A Con
<footer class="post-footer">
<span>

<a href="http://donw.io/post/packed-circle-radius/#comments"><i class="fa fa-comment"></i> Comments</a>


&nbsp;&nbsp;<i class="fa fa-tag"></i>
math
Expand All @@ -133,8 +154,6 @@ <h3 class="post-title"><a href="http://donw.io/post/high-prec-noise-hlsl/">Mixed
<footer class="post-footer">
<span>

<a href="http://donw.io/post/high-prec-noise-hlsl/#comments"><i class="fa fa-comment"></i> Comments</a>


&nbsp;&nbsp;<i class="fa fa-tag"></i>
noise, gpu
Expand All @@ -156,8 +175,6 @@ <h3 class="post-title"><a href="http://donw.io/post/a-new-host-server-site/">A N
<footer class="post-footer">
<span>

<a href="http://donw.io/post/a-new-host-server-site/#comments"><i class="fa fa-comment"></i> Comments</a>


&nbsp;&nbsp;<i class="fa fa-tag"></i>
website
Expand All @@ -180,8 +197,6 @@ <h3 class="post-title"><a href="http://donw.io/post/distant-sphere-lights/">Dist
<footer class="post-footer">
<span>

<a href="http://donw.io/post/distant-sphere-lights/#comments"><i class="fa fa-comment"></i> Comments</a>


&nbsp;&nbsp;<i class="fa fa-tag"></i>
pbr, lighting
Expand All @@ -204,8 +219,6 @@ <h3 class="post-title"><a href="http://donw.io/post/high-prec-gradient-noise/">V
<footer class="post-footer">
<span>

<a href="http://donw.io/post/high-prec-gradient-noise/#comments"><i class="fa fa-comment"></i> Comments</a>


&nbsp;&nbsp;<i class="fa fa-tag"></i>
noise, simd, gpu
Expand All @@ -227,8 +240,6 @@ <h3 class="post-title"><a href="http://donw.io/post/animation-autocorrelation/">
<footer class="post-footer">
<span>

<a href="http://donw.io/post/animation-autocorrelation/#comments"><i class="fa fa-comment"></i> Comments</a>


&nbsp;&nbsp;<i class="fa fa-tag"></i>
animation
Expand All @@ -250,8 +261,6 @@ <h3 class="post-title"><a href="http://donw.io/post/dual-quaternion-skinning/">Q
<footer class="post-footer">
<span>

<a href="http://donw.io/post/dual-quaternion-skinning/#comments"><i class="fa fa-comment"></i> Comments</a>


&nbsp;&nbsp;<i class="fa fa-tag"></i>
quaternions, animation
Expand All @@ -273,31 +282,6 @@ <h3 class="post-title"><a href="http://donw.io/post/reflection-cpp-2/">Reflectio
<footer class="post-footer">
<span>

<a href="http://donw.io/post/reflection-cpp-2/#comments"><i class="fa fa-comment"></i> Comments</a>


&nbsp;&nbsp;<i class="fa fa-tag"></i>
c++, reflection

</span>
</footer>
</article>

<article class="li post">
<header class="post-header">
<h3 class="post-title"><a href="http://donw.io/post/reflection-cpp-1/">Reflection in C&#43;&#43;, Part 1: Introduction</a></h3>
<p class="post-time"><time datetime="2011-09-25T23:34:13&#43;01:00">September 25, 2011</time></p>
</header>

<section class="post-excerpt">
<p>If there was one job I&rsquo;d love to do other than writing games it&rsquo;d be writing compilers. This probably explains my obsession with the subject of reflection; a topic I&rsquo;ve been hammering away at for almost 10 years now. Having written a few compilers in the past, it became glaringly obvious to me that reflection would be quite simple to add to C++ &ndash; if you&rsquo;re willing to place some limits on it &ndash; and that the language has suffered from its absence.</p>
</section>

<footer class="post-footer">
<span>

<a href="http://donw.io/post/reflection-cpp-1/#comments"><i class="fa fa-comment"></i> Comments</a>


&nbsp;&nbsp;<i class="fa fa-tag"></i>
c++, reflection
Expand All @@ -307,6 +291,16 @@ <h3 class="post-title"><a href="http://donw.io/post/reflection-cpp-1/">Reflectio
</article>


<nav role="pagination" class="pagination">

<span class="post-list-pagination-item post-list-pagination-item-current">Page 1 of 2</span>

<a href="/page/2/" class="older-posts">
&nbsp;Older&nbsp;<i class="fa fa-angle-double-right"></i>
</a>

</nav>

</div>
</main>
<footer id="site-footer">
Expand Down
Loading

0 comments on commit d7f1f58

Please sign in to comment.