diff --git a/_config.yml b/_config.yml index 4e3379a..3240e06 100755 --- a/_config.yml +++ b/_config.yml @@ -110,6 +110,23 @@ comments: issue-number: theme: preferred-color-scheme label: + # giscus + # https://giscus.app/zh-CN + giscus: + data-repo: xxx/xxx # [在此输入仓库] + data-repo-id: # [在此输入仓库 ID] + data-category: # [在此输入分类名] + data-category-id: + data-mapping: pathname + data-strict: 0 + data-reactions-enabled: 1 + data-emit-metadata: 0 + data-input-position: top # top, bottom + data-theme: preferred_color_scheme + data-lang: zh-CN + data-loading: lazy + crossorigin: anonymous + valine: js: https://fastly.jsdelivr.net/gh/XuxuGood/simple-blog-cdn@main/js/Valine.min.js appId: # your appId @@ -213,7 +230,7 @@ footer: # '更多': # - '[关于本站](/)' # - '[GitHub](/)' - license: '[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)' + license: # '[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)' source: #'[GitHub](https://github.com/xaoxuu/hexo-theme-stellar)' more: # string or array (support markdown) diff --git a/layout/_partial/plugins/comments/giscus/layout.ejs b/layout/_partial/plugins/comments/giscus/layout.ejs new file mode 100644 index 0000000..23af6b4 --- /dev/null +++ b/layout/_partial/plugins/comments/giscus/layout.ejs @@ -0,0 +1,39 @@ +<% +function layoutDiv() { + const cmt = 'giscus'; + // 合并配置参数 + var config = Object.assign({}, theme.comments[cmt]); + if (page.layout === 'wiki' && page.wiki) { + let proj = theme.wiki.projects[page.wiki]; + if (proj[cmt] != undefined) { + Object.assign(config, proj[cmt]); + } + } + Object.assign(config, page[cmt]); + // 合并评论数据 + if (page.comment_id != undefined) { + config['data-mapping'] = 'specific'; + config['data-term'] = page.comment_id; + } else if (page.layout === 'wiki' && page.wiki) { + let proj = theme.wiki.projects[page.wiki]; + if (proj.comment_id != undefined) { + config['data-mapping'] = 'specific'; + config['data-term'] = proj.comment_id; + } + } + // 布局 + var el = ''; + el += '
+ + + +<%- layoutDiv() %> diff --git a/layout/_partial/plugins/comments/giscus/script.ejs b/layout/_partial/plugins/comments/giscus/script.ejs new file mode 100644 index 0000000..3a9aa72 --- /dev/null +++ b/layout/_partial/plugins/comments/giscus/script.ejs @@ -0,0 +1,26 @@ + diff --git a/layout/_partial/plugins/comments/layout.ejs b/layout/_partial/plugins/comments/layout.ejs index 1ae3911..25c6b63 100644 --- a/layout/_partial/plugins/comments/layout.ejs +++ b/layout/_partial/plugins/comments/layout.ejs @@ -9,7 +9,7 @@ if (theme.comments.service && theme.comments.service.length > 0) { if (loadComment && page.layout == 'wiki' && page.wiki) { let proj = theme.wiki.projects[page.wiki]; if (proj.comment_title != undefined && page.comment_title == undefined) { - if (['utterances', 'beaudar'].includes(theme.comments.service)) { + if (['utterances', 'beaudar', 'giscus'].includes(theme.comments.service)) { page.comment_title = proj.comment_title; } }