feat: refactor commenting system + add support for Commento

BREAKING CHANGES
See #1218

Close #1218
This commit is contained in:
George Cushen committed 2019-07-22 19:50:11 +01:00
1 parent 96d061bfff
commit a1ba678e79
10 files changed
+68 -29

No files matched your search

-3
View File
@@ -18,9 +18,6 @@ copyright = ""
# Enable analytics by entering your Google Analytics tracking ID
googleAnalytics = ""
# Enable comments by entering your Disqus shortname
disqusShortname = ""
############################
## Advanced options below ##
############################
+17 -4
View File
@@ -45,7 +45,7 @@ privacy_pack = false
# Enable visitors to edit pages?
# `repo` defines the repository URL. `editable` defines which page types can be edited.
edit_page = {repo_url = "https://github.com/gcushen/hugo-academic", editable = {docs = true}}
edit_page = {repo_url = "https://github.com/gcushen/hugo-academic", editable = {docs = true, page = false, post = false}}
# Date and time format (refer to https://sourcethemes.com/academic/docs/customization/#date-format )
# Examples: "Mon, Jan 2, 2006" or "2006-01-02"
@@ -123,9 +123,6 @@ menu_align_right = false
# Show estimated reading time for posts? (true/false)
reading_time = true
# Display comment count (if commenting enabled in config.toml)? (true/false)
comment_count = true
# Display next/previous section pager? (true/false)
section_pager = false
docs_section_pager = true # Display pager in Docs layout (e.g. tutorials)?
@@ -153,6 +150,22 @@ sharing = true
publication_view = 2
talk_view = 2
# Comments.
[comments]
# Comment provider:
# 0: Disabled
# 1: Disqus (https://disqus.com)
# 2: Commento (https://commento.io)
engine = 0
# Which page types are commentable?
commentable = {page = true, post = true, docs = true}
# Configuration of Disqus.
[comments.disqus]
shortname = "" # Paste the shortname from your Disqus dashboard.
show_count = true # Show comment count in page header? (true/false)
# Search.
[search]
# Search provider:
+7 -5
View File
@@ -2,7 +2,7 @@
<article class="article" itemscope itemtype="http://schema.org/Article">
{{ partial "page_header.html" . }}
{{ partial "page_header" . }}
<div class="article-container">
@@ -10,10 +10,12 @@
{{ .Content }}
</div>
{{ partial "tags.html" . }}
{{ partial "edit_page" . }}
{{ partial "tags" . }}
{{ if ne .Type "page" }}
{{ partial "page_author.html" . }}
{{ partial "page_author" . }}
{{ $related := site.RegularPages.Related . | first 5 }}
{{ with $related }}
<div class="article-widget">
@@ -30,11 +32,11 @@
{{ if site.Params.section_pager }}
<div class="article-widget">
{{ partial "section_pager.html" . }}
{{ partial "section_pager" . }}
</div>
{{ end }}
{{ partial "comments.html" . }}
{{ partial "comments" . }}
</div>
</article>
+6 -2
View File
@@ -1,5 +1,9 @@
{{ if and site.DisqusShortname (not (or site.Params.disable_comments .Params.disable_comments)) }}
{{ if site.Params.comments.engine | and (index site.Params.comments.commentable .Type) | and (ne .Params.commentable false) | or .Params.commentable }}
<section id="comments">
{{ template "_internal/disqus.html" . }}
{{ if eq site.Params.comments.engine 1 }}
{{ partial "comments/disqus.html" . }}
{{ else if eq site.Params.comments.engine 2 }}
{{ partial "comments/commento.html" . }}
{{ end }}
</section>
{{ end }}
+2
View File
@@ -0,0 +1,2 @@
<div id="commento"></div>
<script src="https://cdn.commento.io/js/commento.js" defer></script>
+22
View File
@@ -0,0 +1,22 @@
{{ if site.Params.comments.disqus.shortname }}
<div id="disqus_thread"></div>
<script>
let disqus_config = function () {
{{with .Params.disqus_identifier }}this.page.identifier = '{{ . }}';{{end}}
{{with .Params.disqus_title }}this.page.title = '{{ . }}';{{end}}
{{with .Params.disqus_url }}this.page.url = '{{ . | html }}';{{end}}
};
(function() {
if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
document.getElementById('disqus_thread').innerHTML = 'Disqus comments not available by default when the website is previewed locally.';
return;
}
var d = document, s = d.createElement('script'); s.async = true;
s.src = 'https://' + {{site.Params.comments.disqus.shortname}} + '.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</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>
{{end}}
+3 -7
View File
@@ -41,13 +41,9 @@
<div class="body-footer">
<p>{{ i18n "last_updated" }} {{ $.Lastmod.Format site.Params.date_format }}</p>
{{ if site.Params.edit_page.repo_url | and site.Params.edit_page.editable.docs | and (ne .Params.editable false) | or .Params.editable }}
<p class="edit-page">
<a href="{{site.Params.edit_page.repo_url}}/blob/master/content/{{.File.Path}}">
<i class="fas fa-pen pr-2"></i>{{ i18n "edit_page" | default "Edit this page" }}
</a>
</p>
{{ end }}
{{ partial "edit_page" . }}
{{ partial "comments" . }}
</div>
</article>
+7
View File
@@ -0,0 +1,7 @@
{{ if site.Params.edit_page.repo_url | and (index site.Params.edit_page.editable .Type) | and (ne .Params.editable false) | or .Params.editable }}
<p class="edit-page">
<a href="{{site.Params.edit_page.repo_url}}/blob/master/content/{{.File.Path}}">
<i class="fas fa-pen pr-2"></i>{{ i18n "edit_page" | default "Edit this page" }}
</a>
</p>
{{ end }}
+4 -2
View File
@@ -49,10 +49,12 @@
</span>
{{ end }}
{{ $comments_enabled := and site.DisqusShortname (in (slice "post" "page") $page.Type) (not (or site.Params.disable_comments (eq $page.Params.comments false))) }}
{{ if and $comments_enabled (site.Params.comment_count | default true) }}
{{/* Show Disqus comment count if enabled. */}}
{{ $disqus_enabled := eq site.Params.comments.engine 1 | and (index site.Params.comments.commentable $page.Type) | and (ne $page.Params.commentable false) | or $page.Params.commentable }}
{{ if and $disqus_enabled (site.Params.comments.disqus.show_count | default true) }}
<span class="middot-divider"></span>
<a href="{{ $page.RelPermalink }}#disqus_thread"><!-- Count will be inserted here --></a>
<script id="dsq-count-scr" src="https://{{site.Params.comments.disqus.shortname}}.disqus.com/count.js" async></script>
{{ end}}
{{ $taxonomy := "categories" }}
-6
View File
@@ -44,12 +44,6 @@
{{ printf "<script src=\"%s\" integrity=\"%s\" crossorigin=\"anonymous\"></script>" (printf $js.leaflet.url $js.leaflet.version) $js.leaflet.sri | safeHTML }}
{{ end }}
{{/* Comments JS. */}}
{{ $comments_enabled := and site.DisqusShortname (not (or site.Params.disable_comments $.Params.disable_comments)) }}
{{ if and $comments_enabled (site.Params.comment_count | default true) }}
<script id="dsq-count-scr" src="https://{{ site.DisqusShortname }}.disqus.com/count.js" async></script>
{{ end }}
{{/* Initialise code highlighting. */}}
{{ if $.Scratch.Get "highlight_enabled" }}
<script>hljs.initHighlightingOnLoad();</script>