Self-hosted Kommentarsystem für Hugo
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
comments
config
controller
js
screenshot
server
tls
.gitignore
README.md
config.json
main.go

README.md

cmnts

Self-hosted Kommentarsystem für Hugo.

Demo

LOG=* ./cmnts

frontmatter

+++
title = "Cmnts - Playground"
date = 2018-03-17T13:59:33+01:00
tags = ["blog", "hugo", "go"]
slug = "playground"
draft = false
share = false
comments = "2e5512b6-44fd-4e12-a8c0-7293f61225d9"
+++

post/single.html

...
{{ if .Params.comments }}
{{ partial "comments.html" . }}
{{ end }}
...

partials/comments.html

<div id="discourse" class="discourse hidden" data-comments-id="{{.Params.comments}}">
</div>
<script type="text/javascript" src="{{.Site.BaseURL}}js/proto.js"></script>
<script type="text/javascript" src="{{.Site.BaseURL}}js/api.js"></script>
<!--script type="text/javascript" src="{{.Site.BaseURL}}js/renderer.js"></script-->

Die Daten die aus der API herausfallen müssen noch entsprechend gerendert werden. Das bleibt jedem selbst überlassen und könnte z.B. so aussehen.

document.ready.then(function() {
  var discourse = $('#discourse');
  var id = discourse.attr('data-comments-id');
  if (id === undefined || id.length === 0) {
    return;
  };
  
  cmnts.init({
    file: id,
    url: 'https://example:8080'
  });
  
  cmnts.get().then(function(json) {
    if ('data' in json && json.data instanceof Array) {
      json.data.forEach(renderComment);
  };
            
  cmnts.listen(function(data) {
      renderComment(data);               
  });

});

License

released under the GPL 3 license.