summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReorx <novoreorx@gmail.com>2022-05-27 21:33:40 +0800
committerReorx <novoreorx@gmail.com>2022-05-27 21:33:40 +0800
commit28511efd081dba9dac8cbf8fa2c8135216264243 (patch)
tree6fe8e74f91dbc1ae25d848d552cc0e3357d3b53d
parent9f8b0c319412a75f703d98e9a36cc91e8d7ccdda (diff)
control comment system in partials/comments.html
-rw-r--r--layouts/_default/single.html2
-rw-r--r--layouts/partials/comments.html12
-rw-r--r--layouts/partials/comments_js.html3
-rw-r--r--layouts/partials/comments_script.html5
-rw-r--r--layouts/partials/disqus.html3
-rw-r--r--layouts/partials/disqus_script.html27
-rw-r--r--layouts/partials/page_footer.html2
-rw-r--r--layouts/partials/telegram_widget.html7
8 files changed, 53 insertions, 8 deletions
diff --git a/layouts/_default/single.html b/layouts/_default/single.html
index 9b0a398..c71f66d 100644
--- a/layouts/_default/single.html
+++ b/layouts/_default/single.html
@@ -46,7 +46,7 @@
</footer>
{{- if not (.Param "noComments") }}
- {{- partial "comments.html" . }}
+ {{- partial "comments.html" . }}
{{- end }}
</article>
diff --git a/layouts/partials/comments.html b/layouts/partials/comments.html
index 918451a..a07744a 100644
--- a/layouts/partials/comments.html
+++ b/layouts/partials/comments.html
@@ -1,3 +1,9 @@
-{{- /* Comments area start */ -}}
-{{- /* to add comments read => https://gohugo.io/content-management/comments/ */ -}}
-{{- /* Comments area end */ -}}
+{{- /* You can add your own layouts/comments.html to override this file */ -}}
+
+{{- with site.Params.commentSystem.disqus -}}
+ {{- partial "disqus.html" . }}
+{{- end -}}
+
+{{- with site.Params.commentSystem.telegramWidget -}}
+ {{- partial "telegram_widget.html" . }}
+{{- end -}}
diff --git a/layouts/partials/comments_js.html b/layouts/partials/comments_js.html
deleted file mode 100644
index cca3404..0000000
--- a/layouts/partials/comments_js.html
+++ /dev/null
@@ -1,3 +0,0 @@
-{{- /* Comments js area start */ -}}
-{{- /* to add comments read => https://gohugo.io/content-management/comments/ */ -}}
-{{- /* Comments js area end */ -}}
diff --git a/layouts/partials/comments_script.html b/layouts/partials/comments_script.html
new file mode 100644
index 0000000..8663497
--- /dev/null
+++ b/layouts/partials/comments_script.html
@@ -0,0 +1,5 @@
+{{- /* You can add your own layouts/comments_script.html to override this file */ -}}
+
+{{- with site.Params.commentSystem.disqus -}}
+ {{ partial "disqus_script.html" . }}
+{{- end -}}
diff --git a/layouts/partials/disqus.html b/layouts/partials/disqus.html
new file mode 100644
index 0000000..dc86fc2
--- /dev/null
+++ b/layouts/partials/disqus.html
@@ -0,0 +1,3 @@
+<div class="disqus-container">
+ <div id="disqus_thread"></div>
+</div>
diff --git a/layouts/partials/disqus_script.html b/layouts/partials/disqus_script.html
new file mode 100644
index 0000000..4840d14
--- /dev/null
+++ b/layouts/partials/disqus_script.html
@@ -0,0 +1,27 @@
+<script type="text/javascript">
+ var disqus_config = function () {
+ this.page.url = '{{ .Page.Permalink }}'; // Replace PAGE_URL with your page's canonical URL variable
+ this.page.identifier = '{{ .Page.Permalink | path.Base }}'; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
+ };
+
+ (function () {
+ let disqusEmbedLoaded = window.disqusEmbedLoaded;
+ if (disqusEmbedLoaded) {
+ // Use DISQUS.reset instead of reloading embed.js please.
+ // https://help.disqus.com/en/articles/1717163-using-disqus-on-ajax-sites
+ DISQUS.reset({
+ reload: true,
+ config: disqus_config,
+ });
+ } else {
+ var d = document, s = d.createElement('script');
+ s.src = '//' + '{{ site.Params.commentSystem.disqus.shortname }}' + '.disqus.com/embed.js';
+ s.setAttribute('data-timestamp', +new Date());
+ // prevent the <script> from loading mutiple times by InstantClick
+ s.setAttribute('data-no-instant', '')
+ d.head.appendChild(s);
+
+ window.disqusEmbedLoaded = true;
+ }
+ })();
+</script>
diff --git a/layouts/partials/page_footer.html b/layouts/partials/page_footer.html
index 589292b..2d0dd2a 100644
--- a/layouts/partials/page_footer.html
+++ b/layouts/partials/page_footer.html
@@ -126,5 +126,5 @@
{{- end }}
{{- if not (.Param "noComments") }}
- {{- partial "comments_js.html" . }}
+ {{- partial "comments_script.html" . }}
{{ end }}
diff --git a/layouts/partials/telegram_widget.html b/layouts/partials/telegram_widget.html
new file mode 100644
index 0000000..84db442
--- /dev/null
+++ b/layouts/partials/telegram_widget.html
@@ -0,0 +1,7 @@
+{{- with site.Params.commentSystem.telegramWidget }}
+<script async
+ src="https://telegram.org/js/telegram-widget.js?19"
+ data-telegram-discussion="{{ .channel }}"
+ data-comments-limit="{{ .limit | default 10 }}"
+ {{ with .accentColor }}data-color="{{ . }}"{{ end }}></script>
+{{- end }}