control comment system in partials/comments.html

This commit is contained in:
Reorx 2022-05-27 21:33:40 +08:00
parent 9f8b0c3194
commit 28511efd08
8 changed files with 53 additions and 8 deletions

View File

@ -46,7 +46,7 @@
</footer>
{{- if not (.Param "noComments") }}
{{- partial "comments.html" . }}
{{- partial "comments.html" . }}
{{- end }}
</article>

View File

@ -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 -}}

View File

@ -1,3 +0,0 @@
{{- /* Comments js area start */ -}}
{{- /* to add comments read => https://gohugo.io/content-management/comments/ */ -}}
{{- /* Comments js area end */ -}}

View File

@ -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 -}}

View File

@ -0,0 +1,3 @@
<div class="disqus-container">
<div id="disqus_thread"></div>
</div>

View File

@ -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>

View File

@ -126,5 +126,5 @@
{{- end }}
{{- if not (.Param "noComments") }}
{{- partial "comments_js.html" . }}
{{- partial "comments_script.html" . }}
{{ end }}

View File

@ -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 }}