diff --git a/_config.yml b/_config.yml index e6f096e..0569c4d 100644 --- a/_config.yml +++ b/_config.yml @@ -565,7 +565,7 @@ comments: # Available values: tabs | buttons style: tabs # Choose a comment system to be displayed by default. - # Available values: disqus | disqusjs | changyan | livere | gitalk + # Available values: disqus | disqusjs | changyan | livere | gitalk | utterances active: # Setting `true` means remembering the comment system selected by the visitor. storage: true @@ -624,6 +624,15 @@ gitalk: # Available values: en | es-ES | fr | ru | zh-CN | zh-TW language: +# Utterances +# For more information: https://utteranc.es +utterances: + enable: false + repo: # Github repository name + # Available values: pathname | url | title | og:title + issue_term: pathname + # Available values: github-light | github-dark | preferred-color-scheme | github-dark-orange | icy-dark | dark-blue | photon-dark | boxy-light + theme: github-light # --------------------------------------------------------------- # Post Widgets & Content Sharing Services diff --git a/layout/_third-party/comments/utterances.njk b/layout/_third-party/comments/utterances.njk new file mode 100644 index 0000000..85625af --- /dev/null +++ b/layout/_third-party/comments/utterances.njk @@ -0,0 +1,14 @@ +{%- if page.comments %} + +{%- endif %} diff --git a/scripts/filters/comment/changyan.js b/scripts/filters/comment/changyan.js index 792ef98..71e4251 100644 --- a/scripts/filters/comment/changyan.js +++ b/scripts/filters/comment/changyan.js @@ -7,8 +7,8 @@ const { iconText } = require('./common'); // Add comment hexo.extend.filter.register('theme_inject', injects => { - const theme = hexo.theme.config; - if (!theme.changyan.enable || !theme.changyan.appid || !theme.changyan.appkey) return; + const config = hexo.theme.config.changyan; + if (!config.enable || !config.appid || !config.appkey) return; injects.comment.raw('changyan', `
@@ -22,8 +22,8 @@ hexo.extend.filter.register('theme_inject', injects => { // Add post_meta hexo.extend.filter.register('theme_inject', injects => { - const theme = hexo.theme.config; - if (!theme.changyan.enable || !theme.changyan.appid || !theme.changyan.appkey) return; + const config = hexo.theme.config.changyan; + if (!config.enable || !config.appid || !config.appkey) return; injects.postMeta.raw('changyan', ` {% if post.comments %} diff --git a/scripts/filters/comment/disqus.js b/scripts/filters/comment/disqus.js index fa7771e..6621dae 100644 --- a/scripts/filters/comment/disqus.js +++ b/scripts/filters/comment/disqus.js @@ -7,8 +7,8 @@ const { iconText } = require('./common'); // Add comment hexo.extend.filter.register('theme_inject', injects => { - const theme = hexo.theme.config; - if (!theme.disqus.enable || !theme.disqus.shortname) return; + const config = hexo.theme.config.disqus; + if (!config.enable || !config.shortname) return; injects.comment.raw('disqus', `
@@ -24,8 +24,8 @@ hexo.extend.filter.register('theme_inject', injects => { // Add post_meta hexo.extend.filter.register('theme_inject', injects => { - const theme = hexo.theme.config; - if (!theme.disqus.enable || !theme.disqus.shortname || !theme.disqus.count) return; + const config = hexo.theme.config.disqus; + if (!config.enable || !config.shortname || !config.count) return; injects.postMeta.raw('disqus', ` {% if post.comments %} diff --git a/scripts/filters/comment/disqusjs.js b/scripts/filters/comment/disqusjs.js index 1590738..57daa4a 100644 --- a/scripts/filters/comment/disqusjs.js +++ b/scripts/filters/comment/disqusjs.js @@ -6,8 +6,8 @@ const path = require('path'); // Add comment hexo.extend.filter.register('theme_inject', injects => { - const theme = hexo.theme.config; - if (!theme.disqusjs.enable || !theme.disqusjs.shortname || !theme.disqusjs.apikey) return; + const config = hexo.theme.config.disqus; + if (!config.enable || !config.shortname || !config.apikey) return; injects.comment.raw('disqusjs', `
diff --git a/scripts/filters/comment/utterances.js b/scripts/filters/comment/utterances.js new file mode 100644 index 0000000..aac06f7 --- /dev/null +++ b/scripts/filters/comment/utterances.js @@ -0,0 +1,25 @@ +/* global hexo */ + +'use strict'; + +const path = require('path'); + +// Add comment +hexo.extend.filter.register('theme_inject', injects => { + const config = hexo.theme.config.utterances; + if (!config.enable) return; + + if (!config.repo) { + hexo.log.warn('utterances.repo can\'t be null.'); + return; + } + + injects.comment.raw('utterances', ` +
+
+
+ `, {}, { cache: true }); + + injects.bodyEnd.file('utterances', path.join(hexo.theme_dir, 'layout/_third-party/comments/utterances.njk')); + +}); diff --git a/source/css/_common/components/third-party/third-party.styl b/source/css/_common/components/third-party/third-party.styl index 324d9c5..e6d555e 100644 --- a/source/css/_common/components/third-party/third-party.styl +++ b/source/css/_common/components/third-party/third-party.styl @@ -1,5 +1,7 @@ @import 'gitalk' if (hexo-config('gitalk.enable')); +@import 'utterances' if (hexo-config('utterances.enable')); + @import 'search' if (hexo-config('local_search.enable') || hexo-config('algolia_search.enable')); @import 'related-posts' if (hexo-config('related_posts.enable')); diff --git a/source/css/_common/components/third-party/utterances.styl b/source/css/_common/components/third-party/utterances.styl new file mode 100644 index 0000000..997d39a --- /dev/null +++ b/source/css/_common/components/third-party/utterances.styl @@ -0,0 +1,3 @@ +.utterances { + max-width: unset; +}