- const { use, lazyload } = theme.comments - const { repo, repo_id, category_id, light_theme, dark_theme, js, option } = theme.giscus - const giscusUrl = js || 'https://giscus.app/client.js' - const giscusOriginUrl = new URL(giscusUrl).origin script. (()=>{ const getGiscusTheme = theme => theme === 'dark' ? '!{dark_theme}' : '!{light_theme}' const loadGiscus = () => { const config = Object.assign({ src: '!{giscusUrl}', 'data-repo': '!{repo}', 'data-repo-id': '!{repo_id}', 'data-category-id': '!{category_id}', 'data-mapping': 'pathname', 'data-theme': getGiscusTheme(document.documentElement.getAttribute('data-theme')), 'data-reactions-enabled': '1', crossorigin: 'anonymous', async: true },!{JSON.stringify(option)}) const ele = document.createElement('script') for (let key in config) { ele.setAttribute(key, config[key]) } document.getElementById('giscus-wrap').appendChild(ele) } const changeGiscusTheme = theme => { const iframe = document.querySelector('#giscus-wrap iframe') if (iframe) { const message = { giscus: { setConfig: { theme: getGiscusTheme(theme) } } } iframe.contentWindow.postMessage(message, '!{giscusOriginUrl}') } } btf.addGlobalFn('themeChange', changeGiscusTheme, 'giscus') if ('!{use[0]}' === 'Giscus' || !!{lazyload}) { if (!{lazyload}) btf.loadComment(document.getElementById('giscus-wrap'), loadGiscus) else loadGiscus() } else { window.loadOtherComment= loadGiscus } })()