hexo-theme-butterfly/layout/includes/third-party/comments/giscus.pug
Jerry ab6672429f breaking changes: cdn 可一鍵設置 本地文件/可單獨配置主題文件,第三方文件的 cdn
breaking changes: 移除 utterances,giscus, addtoany, busuanzi 的 cdn 配置
2022-02-19 00:43:01 +08:00

50 lines
1.5 KiB
Plaintext

- const { repo, repo_id, category_id, option } = theme.giscus
- const themes = theme.giscus.theme
script.
function loadGiscus () {
let nowTheme = document.documentElement.getAttribute('data-theme') === 'dark' ? '!{themes.dark}' : '!{themes.light}'
const config = Object.assign({
src: 'https://giscus.app/client.js',
'data-repo': '!{repo}',
'data-repo-id': '!{repo_id}',
'data-category-id': '!{category_id}',
'data-mapping': 'pathname',
'data-theme': nowTheme,
'data-reactions-enabled': '1',
crossorigin: 'anonymous',
async: true
},!{JSON.stringify(option)})
let ele = document.createElement('script')
for (let key in config) {
ele.setAttribute(key, config[key])
}
document.getElementById('giscus-wrap').insertAdjacentElement('afterbegin',ele)
}
function changeGiscusTheme () {
const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? '!{themes.dark}' : '!{themes.light}'
function sendMessage(message) {
const iframe = document.querySelector('iframe.giscus-frame');
if (!iframe) return;
iframe.contentWindow.postMessage({ giscus: message }, 'https://giscus.app');
}
sendMessage({
setConfig: {
theme: theme
}
});
}
if ('!{theme.comments.use[0]}' === 'Giscus' || !!{theme.comments.lazyload}) {
if (!{theme.comments.lazyload}) btf.loadComment(document.getElementById('giscus-wrap'), loadGiscus)
else loadGiscus()
} else {
function loadOtherComment () {
loadGiscus()
}
}