Skip to content

Commit

Permalink
Added utteranc.es and Cactus Comments support
Browse files Browse the repository at this point in the history
  • Loading branch information
oneleaftea committed Aug 22, 2021
1 parent 8073c98 commit 02e057b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 26 deletions.
12 changes: 10 additions & 2 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,16 @@ weight = 4
showReadTime = true # default

[params.comments]
enabled = false # default
engine = "disqus" # more supported engines will be added.
enabled = true # default
engine = "cactus_comments" # only disqus, utterances, and cactus_comments is supported
[params.comments.utterances]
repo = "<github_username>/<github_reponame>"
label = "hugo-site-name" # you can use however you want to label your name in your repo's issues
theme = "github-light"
[params.comments.cactuscomments]
siteName = "your_cactus_comments_sitename" # see https://cactus.chat/ on how to register your site name
#serverUrl = "" # Defaults to https://matrix.cactus.chat:8448 (Cactus Chat public server)
#serverName = "" # Defaults to cactus.chat

# the value of name should be an valid font awesome icon name (brands type)
# https://fontawesome.com/icons?d=gallery&s=brands
Expand Down
34 changes: 10 additions & 24 deletions layouts/partials/comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,13 @@

{{ $enable_comments := .Scratch.Get "enable_comments" }}
{{ if $enable_comments }}
{{ if (or (not (isset .Site.Params.Comments "engine")) (eq .Site.Params.Comments.Engine "disqus")) }}
<div class="blog-post-comments">
<div id="disqus_thread">
<script type="text/javascript">

(function() {
// Don't ever inject Disqus on localhost--it creates unwanted
// discussions from 'localhost:1313' on your Disqus account...
// if (window.location.hostname == "localhost")
// return;

var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
var disqus_shortname = '{{ if .Site.DisqusShortname }}{{ .Site.DisqusShortname }}{{ else }}{{ .Site.Title }}{{ end }}';
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com/" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
</div>

{{ end }}
{{ end }}
<div class="blog-post-comments">
{{ if (or (not (isset .Site.Params.Comments "engine")) (eq .Site.Params.Comments.Engine "disqus")) }}
{{ partial "comments/disqus.html" . }}
{{ else if eq .Site.Params.Comments.Engine "utterances" }}
{{ partial "comments/utterances.html" . }}
{{ else if eq .Site.Params.Comments.Engine "cactus_comments" }}
{{ partial "comments/cactus_comments.html" . }}
{{ end }}
</div>
{{ end }}
11 changes: 11 additions & 0 deletions layouts/partials/comments/cactus_comments.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div id="cactus-comments-thread">
<script>
initComments({
node: document.getElementById("cactus-comments-thread"),
defaultHomeserverUrl: '{{ default "https://matrix.cactus.chat:8448" .Site.Params.Comments.Cactuscomments.ServerUrl }}',
serverName: '{{ default "cactus.chat" .Site.Params.Comments.Cactuscomments.ServerName }}',
siteName: "{{ .Site.Params.Comments.Cactuscomments.SiteName }}",
commentSectionId: "{{ .RelPermalink }}"
})
</script>
</div>
17 changes: 17 additions & 0 deletions layouts/partials/comments/disqus.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div id="disqus_thread">
<script type="text/javascript">
(function() {
// Don't ever inject Disqus on localhost--it creates unwanted
// discussions from 'localhost:1313' on your Disqus account...
// if (window.location.hostname == "localhost")
// return;

var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
var disqus_shortname = '{{ if .Site.DisqusShortname }}{{ .Site.DisqusShortname }}{{ else }}{{ .Site.Title }}{{ end }}';
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com/" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
10 changes: 10 additions & 0 deletions layouts/partials/comments/utterances.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div id="disquss_thread">
<script src="https://utteranc.es/client.js"
repo="{{ .Site.Params.Comments.Utterances.Repo }}"
issue-term="pathname"
label="{{ .Site.Params.Comments.Utterances.Label }}"
theme="{{ .Site.Params.Comments.Utterances.Theme }}"
crossorigin="anonymous"
async>
</script>
</div>
2 changes: 2 additions & 0 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<link rel="preload" href="{{ "lib/font-awesome/webfonts/fa-regular-400.woff2" | relURL }}" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="{{ "lib/font-awesome/webfonts/fa-solid-900.woff2" | relURL }}" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="{{ "lib/JetBrainsMono/web/woff2/JetBrainsMono-Regular.woff2" | relURL }}" as="font" type="font/woff2" crossorigin="anonymous">
<script type="text/javascript" src="https://latest.cactus.chat/cactus.js"></script>
<link rel="stylesheet" href="https://latest.cactus.chat/style.css" type="text/css">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{{ if .IsPage }} {{ .Title }} | {{ end }}{{ .Site.Title }}</title>
Expand Down

0 comments on commit 02e057b

Please sign in to comment.