init...
This commit is contained in:
63
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/comments/artalk.pug
vendored
Normal file
63
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/comments/artalk.pug
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
- const { server, site, option } = theme.artalk
|
||||
- const { use, lazyload, count } = theme.comments
|
||||
|
||||
script.
|
||||
(() => {
|
||||
const initArtalk = () => {
|
||||
window.artalkItem = new Artalk(Object.assign({
|
||||
el: '#artalk-wrap',
|
||||
server: '!{server}',
|
||||
site: '!{site}',
|
||||
pageKey: location.pathname,
|
||||
darkMode: document.documentElement.getAttribute('data-theme') === 'dark',
|
||||
countEl: '.artalk-count'
|
||||
},!{JSON.stringify(option)}))
|
||||
|
||||
if (GLOBAL_CONFIG.lightbox === 'null') return
|
||||
window.artalkItem.use(ctx => {
|
||||
ctx.on('list-loaded', () => {
|
||||
ctx.getCommentList().forEach(comment => {
|
||||
const $content = comment.getRender().$content
|
||||
anzhiyu.loadLightbox($content.querySelectorAll('img:not([atk-emoticon])'))
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const loadArtalk = async () => {
|
||||
if (typeof window.artalkItem === 'object') {
|
||||
initArtalk()
|
||||
!{count ? 'GLOBAL_CONFIG_SITE.isPost && getCount()' : ''}
|
||||
} else {
|
||||
await getCSS('!{theme.asset.artalk_css}')
|
||||
await getScript('!{theme.asset.artalk_js}')
|
||||
initArtalk()
|
||||
!{count ? 'GLOBAL_CONFIG_SITE.isPost && getCount()' : ''}
|
||||
}
|
||||
}
|
||||
|
||||
const getCount = () => {
|
||||
Artalk.loadCountWidget({
|
||||
server: '!{server}',
|
||||
site: '!{site}',
|
||||
countEl: '.artalk-count'
|
||||
})
|
||||
}
|
||||
|
||||
const artalkChangeMode = theme => {
|
||||
const artalkWrap = document.getElementById('artalk-wrap')
|
||||
if (!(artalkWrap && artalkWrap.children.length)) return
|
||||
const isDark = theme === 'dark'
|
||||
window.artalkItem.setDarkMode(isDark)
|
||||
}
|
||||
|
||||
|
||||
anzhiyu.addGlobalFn('themeChange', artalkChangeMode, 'artalk')
|
||||
|
||||
if ('!{use[0]}' === 'Artalk' || !!{lazyload}) {
|
||||
if (!{lazyload}) anzhiyu.loadComment(document.getElementById('artalk-wrap'), loadArtalk)
|
||||
else loadArtalk()
|
||||
} else {
|
||||
window.loadOtherComment = loadArtalk
|
||||
}
|
||||
})()
|
||||
35
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/comments/index.pug
vendored
Normal file
35
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/comments/index.pug
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
- let defaultComment = theme.comments.use[0]
|
||||
hr
|
||||
#post-comment
|
||||
.comment-head
|
||||
.comment-headline
|
||||
i.anzhiyufont.anzhiyu-icon-comments
|
||||
span= ' ' + _p('comment')
|
||||
.comment-randomInfo
|
||||
a(onclick="anzhiyu.addRandomCommentInfo()" href="javascript:void(0)" style=theme.visitorMail.enable ? "" : "display: none") 匿名评论
|
||||
a(href=url_for('/privacy') style="margin-left: 4px") 隐私政策
|
||||
|
||||
if theme.comments.use.length > 1
|
||||
.comment-switch
|
||||
span.first-comment=defaultComment
|
||||
span#switch-btn
|
||||
span.second-comment=theme.comments.use[1]
|
||||
|
||||
if defaultComment == "Twikoo"
|
||||
.comment-tips#comment-tips
|
||||
span ✅ 你无需删除空行,直接评论以获取最佳展示效果
|
||||
|
||||
.comment-wrap
|
||||
each name in theme.comments.use
|
||||
div
|
||||
case name
|
||||
when 'Valine'
|
||||
#vcomment.vcomment
|
||||
when 'Twikoo'
|
||||
#twikoo-wrap
|
||||
when 'Waline'
|
||||
#waline-wrap
|
||||
when 'Artalk'
|
||||
#artalk-wrap
|
||||
|
||||
.comment-barrage
|
||||
10
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/comments/js.pug
vendored
Normal file
10
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/comments/js.pug
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
each name in theme.comments.use
|
||||
case name
|
||||
when 'Valine'
|
||||
!=partial('includes/third-party/comments/valine', {}, {cache: true})
|
||||
when 'Twikoo'
|
||||
!=partial('includes/third-party/comments/twikoo', {}, {cache: true})
|
||||
when 'Waline'
|
||||
!=partial('includes/third-party/comments/waline', {}, {cache: true})
|
||||
when 'Artalk'
|
||||
!=partial('includes/third-party/comments/artalk', {}, {cache: true})
|
||||
50
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/comments/twikoo.pug
vendored
Normal file
50
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/comments/twikoo.pug
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
- const { envId, region, option } = theme.twikoo
|
||||
- const { use, lazyload, count } = theme.comments
|
||||
|
||||
script.
|
||||
(() => {
|
||||
const init = () => {
|
||||
twikoo.init(Object.assign({
|
||||
el: '#twikoo-wrap',
|
||||
envId: '!{envId}',
|
||||
region: '!{region}',
|
||||
onCommentLoaded: () => {
|
||||
anzhiyu.loadLightbox(document.querySelectorAll('#twikoo .tk-content img:not(.tk-owo-emotion)'))
|
||||
}
|
||||
}, !{JSON.stringify(option)}))
|
||||
}
|
||||
|
||||
const loadTwikoo = () => {
|
||||
if (typeof twikoo === 'object') setTimeout(runFn,0)
|
||||
else getScript('!{url_for(theme.asset.twikoo)}').then(runFn)
|
||||
}
|
||||
|
||||
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 runFn = () => {
|
||||
init();
|
||||
!{count ? 'GLOBAL_CONFIG_SITE.isPost && getCount()' : ''}
|
||||
}
|
||||
|
||||
if ('!{use[0]}' === 'Twikoo' || !!{lazyload}) {
|
||||
if (!{lazyload}) anzhiyu.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo)
|
||||
else {
|
||||
loadTwikoo()
|
||||
}
|
||||
} else {
|
||||
window.loadOtherComment = loadTwikoo
|
||||
}
|
||||
})()
|
||||
37
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/comments/valine.pug
vendored
Normal file
37
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/comments/valine.pug
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
- 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 initValine = () => {
|
||||
const valine = new Valine(Object.assign({
|
||||
el: '#vcomment',
|
||||
appId: '#{appId}',
|
||||
appKey: '#{appKey}',
|
||||
avatar: '#{avatar}',
|
||||
serverURLs: '#{serverURLs}',
|
||||
emojiMaps: !{emojiMaps},
|
||||
path: window.location.pathname,
|
||||
visitor: #{visitor}
|
||||
}, !{JSON.stringify(option)}))
|
||||
}
|
||||
|
||||
const loadValine = async () => {
|
||||
if (typeof Valine === 'function') initValine()
|
||||
else {
|
||||
await getScript('!{url_for(theme.asset.valine)}')
|
||||
initValine()
|
||||
}
|
||||
}
|
||||
|
||||
if ('!{use[0]}' === 'Valine' || !!{lazyload}) {
|
||||
if (!{lazyload}) anzhiyu.loadComment(document.getElementById('vcomment'),loadValine)
|
||||
else setTimeout(loadValine, 0)
|
||||
} else {
|
||||
window.loadOtherComment = loadValine
|
||||
}
|
||||
})()
|
||||
32
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/comments/waline.pug
vendored
Normal file
32
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/comments/waline.pug
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
- const { serverURL, option, pageview } = theme.waline
|
||||
- const { lazyload, count, use } = theme.comments
|
||||
|
||||
script.
|
||||
(() => {
|
||||
const initWaline = () => {
|
||||
const waline = Waline.init(Object.assign({
|
||||
el: '#waline-wrap',
|
||||
serverURL: '!{serverURL}',
|
||||
pageview: !{lazyload ? false : pageview},
|
||||
dark: 'html[data-theme="dark"]',
|
||||
path: window.location.pathname,
|
||||
comment: !{lazyload ? false : count},
|
||||
}, !{JSON.stringify(option)}))
|
||||
}
|
||||
|
||||
const loadWaline = async () => {
|
||||
if (typeof Waline === 'object') initWaline()
|
||||
else {
|
||||
await getCSS('!{url_for(theme.asset.waline_css)}')
|
||||
await getScript('!{url_for(theme.asset.waline_js)}')
|
||||
initWaline()
|
||||
}
|
||||
}
|
||||
|
||||
if ('!{use[0]}' === 'Waline' || !!{lazyload}) {
|
||||
if (!{lazyload}) anzhiyu.loadComment(document.getElementById('waline-wrap'),loadWaline)
|
||||
else setTimeout(loadWaline, 0)
|
||||
} else {
|
||||
window.loadOtherComment = loadWaline
|
||||
}
|
||||
})()
|
||||
Reference in New Issue
Block a user