support specifying comment system in both config and front matter
in config: site.Params.defaultCommentSystems in front matter: pageCommentSystems
This commit is contained in:
parent
81f885a7b9
commit
5c47607d23
|
@ -1,13 +1,27 @@
|
|||
{{- /* You can add your own layouts/comments.html to override this file */ -}}
|
||||
|
||||
{{- with site.Params.commentSystem.remark42 -}}
|
||||
{{- partial "remark42.html" . }}
|
||||
{{- end -}}
|
||||
{{- $pageCommentSystems := .Param "pageCommentSystems"}}
|
||||
{{- if not $pageCommentSystems }}
|
||||
{{- $pageCommentSystems = site.Params.defaultCommentSystems }}
|
||||
{{- end }}
|
||||
|
||||
{{- with site.Params.commentSystem.telegramWidget -}}
|
||||
{{- partial "telegram_widget.html" . }}
|
||||
{{- end -}}
|
||||
{{- $page := . -}}
|
||||
{{- with site.Params.commentSystems -}}
|
||||
{{- if $pageCommentSystems.remark42 -}}
|
||||
{{- with .remark42 -}}
|
||||
{{- partial "remark42.html" . }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- with site.Params.commentSystem.disqus -}}
|
||||
{{- partial "disqus.html" . }}
|
||||
{{- if $pageCommentSystems.telegramWidget -}}
|
||||
{{- with .telegramWidget -}}
|
||||
{{- partial "telegram_widget.html" . }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $pageCommentSystems.disqus -}}
|
||||
{{- with .disqus -}}
|
||||
{{- partial "disqus.html" (dict "page" $page "disqus" .) }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
|
|
@ -1,3 +1,30 @@
|
|||
<div class="disqus-container">
|
||||
<div id="disqus_thread"></div>
|
||||
</div>
|
||||
|
||||
<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 () {
|
||||
const disqus = window.DISQUS
|
||||
if (disqus) {
|
||||
// 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 = '//' + '{{ .disqus.shortname }}' + '.disqus.com/embed.js';
|
||||
s.defer = true;
|
||||
s.setAttribute('data-timestamp', +new Date());
|
||||
// prevent the <script> from loading mutiple times by InstantClick
|
||||
s.setAttribute('data-no-instant', '')
|
||||
d.head.appendChild(s);
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
<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>
|
|
@ -1,4 +1,3 @@
|
|||
{{- with site.Params.commentSystem.telegramWidget }}
|
||||
<div class="telegram-widget-container"></div>
|
||||
|
||||
<script>
|
||||
|
@ -34,6 +33,9 @@
|
|||
if (!toggleThemeCallbacks) {
|
||||
return;
|
||||
}
|
||||
if (document.getElementsByClassName('telegram-widget-container').length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
toggleThemeCallbacks.push((isDark) => {
|
||||
// console.log('window toggle-theme for telegram widget')
|
||||
|
@ -48,4 +50,3 @@
|
|||
});
|
||||
})();
|
||||
</script>
|
||||
{{- end }}
|
||||
|
|
Loading…
Reference in New Issue