add theme

This commit is contained in:
2025-08-12 12:19:25 +08:00
parent 8c06923a46
commit ac0d1944ab
227 changed files with 18962 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
- const { server, site, option } = theme.artalk
- const { use, lazyload } = theme.comments
script.
(() => {
let artalkItem = null
const option = !{JSON.stringify(option)}
const isShuoshuo = GLOBAL_CONFIG_SITE.pageType === 'shuoshuo'
const destroyArtalk = () => {
if (artalkItem) {
artalkItem.destroy()
artalkItem = null
}
}
const artalkChangeMode = theme => artalkItem && artalkItem.setDarkMode(theme === 'dark')
const initArtalk = (el = document, pageKey = location.pathname) => {
artalkItem = Artalk.init({
el: el.querySelector('#artalk-wrap'),
server: '!{server}',
site: '!{site}',
darkMode: document.documentElement.getAttribute('data-theme') === 'dark',
...option,
pageKey: isShuoshuo ? pageKey : (option && option.pageKey) || pageKey
})
if (GLOBAL_CONFIG.lightbox === 'null') return
artalkItem.on('list-loaded', () => {
artalkItem.ctx.get('list').getCommentNodes().forEach(comment => {
const $content = comment.getRender().$content
btf.loadLightbox($content.querySelectorAll('img:not([atk-emoticon])'))
})
})
if (isShuoshuo) {
window.shuoshuoComment.destroyArtalk = () => {
destroyArtalk()
if (el.children.length) {
el.innerHTML = ''
el.classList.add('no-comment')
}
}
}
btf.addGlobalFn('pjaxSendOnce', destroyArtalk, 'destroyArtalk')
btf.addGlobalFn('themeChange', artalkChangeMode, 'artalk')
}
const loadArtalk = async (el, pageKey) => {
if (typeof Artalk === 'object') initArtalk(el, pageKey)
else {
await btf.getCSS('!{theme.asset.artalk_css}')
await btf.getScript('!{theme.asset.artalk_js}')
initArtalk(el, pageKey)
}
}
if (isShuoshuo) {
'!{use[0]}' === 'Artalk'
? window.shuoshuoComment = { loadComment: loadArtalk }
: window.loadOtherComment = loadArtalk
return
}
if ('!{use[0]}' === 'Artalk' || !!{lazyload}) {
if (!{lazyload}) btf.loadComment(document.getElementById('artalk-wrap'), loadArtalk)
else setTimeout(loadArtalk, 100)
} else {
window.loadOtherComment = loadArtalk
}
})()

View File

@@ -0,0 +1,80 @@
- const disqusPageTitle = page.title.replace(/'/ig,"\\'")
- const { shortname, apikey } = theme.disqus
- const { use, lazyload, count } = theme.comments
script.
(() => {
const isShuoshuo = GLOBAL_CONFIG_SITE.pageType === 'shuoshuo'
const disqusReset = conf => {
window.DISQUS && window.DISQUS.reset({
reload: true,
config: conf
})
}
const loadDisqus = (el, path) => {
if (isShuoshuo) {
window.shuoshuoComment.destroyDisqus = () => {
if (el.children.length) {
el.innerHTML = ''
el.classList.add('no-comment')
}
}
}
window.disqus_identifier = isShuoshuo ? path : '!{ url_for(page.path) }'
window.disqus_url = isShuoshuo ? location.origin + path : '!{ page.permalink }'
const disqus_config = function () {
this.page.url = disqus_url
this.page.identifier = disqus_identifier
this.page.title = '!{ disqusPageTitle }'
}
if (window.DISQUS) disqusReset(disqus_config)
else {
const script = document.createElement('script')
script.src = 'https://!{shortname}.disqus.com/embed.js'
script.setAttribute('data-timestamp', +new Date())
document.head.appendChild(script)
}
btf.addGlobalFn('themeChange', () => disqusReset(disqus_config), 'disqus')
}
const getCount = async() => {
try {
const eleGroup = document.querySelector('#post-meta .disqus-comment-count')
if (!eleGroup) return
const cleanedLinks = eleGroup.href.replace(/#post-comment$/, '')
const res = await fetch(`https://disqus.com/api/3.0/threads/set.json?forum=!{shortname}&api_key=!{apikey}&thread:link=${cleanedLinks}`,{
method: 'GET'
})
const result = await res.json()
const count = result.response.length ? result.response[0].posts : 0
eleGroup.textContent = count
} catch (err) {
console.error(err)
}
}
if (isShuoshuo) {
'!{use[0]}' === 'Disqus'
? window.shuoshuoComment = { loadComment: loadDisqus }
: window.loadOtherComment = loadDisqus
return
}
if ('!{use[0]}' === 'Disqus' || !!{lazyload}) {
if (!{lazyload}) btf.loadComment(document.getElementById('disqus_thread'), loadDisqus)
else {
loadDisqus()
!{ count ? `GLOBAL_CONFIG_SITE.pageType === 'post' && getCount()` : '' }
}
} else {
window.loadOtherComment = loadDisqus
}
})()

View File

@@ -0,0 +1,87 @@
- let disqusjsPageTitle = page.title && page.title.replace(/'/ig,"\\'")
- const { shortname:dqShortname, apikey:dqApikey, option:dqOption } = theme.disqusjs
script.
(() => {
const isShuoshuo = GLOBAL_CONFIG_SITE.pageType === 'shuoshuo'== 'shuoshuo'
const dqOption = !{JSON.stringify(dqOption)}
const destroyDisqusjs = () => {
disqusjs.destroy()
window.disqusjs = null
}
const themeChange = (el, path) => {
destroyDisqusjs()
initDisqusjs(el, path)
}
const initDisqusjs = (el = document, path) => {
if (isShuoshuo) {
window.shuoshuoComment.destroyDisqusjs = () => {
destroyDisqusjs()
if (el.children.length) {
el.innerHTML = ''
el.classList.add('no-comment')
}
}
}
disqusjs = new DisqusJS({
shortname: '!{dqShortname}',
title: '!{ disqusjsPageTitle }',
apikey: '!{dqApikey}',
...dqOption,
identifier: isShuoshuo ? path : (dqOption && dqOption.identifier) || '!{ url_for(page.path) }',
url: isShuoshuo ? location.origin + path : (dqOption && dqOption.url) || '!{ page.permalink }'
})
disqusjs.render(el.querySelector('#disqusjs-wrap'))
btf.addGlobalFn('themeChange', () => themeChange(el, path), 'disqusjs')
}
const loadDisqusjs = async(el, path) => {
if (window.disqusJsLoad) initDisqusjs(el, path)
else {
await btf.getCSS('!{url_for(theme.asset.disqusjs_css)}')
await btf.getScript('!{url_for(theme.asset.disqusjs)}')
initDisqusjs(el, path)
window.disqusJsLoad = true
}
}
const getCount = async() => {
try {
const eleGroup = document.querySelector('#post-meta .disqusjs-comment-count')
if (!eleGroup) return
const cleanedLinks = eleGroup.href.replace(/#post-comment$/, '')
const res = await fetch(`https://disqus.com/api/3.0/threads/set.json?forum=!{dqShortname}&api_key=!{dqApikey}&thread:link=${cleanedLinks}`,{
method: 'GET'
})
const result = await res.json()
const count = result.response.length ? result.response[0].posts : 0
eleGroup.textContent = count
} catch (err) {
console.error(err)
}
}
if (isShuoshuo) {
'!{theme.comments.use[0]}' === 'Disqusjs'
? window.shuoshuoComment = { loadComment: loadDisqusjs }
: window.loadOtherComment = loadDisqusjs
return
}
if ('!{theme.comments.use[0]}' === 'Disqusjs' || !!{theme.comments.lazyload}) {
if (!{theme.comments.lazyload}) btf.loadComment(document.getElementById('disqusjs-wrap'), loadDisqusjs)
else {
loadDisqusjs()
!{ theme.comments.count ? `GLOBAL_CONFIG_SITE.pageType === 'post' && getCount()` : '' }
}
} else {
window.loadOtherComment = loadDisqusjs
}
})()

View File

@@ -0,0 +1,64 @@
- const fbSDKVer = 'v20.0'
- const fbSDK = `https://connect.facebook.net/${theme.facebook_comments.lang}/sdk.js#xfbml=1&version=${fbSDKVer}`
script.
(()=>{
const isShuoshuo = GLOBAL_CONFIG_SITE.pageType === 'shuoshuo'== 'shuoshuo'
const loadFBComment = (el = document, path) => {
if (isShuoshuo) {
window.shuoshuoComment.destroyFB = () => {
if (el.children.length) {
el.innerHTML = ''
el.classList.add('no-comment')
}
}
}
document.getElementById('fb-root') ? '' : document.body.insertAdjacentHTML('afterend', '<div id="fb-root"></div>')
const themeNow = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'light'
const $fbComment = el.getElementsByClassName('fb-comments')[0]
$fbComment.setAttribute('data-colorscheme',themeNow)
$fbComment.setAttribute('data-href', isShuoshuo ? '!{urlNoIndex(page.permalink)}' + '#' + path : '!{urlNoIndex(page.permalink)}')
if (typeof FB === 'object') {
FB.XFBML.parse(document.getElementsByClassName('post-meta-commentcount')[0])
FB.XFBML.parse(el.querySelector('#post-comment'))
}
else {
let ele = document.createElement('script')
ele.setAttribute('src','!{fbSDK}')
ele.setAttribute('async', 'true')
ele.setAttribute('defer', 'true')
ele.setAttribute('crossorigin', 'anonymous')
ele.setAttribute('id', 'facebook-jssdk')
document.getElementById('fb-root').insertAdjacentElement('afterbegin',ele)
}
}
const fbModeChange = theme => {
const $fbComment = document.getElementsByClassName('fb-comments')[0]
if ($fbComment && typeof FB === 'object') {
$fbComment.setAttribute('data-colorscheme',theme)
FB.XFBML.parse(document.getElementById('post-comment'))
}
}
btf.addGlobalFn('themeChange', fbModeChange, 'facebook_comments')
if (isShuoshuo) {
'!{theme.comments.use[0]}' === 'Facebook Comments'
? window.shuoshuoComment = { loadComment: loadFBComment }
: window.loadOtherComment = loadFBComment
return
}
if ('!{theme.comments.use[0]}' === 'Facebook Comments' || !!{theme.comments.lazyload}) {
if (!{theme.comments.lazyload}) btf.loadComment(document.querySelector('#post-comment .fb-comments'), loadFBComment)
else loadFBComment()
} else {
window.loadOtherComment = loadFBComment
}
})()

View File

@@ -0,0 +1,82 @@
- 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 isShuoshuo = GLOBAL_CONFIG_SITE.pageType === 'shuoshuo'
const option = !{JSON.stringify(option)}
const getGiscusTheme = theme => theme === 'dark' ? '!{dark_theme}' : '!{light_theme}'
const createScriptElement = config => {
const ele = document.createElement('script')
Object.entries(config).forEach(([key, value]) => {
ele.setAttribute(key, value)
})
return ele
}
const loadGiscus = (el = document, key) => {
const mappingConfig = isShuoshuo
? { 'data-mapping': 'specific', 'data-term': key }
: { 'data-mapping': (option && option['data-mapping']) || 'pathname' }
const giscusConfig = {
src: '!{giscusUrl}',
'data-repo': '!{repo}',
'data-repo-id': '!{repo_id}',
'data-category-id': '!{category_id}',
'data-theme': getGiscusTheme(document.documentElement.getAttribute('data-theme')),
'data-reactions-enabled': '1',
crossorigin: 'anonymous',
async: true,
...option,
...mappingConfig
}
const scriptElement = createScriptElement(giscusConfig)
el.querySelector('#giscus-wrap').appendChild(scriptElement)
if (isShuoshuo) {
window.shuoshuoComment.destroyGiscus = () => {
if (el.children.length) {
el.innerHTML = ''
el.classList.add('no-comment')
}
}
}
}
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 (isShuoshuo) {
'!{use[0]}' === 'Giscus'
? window.shuoshuoComment = { loadComment: loadGiscus }
: window.loadOtherComment = loadGiscus
return
}
if ('!{use[0]}' === 'Giscus' || !!{lazyload}) {
if (!{lazyload}) btf.loadComment(document.getElementById('giscus-wrap'), loadGiscus)
else loadGiscus()
} else {
window.loadOtherComment = loadGiscus
}
})()

View File

@@ -0,0 +1,64 @@
- const { client_id, client_secret, repo, owner, admin, option } = theme.gitalk
script.
(() => {
const isShuoshuo = GLOBAL_CONFIG_SITE.pageType === 'shuoshuo'
const option = !{JSON.stringify(option)}
const commentCount = n => {
const isCommentCount = document.querySelector('#post-meta .gitalk-comment-count')
if (isCommentCount) {
isCommentCount.textContent= n
}
}
const initGitalk = (el, path) => {
if (isShuoshuo) {
window.shuoshuoComment.destroyGitalk = () => {
if (el.children.length) {
el.innerHTML = ''
el.classList.add('no-comment')
}
}
}
const gitalk = new Gitalk({
clientID: '!{client_id}',
clientSecret: '!{client_secret}',
repo: '!{repo}',
owner: '!{owner}',
admin: ['!{admin}'],
updateCountCallback: commentCount,
...option,
id: isShuoshuo ? path : (option && option.id) || '!{md5(page.path)}'
})
gitalk.render('gitalk-container')
}
const loadGitalk = async(el, path) => {
if (typeof Gitalk === 'function') initGitalk(el, path)
else {
await btf.getCSS('!{url_for(theme.asset.gitalk_css)}')
await btf.getScript('!{url_for(theme.asset.gitalk)}')
initGitalk(el, path)
}
}
if (isShuoshuo) {
'!{theme.comments.use[0]}' === 'Gitalk'
? window.shuoshuoComment = { loadComment: loadGitalk }
: window.loadOtherComment = loadGitalk
return
}
if ('!{theme.comments.use[0]}' === 'Gitalk' || !!{theme.comments.lazyload}) {
if (!{theme.comments.lazyload}) btf.loadComment(document.getElementById('gitalk-container'), loadGitalk)
else loadGitalk()
} else {
window.loadOtherComment = loadGitalk
}
})()

View File

@@ -0,0 +1,46 @@
- let defaultComment = theme.comments.use[0]
hr.custom-hr
#post-comment
.comment-head
.comment-headline
i.fas.fa-comments.fa-fw
span= ' ' + _p('comment')
if theme.comments.use.length > 1
.comment-switch
span.first-comment=defaultComment
span#switch-btn
span.second-comment=theme.comments.use[1]
.comment-wrap
each name in theme.comments.use
div
case name
when 'Disqus'
#disqus_thread
when 'Valine'
#vcomment.vcomment
when 'Disqusjs'
#disqusjs-wrap
when 'Livere'
#lv-container(data-id="city" data-uid=theme.livere.uid)
when 'Gitalk'
#gitalk-container
when 'Utterances'
#utterances-wrap
when 'Twikoo'
#twikoo-wrap
when 'Waline'
#waline-wrap
when 'Giscus'
#giscus-wrap
when 'Facebook Comments'
.fb-comments(data-colorscheme = theme.display_mode === 'dark' ? 'dark' : 'light'
data-numposts= theme.facebook_comments.pageSize || 10
data-order-by= theme.facebook_comments.order_by || 'social'
data-width="100%")
when 'Remark42'
#remark42
when 'Artalk'
#artalk-wrap

View File

@@ -0,0 +1,26 @@
each name in theme.comments.use
case name
when 'Valine'
!=partial('includes/third-party/comments/valine', {}, {cache: true})
when 'Disqus'
include ./disqus.pug
when 'Disqusjs'
include ./disqusjs.pug
when 'Livere'
!=partial('includes/third-party/comments/livere', {}, {cache: true})
when 'Gitalk'
include ./gitalk.pug
when 'Utterances'
!=partial('includes/third-party/comments/utterances', {}, {cache: true})
when 'Twikoo'
!=partial('includes/third-party/comments/twikoo', {}, {cache: true})
when 'Waline'
!=partial('includes/third-party/comments/waline', {}, {cache: true})
when 'Giscus'
!=partial('includes/third-party/comments/giscus', {}, {cache: true})
when 'Facebook Comments'
include ./facebook_comments.pug
when 'Remark42'
!=partial('includes/third-party/comments/remark42', {}, {cache: true})
when 'Artalk'
!=partial('includes/third-party/comments/artalk', {}, {cache: true})

View File

@@ -0,0 +1,47 @@
- const { use, lazyload } = theme.comments
script.
(() => {
const isShuoshuo = GLOBAL_CONFIG_SITE.pageType === 'shuoshuo'
const loadLivere = (el, path) => {
window.livereOptions = {
refer: path || location.pathname
}
if (isShuoshuo) {
window.shuoshuoComment.destroyLivere = () => {
if (el.children.length) {
el.innerHTML = ''
el.classList.add('no-comment')
}
}
}
if (typeof LivereTower === 'object') window.LivereTower.init()
else {
(function(d, s) {
var j, e = d.getElementsByTagName(s)[0];
if (typeof LivereTower === 'function') { return; }
j = d.createElement(s);
j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
j.async = true;
e.parentNode.insertBefore(j, e);
})(document, 'script');
}
}
if (isShuoshuo) {
'!{use[0]}' === 'Livere'
? window.shuoshuoComment = { loadComment: loadLivere }
: window.loadOtherComment = loadLivere
return
}
if ('!{use[0]}' === 'Livere' || !!{lazyload}) {
if (!{lazyload}) btf.loadComment(document.getElementById('lv-container'), loadLivere)
else loadLivere()
} else {
window.loadOtherComment = loadLivere
}
})()

View File

@@ -0,0 +1,78 @@
- const { host, siteId, option } = theme.remark42
script.
(() => {
const isShuoshuo = GLOBAL_CONFIG_SITE.pageType === 'shuoshuo'
const options = !{JSON.stringify(option)}
const loadScript = src => {
const script = document.createElement('script')
script.src = src
script.defer = true
document.head.appendChild(script)
}
const addRemark42 = () => loadScript('!{host}/web/embed.js')
const getCount = () => document.querySelector('.remark42__counter') && loadScript('!{host}/web/count.js')
const destroyRemark42 = () => window.remark42Instance && window.remark42Instance.destroy()
const initRemark42 = remark_config => {
if (window.REMARK42) {
destroyRemark42()
window.remark42Instance = window.REMARK42.createInstance({
...remark_config
})
}
}
const loadRemark42 = (el, path) => {
if (isShuoshuo) {
window.shuoshuoComment.destroyRemark42 = () => {
destroyRemark42()
if (el.children.length) {
el.innerHTML = ''
el.classList.add('no-comment')
}
}
}
window.remark_config = {
host: '!{host}',
site_id: '!{siteId}',
theme: document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'light',
...options,
url: isShuoshuo ? window.location.origin + path : (options && options.url) || window.location.origin + window.location.pathname
}
if (window.REMARK42) {
initRemark42(remark_config)
getCount()
} else {
addRemark42()
window.addEventListener('REMARK42::ready', () => {
initRemark42(remark_config)
getCount()
})
}
}
const remarkChangeMode = theme => window.REMARK42 && window.REMARK42.changeTheme(theme)
btf.addGlobalFn('themeChange', remarkChangeMode, 'remark42')
if (isShuoshuo) {
'!{theme.comments.use[0]}' === 'Remark42'
? window.shuoshuoComment = { loadComment: loadRemark42 }
: window.loadOtherComment = loadRemark42
return
}
if ('!{theme.comments.use[0]}' === 'Remark42' || !!{theme.comments.lazyload}) {
if (!{theme.comments.lazyload}) btf.loadComment(document.getElementById('remark42'), loadRemark42)
else loadRemark42()
} else {
window.loadOtherComment = loadRemark42
}
})()

View File

@@ -0,0 +1,64 @@
- const { envId, region, option } = theme.twikoo
- const { use, lazyload, count } = theme.comments
script.
(() => {
const isShuoshuo = GLOBAL_CONFIG_SITE.pageType === 'shuoshuo'
const option = !{JSON.stringify(option)}
const getCount = () => {
const countELement = document.getElementById('twikoo-count')
if(!countELement) return
twikoo.getCommentsCount({
envId: '!{envId}',
region: '!{region}',
urls: [window.location.pathname],
includeReply: false
}).then(res => {
countELement.textContent = res[0].count
}).catch(err => {
console.error(err)
})
}
const init = (el = document, path = location.pathname) => {
twikoo.init({
el: el.querySelector('#twikoo-wrap'),
envId: '!{envId}',
region: '!{region}',
onCommentLoaded: () => {
btf.loadLightbox(document.querySelectorAll('#twikoo .tk-content img:not(.tk-owo-emotion)'))
},
...option,
path: isShuoshuo ? path : (option && option.path) || path
})
!{count ? `GLOBAL_CONFIG_SITE.pageType === 'post' && getCount()` : ''}
isShuoshuo && (window.shuoshuoComment.destroyTwikoo = () => {
if (el.children.length) {
el.innerHTML = ''
el.classList.add('no-comment')
}
})
}
const loadTwikoo = (el, path) => {
if (typeof twikoo === 'object') setTimeout(() => init(el, path), 0)
else btf.getScript('!{url_for(theme.asset.twikoo)}').then(() => init(el, path))
}
if (isShuoshuo) {
'!{use[0]}' === 'Twikoo'
? window.shuoshuoComment = { loadComment: loadTwikoo }
: window.loadOtherComment = loadTwikoo
return
}
if ('!{use[0]}' === 'Twikoo' || !!{lazyload}) {
if (!{lazyload}) btf.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo)
else loadTwikoo()
} else {
window.loadOtherComment = loadTwikoo
}
})()

View File

@@ -0,0 +1,63 @@
- const { use, lazyload } = theme.comments
- const { repo, issue_term, light_theme, dark_theme, js, option } = theme.utterances
- const utterancesUrl = js || 'https://utteranc.es/client.js'
- const utterancesOriginUrl = new URL(utterancesUrl).origin
script.
(() => {
const isShuoshuo = GLOBAL_CONFIG_SITE.pageType === 'shuoshuo'
const option = !{JSON.stringify(option)}
const getUtterancesTheme = theme => theme === 'dark' ? '#{dark_theme}' : '#{light_theme}'
const loadUtterances = (el = document, key) => {
if (isShuoshuo) {
window.shuoshuoComment.destroyUtterances = () => {
if (el.children.length) {
el.innerHTML = ''
el.classList.add('no-comment')
}
}
}
const config = {
src: '!{utterancesUrl}',
repo: '!{repo}',
theme: getUtterancesTheme(document.documentElement.getAttribute('data-theme')),
crossorigin: 'anonymous',
async: true,
...option,
'issue-term': isShuoshuo ? key : (option && option['issue-term']) || '!{issue_term}'
}
const ele = document.createElement('script')
Object.entries(config).forEach(([key, value]) => ele.setAttribute(key, value))
el.querySelector('#utterances-wrap').appendChild(ele)
}
const changeUtterancesTheme = theme => {
const iframe = document.querySelector('#utterances-wrap iframe')
if (iframe) {
const message = {
type: 'set-theme',
theme: getUtterancesTheme(theme)
};
iframe.contentWindow.postMessage(message, '!{utterancesOriginUrl}')
}
}
btf.addGlobalFn('themeChange', changeUtterancesTheme, 'utterances')
if (isShuoshuo) {
'!{use[0]}' === 'Utterances'
? window.shuoshuoComment = { loadComment: loadUtterances }
: window.loadOtherComment = loadUtterances
return
}
if ('!{use[0]}' === 'Utterances' || !!{lazyload}) {
if (!{lazyload}) btf.loadComment(document.getElementById('utterances-wrap'), loadUtterances)
else loadUtterances()
} else {
window.loadOtherComment = loadUtterances
}
})()

View File

@@ -0,0 +1,60 @@
- const { use, lazyload } = theme.comments
- const { appId, appKey, avatar, serverURLs, visitor, option } = theme.valine
- let emojiMaps = '""'
if site.data.valine
- emojiMaps = JSON.stringify(site.data.valine)
script.
(() => {
const isShuoshuo = GLOBAL_CONFIG_SITE.pageType === 'shuoshuo'
const option = !{JSON.stringify(option)}
const initValine = (el, path) => {
if (isShuoshuo) {
window.shuoshuoComment.destroyValine = () => {
if (el.children.length) {
el.innerHTML = ''
el.classList.add('no-comment')
}
}
}
const valineConfig = {
el: '#vcomment',
appId: '#{appId}',
appKey: '#{appKey}',
avatar: '#{avatar}',
serverURLs: '#{serverURLs}',
emojiMaps: !{emojiMaps},
visitor: #{visitor},
...option,
path: isShuoshuo ? path : (option && option.path) || window.location.pathname
}
new Valine(valineConfig)
}
const loadValine = async (el, path) => {
if (typeof Valine === 'function') {
initValine(el, path)
} else {
await btf.getScript('!{url_for(theme.asset.valine)}')
initValine(el, path)
}
}
if (isShuoshuo) {
'!{use[0]}' === 'Valine'
? window.shuoshuoComment = { loadComment: loadValine }
: window.loadOtherComment = loadValine
return
}
if ('!{use[0]}' === 'Valine' || !!{lazyload}) {
if (!{lazyload}) btf.loadComment(document.getElementById('vcomment'),loadValine)
else setTimeout(loadValine, 0)
} else {
window.loadOtherComment = loadValine
}
})()

View File

@@ -0,0 +1,61 @@
- const { serverURL, option, pageview } = theme.waline
- const { lazyload, count, use } = theme.comments
script.
(() => {
let initFn = window.walineFn || null
const isShuoshuo = GLOBAL_CONFIG_SITE.pageType === 'shuoshuo'
const option = !{JSON.stringify(option)}
const destroyWaline = ele => ele.destroy()
const initWaline = (Fn, el = document, path = window.location.pathname) => {
const waline = Fn({
el: el.querySelector('#waline-wrap'),
serverURL: '!{serverURL}',
pageview: !{lazyload ? false : pageview},
dark: 'html[data-theme="dark"]',
comment: !{lazyload ? false : count},
...option,
path: isShuoshuo ? path : (option && option.path) || path
})
if (isShuoshuo) {
window.shuoshuoComment.destroyWaline = () => {
destroyWaline(waline)
if (el.children.length) {
el.innerHTML = ''
el.classList.add('no-comment')
}
}
}
}
const loadWaline = (el, path) => {
if (initFn) initWaline(initFn, el, path)
else {
btf.getCSS('!{url_for(theme.asset.waline_css)}')
.then(() => import('!{url_for(theme.asset.waline_js)}'))
.then(({ init }) => {
initFn = init || Waline.init
initWaline(initFn, el, path)
window.walineFn = initFn
})
}
}
if (isShuoshuo) {
'!{use[0]}' === 'Waline'
? window.shuoshuoComment = { loadComment: loadWaline }
: window.loadOtherComment = loadWaline
return
}
if ('!{use[0]}' === 'Waline' || !!{lazyload}) {
if (!{lazyload}) btf.loadComment(document.getElementById('waline-wrap'),loadWaline)
else setTimeout(loadWaline, 0)
} else {
window.loadOtherComment = loadWaline
}
})()