add giscus
This commit is contained in:
parent
d3e37b310d
commit
d5889c5c57
19
_config.yml
19
_config.yml
|
@ -110,6 +110,23 @@ comments:
|
||||||
issue-number:
|
issue-number:
|
||||||
theme: preferred-color-scheme
|
theme: preferred-color-scheme
|
||||||
label:
|
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:
|
valine:
|
||||||
js: https://fastly.jsdelivr.net/gh/XuxuGood/simple-blog-cdn@main/js/Valine.min.js
|
js: https://fastly.jsdelivr.net/gh/XuxuGood/simple-blog-cdn@main/js/Valine.min.js
|
||||||
appId: # your appId
|
appId: # your appId
|
||||||
|
@ -213,7 +230,7 @@ footer:
|
||||||
# '更多':
|
# '更多':
|
||||||
# - '[关于本站](/)'
|
# - '[关于本站](/)'
|
||||||
# - '[GitHub](/)'
|
# - '[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)'
|
source: #'[GitHub](https://github.com/xaoxuu/hexo-theme-stellar)'
|
||||||
more: # string or array (support markdown)
|
more: # string or array (support markdown)
|
||||||
|
|
||||||
|
|
|
@ -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 += '<div id="' + cmt + '"';
|
||||||
|
for (let key of Object.keys(config)) {
|
||||||
|
if (config[key] !== null) {
|
||||||
|
el += ' ' + key + '="' + config[key] + '"';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
el += '></div>';
|
||||||
|
return el;
|
||||||
|
}
|
||||||
|
%>
|
||||||
|
|
||||||
|
<svg class="loading" style="vertical-align: middle;fill: currentColor;overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2709"><path d="M832 512c0-176-144-320-320-320V128c211.2 0 384 172.8 384 384h-64zM192 512c0 176 144 320 320 320v64C300.8 896 128 723.2 128 512h64z" p-id="2710"></path></svg>
|
||||||
|
|
||||||
|
<%- layoutDiv() %>
|
|
@ -0,0 +1,26 @@
|
||||||
|
<script>
|
||||||
|
function loadJS() {
|
||||||
|
const els = document.querySelectorAll("#comments #giscus");
|
||||||
|
if (els.length === 0) return;
|
||||||
|
els.forEach((el, i) => {
|
||||||
|
try {
|
||||||
|
el.innerHTML = '';
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
var script = document.createElement('script');
|
||||||
|
script.src = 'https://giscus.app/client.js';
|
||||||
|
script.async = true;
|
||||||
|
for (let key of Object.keys(el.attributes)) {
|
||||||
|
let attr = el.attributes[key];
|
||||||
|
if (['class', 'id'].includes(attr.name) === false) {
|
||||||
|
script.setAttribute(attr.name, attr.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
el.appendChild(script);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
window.addEventListener('DOMContentLoaded', (event) => {
|
||||||
|
loadJS();
|
||||||
|
});
|
||||||
|
</script>
|
|
@ -9,7 +9,7 @@ if (theme.comments.service && theme.comments.service.length > 0) {
|
||||||
if (loadComment && page.layout == 'wiki' && page.wiki) {
|
if (loadComment && page.layout == 'wiki' && page.wiki) {
|
||||||
let proj = theme.wiki.projects[page.wiki];
|
let proj = theme.wiki.projects[page.wiki];
|
||||||
if (proj.comment_title != undefined && page.comment_title == undefined) {
|
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;
|
page.comment_title = proj.comment_title;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue