diff --git a/_config.yml b/_config.yml index 5a2335e9ae0a826099bf9c9f87524d74c4d71d58..59a263748217087fbcd2a4a2717f6459c5714b03 100644 --- a/_config.yml +++ b/_config.yml @@ -444,6 +444,28 @@ disqus: shortname: count: true +# Utterances +# See: https://utteranc.es/ +utterances: + enable: false + # Github username. + owner: + # Github repository. + repo: + # Choose the mapping between blog posts and GitHub issues. + # Available values: pathname | url | title | og:title + mapping: pathname + # Choose the label that will be assigned to issues created by Utterances. + # Emoji are supported in label names. + label: utterances + # Choose an Utterances theme that matches your blog. + # Available values: github-light | github-dark | github-dark-orange | icy-dark | dark-blue | photon-dark + theme: github-light + # ! ------------------------------------------------------------------------------- + # ! Don't set this unless the URL of the script in the official website is changed. + # ! ------------------------------------------------------------------------------- + script_url: https://utteranc.es/client.js + # --------------------------------------------------------------- # Statistics and Analytics config # --------------------------------------------------------------- diff --git a/layout/_partials/widgets/comments.pug b/layout/_partials/widgets/comments.pug index b61d2f40678ee5b3a5c16fda1acd12435577ede9..fbb74d11952132ac18c6d6e5aa798ee0fae28f8f 100644 --- a/layout/_partials/widgets/comments.pug +++ b/layout/_partials/widgets/comments.pug @@ -7,6 +7,9 @@ else if theme.valine && theme.valine.enable else if theme.gitalk && theme.gitalk.enable div#comments.comments div#gitalk-container +else if theme.utterances && theme.utterances.enable + div#comments.comments + div#utterances-container else if theme.livere && theme.livere.enable div#comments.comments div#lv-container(data-id="city" data-uid=theme.livere.uid) diff --git a/layout/_third-party/comments/index.pug b/layout/_third-party/comments/index.pug index f1ed00425150cc4de40486da3e9a049c822c2f80..ff03488f6a35d100dc38612dd5f16b1b17cb052e 100644 --- a/layout/_third-party/comments/index.pug +++ b/layout/_third-party/comments/index.pug @@ -5,6 +5,8 @@ if page.comments || theme.pjax.enable include ./valine.pug else if theme.gitalk && theme.gitalk.enable include ./gitalk.pug + else if theme.utterances && theme.utterances.enable + include ./utterances.pug else if theme.livere && theme.livere.enable include ./livere.pug else if theme.valine && theme.valine.enable && theme.valine.visitor diff --git a/layout/_third-party/comments/utterances.pug b/layout/_third-party/comments/utterances.pug new file mode 100644 index 0000000000000000000000000000000000000000..c3ceee3dd5a6d2294f10ed17fb1e2ce744007f3d --- /dev/null +++ b/layout/_third-party/comments/utterances.pug @@ -0,0 +1,25 @@ +script&attributes(dataPjax). + function loadUtterances() { + var d = document, s = d.createElement('script'); + var container = d.getElementById('utterances-container'); + + if (!container) return; + + s.src = '!{ theme.utterances.script_url }'; + s.setAttribute('repo', '!{ theme.utterances.owner }/!{ theme.utterances.repo }'); + s.setAttribute('issue-term', '!{ theme.utterances.mapping }'); + s.setAttribute('label', '!{ theme.utterances.label }'); + s.setAttribute('theme', '!{ theme.utterances.theme }'); + s.setAttribute('crossorigin', 'anonymous'); + s.setAttribute('async', ''); + + if (!{ pjax }) { s.setAttribute('data-pjax-rm', ''); } + + container.append(s); + } + + if (!{ pjax }) { + loadUtterances(); + } else { + window.addEventListener('DOMContentLoaded', loadUtterances, false); + } diff --git a/source/css/_common/components/widgets/comments.styl b/source/css/_common/components/widgets/comments.styl index 717181455902f860578ff963c84479e6a3c9c42b..6079c0f220c9370205379d2707549594ad7a5706 100644 --- a/source/css/_common/components/widgets/comments.styl +++ b/source/css/_common/components/widgets/comments.styl @@ -1,4 +1,4 @@ -if (hexo-config('gitalk.enable') || hexo-config('valine.enable') || hexo-config('livere.enable') || hexo-config('disqus.enable')) { +if (hexo-config('gitalk.enable') || hexo-config('valine.enable') || hexo-config('livere.enable') || hexo-config('disqus.enable') || hexo-config('utterances.enable')) { .comments { margin: 1.5rem 0 0; width: 100%;