适配 beaudar 评论插件
This commit is contained in:
parent
c364229281
commit
180cbaeb70
16
_config.yml
16
_config.yml
|
@ -68,16 +68,24 @@ article:
|
|||
|
||||
######## Comments ########
|
||||
comments:
|
||||
service: # utterances, valine
|
||||
service: # beaudar, utterances, valine, twikoo
|
||||
# beaudar
|
||||
# https://beaudar.lipk.org/
|
||||
beaudar:
|
||||
repo: xxx/xxx
|
||||
issue-term: pathname
|
||||
issue-number:
|
||||
theme: preferred-color-scheme
|
||||
input-position: top # top/bottom 评论框位置
|
||||
comment-order: desc # desc 排序
|
||||
keep-theme: # true/false
|
||||
# utterances
|
||||
# https://utteranc.es/
|
||||
utterances:
|
||||
repo: xxx/xxx
|
||||
issue-term: pathname
|
||||
issue-number:
|
||||
theme:
|
||||
light: github-light
|
||||
dark: github-dark
|
||||
theme: preferred-color-scheme
|
||||
valine:
|
||||
js: https://cdn.jsdelivr.net/gh/XuxuGood/simple-blog-cdn@main/js/Valine.min.js
|
||||
appId: # your appId
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
<%
|
||||
function layoutDiv() {
|
||||
const cmt = 'beaudar';
|
||||
// 合并配置参数
|
||||
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 (config['issue-number'] !== null) {
|
||||
config['issue-term'] = null;
|
||||
} else {
|
||||
if (page.comment_id !== undefined) {
|
||||
config['issue-term'] = page.comment_id;
|
||||
} else if (page.layout === 'wiki' && page.wiki) {
|
||||
let proj = theme.wiki.projects[page.wiki];
|
||||
if (proj.comment_id !== undefined) {
|
||||
config['issue-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,25 @@
|
|||
<script>
|
||||
function beaudar(){
|
||||
if(!document.getElementById("beaudar"))return;
|
||||
setTimeout(function() {
|
||||
var checkbeaudar = setInterval(function () {
|
||||
var el = document.getElementById("beaudar");
|
||||
if (!el) return
|
||||
clearInterval(checkbeaudar)
|
||||
try {
|
||||
el.innerHTML="";
|
||||
} catch (error) {}
|
||||
var script = document.createElement('script');
|
||||
script.src = 'https://beaudar.lipk.org/client.js';
|
||||
const keys = ['repo', 'issue-term', 'issue-number', 'theme', 'label', 'crossorigin', 'input-position', 'comment-order', 'keep-theme'];
|
||||
keys.forEach((key, i) => {
|
||||
if (el.attributes[key] && el.attributes[key].value) {
|
||||
script.setAttribute(key, el.attributes[key].value);
|
||||
}
|
||||
});
|
||||
el.appendChild(script);
|
||||
}, 200)
|
||||
});
|
||||
}
|
||||
beaudar();
|
||||
</script>
|
|
@ -8,13 +8,8 @@ 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_id !== undefined && page.comment_id === undefined) {
|
||||
if (theme.comments.service === 'utterances') {
|
||||
page.comment_id = proj.comment_id;
|
||||
}
|
||||
}
|
||||
if (proj.comment_title !== undefined && page.comment_title === undefined) {
|
||||
if (theme.comments.service === 'utterances') {
|
||||
if (['utterances', 'beaudar'].includes(theme.comments.service)) {
|
||||
page.comment_title = proj.comment_title;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,22 +1,34 @@
|
|||
<%
|
||||
function layoutDiv() {
|
||||
const cmt = 'utterances';
|
||||
// 合并配置参数
|
||||
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 (config['issue-number'] !== null) {
|
||||
config['issue-term'] = null;
|
||||
} else {
|
||||
if (page.comment_id !== undefined) {
|
||||
config['issue-term'] = page.comment_id;
|
||||
} else if (page.layout === 'wiki' && page.wiki) {
|
||||
let proj = theme.wiki.projects[page.wiki];
|
||||
if (proj.comment_id !== undefined) {
|
||||
config['issue-term'] = proj.comment_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 布局
|
||||
var el = '';
|
||||
el += '<div id="utterances"';
|
||||
let utterances = Object.assign({}, theme.comments.utterances, page.utterances);
|
||||
if (page.comment_id) {
|
||||
utterances['issue-term'] = page.comment_id;
|
||||
}
|
||||
if (page.dark && utterances.theme.dark) {
|
||||
utterances.theme = utterances.theme.dark;
|
||||
} else if (utterances.theme.light) {
|
||||
utterances.theme = utterances.theme.light;
|
||||
}
|
||||
if (utterances['issue-number']) {
|
||||
utterances['issue-term'] = null;
|
||||
}
|
||||
for (let key of Object.keys(utterances)) {
|
||||
if (utterances[key]) {
|
||||
el += ' ' + key + '="' + utterances[key] + '"';
|
||||
el += '<div id="' + cmt + '"';
|
||||
for (let key of Object.keys(config)) {
|
||||
if (config[key] !== null) {
|
||||
el += ' ' + key + '="' + config[key] + '"';
|
||||
}
|
||||
}
|
||||
el += '></div>';
|
||||
|
|
Loading…
Reference in New Issue