mirror of
https://github.com/KivotosRailway/website.git
synced 2026-11-03 19:07:56 +09:00
Add solitude
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
- const { server, site, option } = theme.artalk
|
||||
- const { lazyload ,use} = theme.comment
|
||||
|
||||
script.
|
||||
(() => {
|
||||
let artalkItem = null
|
||||
const initArtalk = () => {
|
||||
artalkItem = Artalk.init({
|
||||
el: '#artalk-wrap',
|
||||
server: '!{server}',
|
||||
site: "!{site}",
|
||||
pageKey: location.pathname,
|
||||
darkMode: document.documentElement.getAttribute('data-theme') === 'dark'
|
||||
}, !{JSON.stringify(option)})
|
||||
if (GLOBAL_CONFIG.lightbox === 'null') return
|
||||
artalkItem.on('list-loaded', () => {
|
||||
const array = []
|
||||
artalkItem.ctx.get('list').getCommentNodes().forEach(comment => {
|
||||
array.push({
|
||||
nick: comment.data.nick,
|
||||
content: comment.data.content_marked,
|
||||
mailMd5: comment.data.email_encrypted,
|
||||
})
|
||||
const $content = comment.getRender().$content
|
||||
GLOBAL_CONFIG.lightbox && utils.lightbox($content.querySelectorAll('img:not([atk-emoticon])'))
|
||||
})
|
||||
sco.owoBig({body: '.atk-grp', item: '.atk-item'})
|
||||
!{commentBarrage} && barrageArtalk(array)
|
||||
})
|
||||
const destroyArtalk = () => artalkItem.destroy()
|
||||
utils.addGlobalFn('pjax', destroyArtalk, 'destroyArtalk')
|
||||
}
|
||||
const loadArtalk = async () => {
|
||||
if (typeof Artalk === 'object') initArtalk()
|
||||
else {
|
||||
await utils.getCSS('!{theme.cdn.artalk_css}')
|
||||
await utils.getScript('!{theme.cdn.artalk_js}').then(initArtalk)
|
||||
}
|
||||
}
|
||||
const artalkChangeMode = theme => {
|
||||
const artalkWrap = document.getElementById('artalk-wrap')
|
||||
if (!(artalkWrap && artalkWrap.children.length)) return
|
||||
const isDark = theme === 'dark'
|
||||
artalkItem.setDarkMode(isDark)
|
||||
}
|
||||
utils.addGlobalFn('themeChange', artalkChangeMode, 'artalk')
|
||||
if ('!{use[0]}' === 'Artalk' || !{lazyload}) {
|
||||
if (!{lazyload}) utils.loadComment(document.getElementById('artalk-wrap'), loadArtalk)
|
||||
else loadArtalk()
|
||||
} else {
|
||||
window.loadTwoComment = loadArtalk
|
||||
}
|
||||
})()
|
||||
|
||||
if commentBarrage
|
||||
script.
|
||||
async function barrageArtalk(array) {
|
||||
const init = () => initializeCommentBarrage(array)
|
||||
if (typeof initializeCommentBarrage === "undefined") await utils.getScript('!{url_for(theme.cdn.commentBarrage)}').then(init)
|
||||
else init()
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
- const {use,count} = theme.comment
|
||||
|
||||
#post-comment
|
||||
.comment-head
|
||||
.comment-headline
|
||||
i.solitude.st-chat-fill
|
||||
span=' ' + _p('comment.title')
|
||||
if count && is_post()
|
||||
span.count
|
||||
= ' ('
|
||||
each name in use
|
||||
case name
|
||||
when "Twikoo"
|
||||
span.twikoo-count
|
||||
i.solitude.st-loading-line
|
||||
when "Waline"
|
||||
span.waline-comment-count
|
||||
i.solitude.st-loading-line
|
||||
when "Valine"
|
||||
span.valine-comment-count(data-xid=url_for(page.path) itemprop="commentCount")
|
||||
i.solitude.st-loading-line
|
||||
when "Artalk"
|
||||
span.artalk-count
|
||||
| )
|
||||
|
||||
if use.length > 1
|
||||
.comment-switch
|
||||
span.first=use[0]
|
||||
span#switch-btn
|
||||
span.second=use[1]
|
||||
|
||||
.comment-wrap
|
||||
each name in use
|
||||
case name
|
||||
when 'Valine'
|
||||
#vcomment.vcomment
|
||||
when 'Twikoo'
|
||||
#twikoo-wrap
|
||||
when 'Waline'
|
||||
#waline-wrap
|
||||
when 'Artalk'
|
||||
#artalk-wrap
|
||||
when 'Giscus'
|
||||
#giscus-wrap
|
||||
@@ -0,0 +1,60 @@
|
||||
- const { repo, repo_id, category_id, theme:themes, option } = theme.giscus
|
||||
- const giscusUrl = theme.cdn.giscus || 'https://giscus.app/client.js'
|
||||
- const giscusOriginUrl = new URL(giscusUrl).origin
|
||||
- const { use, lazyload } = theme.comment
|
||||
|
||||
script.
|
||||
(()=>{
|
||||
const getGiscusTheme = theme => {
|
||||
return theme === 'dark' ? '!{themes.dark}' : '!{themes.light}'
|
||||
}
|
||||
|
||||
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 sendMessage = message => {
|
||||
const iframe = document.querySelector('iframe.giscus-frame')
|
||||
if (!iframe) return
|
||||
iframe.contentWindow.postMessage({ giscus: message }, '!{giscusOriginUrl}')
|
||||
}
|
||||
|
||||
sendMessage({
|
||||
setConfig: {
|
||||
theme: getGiscusTheme(theme)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
utils.addGlobalFn('themeChange', changeGiscusTheme, 'giscus')
|
||||
|
||||
if ('!{use[0]}' === 'Giscus' || !!{lazyload}) {
|
||||
if (!{lazyload}) {
|
||||
const giscusWrap = document.getElementById('giscus-wrap')
|
||||
if (giscusWrap) {
|
||||
utils.loadComment(giscusWrap, loadGiscus)
|
||||
}
|
||||
} else {
|
||||
loadGiscus()
|
||||
}
|
||||
} else {
|
||||
window.loadOtherComment = loadGiscus
|
||||
}
|
||||
})()
|
||||
@@ -0,0 +1,14 @@
|
||||
- const {use} = theme.comment
|
||||
|
||||
each name in use
|
||||
case name
|
||||
when 'Twikoo'
|
||||
!=partial('includes/widgets/third-party/comments/twikoo', {}, {cache: true})
|
||||
when 'Waline'
|
||||
!=partial('includes/widgets/third-party/comments/waline', {}, {cache: true})
|
||||
when 'Valine'
|
||||
!=partial('includes/widgets/third-party/comments/valine', {}, {cache: true})
|
||||
when 'Artalk'
|
||||
!=partial('includes/widgets/third-party/comments/artalk', {}, {cache: true})
|
||||
when 'Giscus'
|
||||
!=partial('includes/widgets/third-party/comments/giscus', {}, {cache: true})
|
||||
@@ -0,0 +1,80 @@
|
||||
- const { envId, region, option ,accessToken } = theme.twikoo
|
||||
- const { lazyload, count, use,commentBarrage } = theme.comment
|
||||
|
||||
script().
|
||||
(() => {
|
||||
const getCount = () => {
|
||||
const ele = document.querySelectorAll('.twikoo-count')
|
||||
if (!ele) return
|
||||
twikoo.getCommentsCount({
|
||||
envId: '!{envId}',
|
||||
region: '!{region}',
|
||||
urls: [window.location.pathname],
|
||||
includeReply: false
|
||||
}).then(res => {
|
||||
ele.forEach(item => item.textContent = res[0].count)
|
||||
}).catch(err => {
|
||||
console.error(err)
|
||||
})
|
||||
}
|
||||
const init = () => {
|
||||
twikoo.init(Object.assign({
|
||||
el: '#twikoo-wrap',
|
||||
envId: '!{envId}',
|
||||
region: '!{region}',
|
||||
path: window.location.pathname,
|
||||
onCommentLoaded: () => {
|
||||
GLOBAL_CONFIG.lightbox && utils.lightbox(document.querySelectorAll('#twikoo .tk-content img:not(.tk-owo-emotion)'))
|
||||
}
|
||||
}, !{JSON.stringify(option)}))
|
||||
|
||||
!{count ? ' && getCount()' : ''}
|
||||
sco.owoBig({
|
||||
body: '.OwO-body',
|
||||
item: '.OwO-items li'
|
||||
})
|
||||
|
||||
barrageTwikoo()
|
||||
}
|
||||
|
||||
const loadTwikoo = () => {
|
||||
if (typeof twikoo === 'object') setTimeout(init,0)
|
||||
else utils.getScript('!{url_for(theme.cdn.twikoo)}').then(init)
|
||||
}
|
||||
|
||||
if ('!{use[0]}' === 'Twikoo' || !{lazyload}) {
|
||||
if (!{lazyload}) utils.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo)
|
||||
else loadTwikoo()
|
||||
} else {
|
||||
window.loadTwoComment = loadTwikoo
|
||||
}
|
||||
})()
|
||||
|
||||
if commentBarrage
|
||||
script.
|
||||
async function barrageTwikoo() {
|
||||
await fetch("!{envId}", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
event: "COMMENT_GET",
|
||||
accessToken: "!{accessToken}",
|
||||
url: window.location.pathname
|
||||
})
|
||||
}).then(async res => {
|
||||
if (!res.ok) throw new Error("HTTP error! status: " + res.status)
|
||||
const data = await res.json();
|
||||
const init = () => {
|
||||
initializeCommentBarrage((data.data).map(item => Object.assign({
|
||||
content: item.comment,
|
||||
nick: item.nick,
|
||||
mailMd5: item.mailMd5,
|
||||
id: item.id
|
||||
})))
|
||||
}
|
||||
if (typeof initializeCommentBarrage === "undefined") await utils.getScript('!{url_for(theme.cdn.commentBarrage)}').then(init)
|
||||
else init()
|
||||
}).catch(error => console.error("An error occurred while fetching comments: ", error))
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
- const { lazyload, count, use,commentBarrage } = theme.comment
|
||||
- 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({
|
||||
el: '#vcomment',
|
||||
appId: '#{appId}',
|
||||
appKey: '#{appKey}',
|
||||
avatar: '#{avatar}',
|
||||
serverURLs: '#{serverURLs}',
|
||||
emojiMaps: !{emojiMaps},
|
||||
path: window.location.pathname,
|
||||
visitor: #{visitor},
|
||||
...!{JSON.stringify(option)}
|
||||
})
|
||||
GLOBAL_CONFIG.lightbox && utils.lightbox(document.querySelectorAll('#comment .vcontent img:not(.vemoji)'))
|
||||
sco.owoBig({body: '.vwrap', item: '.vemojis i'})
|
||||
}
|
||||
const loadValine = async () => {
|
||||
if (typeof Valine === 'function') setTimeout(initValine, 0)
|
||||
else {
|
||||
await utils.getScript('!{url_for(theme.cdn.valine)}').then(initValine)
|
||||
}
|
||||
!{commentBarrage} && barrageValine()
|
||||
}
|
||||
if ('!{use[0]}' === 'Valine' || !{lazyload}) {
|
||||
if (!{lazyload}) utils.loadComment(document.getElementById('vcomment'), loadValine)
|
||||
else loadValine()
|
||||
} else {
|
||||
window.loadTwoComment = loadValine
|
||||
}
|
||||
})()
|
||||
|
||||
if commentBarrage
|
||||
script.
|
||||
async function barrageValine() {
|
||||
const url = new URL('!{serverURLs}/1.1/classes/Comment')
|
||||
const params = {
|
||||
url: window.location.pathname,
|
||||
order: '-createdAt'
|
||||
}
|
||||
Object.entries(params).forEach(([key, value]) => url.searchParams.append(key, value))
|
||||
await fetch(url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"X-LC-Id": "#{appId}",
|
||||
"X-LC-Key": "#{appKey}",
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
}).then(async res => {
|
||||
if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`)
|
||||
const data = await res.json()
|
||||
const init = () =>
|
||||
initializeCommentBarrage(data.results
|
||||
.filter(item => item.url === window.location.pathname)
|
||||
.map(item => ({
|
||||
content: item.comment,
|
||||
nick: item.nick,
|
||||
mailMd5: md5(item.mail),
|
||||
id: item.objectId
|
||||
})))
|
||||
if (typeof md5 === "undefined") await utils.getScript('!{url_for(theme.cdn.blueimp_md5)}')
|
||||
if (typeof initializeCommentBarrage === "undefined") await utils.getScript('!{url_for(theme.cdn.commentBarrage)}').then(init)
|
||||
else init()
|
||||
}).catch(error => console.error("An error occurred while fetching comments: ", error))
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
- const { envId, option ,pageview } = theme.waline
|
||||
- const { lazyload, count, commentBarrage,use } = theme.comment
|
||||
|
||||
script.
|
||||
(() => {
|
||||
let walineInitFunction = window.walineFn || null
|
||||
|
||||
function initWaline(initFn) {
|
||||
const walineOptions = {
|
||||
el: '#waline-wrap',
|
||||
serverURL: '!{envId}',
|
||||
pageview: !{pageview},
|
||||
dark: 'html[data-theme="dark"]',
|
||||
path: window.location.pathname,
|
||||
comment: !{count},
|
||||
...!{JSON.stringify(option)}
|
||||
}
|
||||
const walineInstance = initFn(walineOptions)
|
||||
utils.addGlobalFn('pjax', () => walineInstance.destroy(), 'destroyWaline')
|
||||
GLOBAL_CONFIG.lightbox && utils.lightbox(document.querySelectorAll('#comment .wl-content img:not(.wl-emoji)'))
|
||||
sco.owoBig({
|
||||
body: '.wl-emoji-popup',
|
||||
item: '.wl-tab-wrapper button'
|
||||
})
|
||||
}
|
||||
|
||||
async function loadWaline() {
|
||||
if (walineInitFunction) initWaline(walineInitFunction)
|
||||
else {
|
||||
await utils.getCSS('!{url_for(theme.cdn.waline_css)}')
|
||||
const {init} = await import('!{url_for(theme.cdn.waline_js)}')
|
||||
walineInitFunction = init || Waline.init
|
||||
initWaline(walineInitFunction)
|
||||
window.walineFn = walineInitFunction
|
||||
}
|
||||
!{commentBarrage} && barrageWaline()
|
||||
}
|
||||
|
||||
if (!{use[0] === 'Waline'} || !{lazyload}) {
|
||||
if (!{lazyload}) utils.loadComment(document.getElementById('waline-wrap'), loadWaline)
|
||||
else loadWaline()
|
||||
} else window.loadTwoComment = loadWaline
|
||||
})()
|
||||
|
||||
if commentBarrage
|
||||
script.
|
||||
async function barrageWaline() {
|
||||
const url = new URL('!{envId}/api/comment')
|
||||
const params = {path: window.location.pathname, sortBy: 'insertedAt_asc'}
|
||||
Object.entries(params).forEach(([key, value]) => url.searchParams.append(key, value))
|
||||
await fetch(url).then(async res => {
|
||||
if (!res.ok) throw new Error(`HTTP error! status: ${res.status}`)
|
||||
const data = await res.json();
|
||||
const regex = /<img [^>]*class="wl-emoji"[^>]*>/;
|
||||
const init = () => {
|
||||
initializeCommentBarrage(data.data.data
|
||||
.map(item => ({
|
||||
nick: item.nick,
|
||||
mailId: item.avatar,
|
||||
content: item.comment.replace(regex, ''),
|
||||
id: item.objectId
|
||||
})))
|
||||
}
|
||||
if (typeof initializeCommentBarrage === "undefined") await utils.getScript('!{url_for(theme.cdn.commentBarrage)}').then(init)
|
||||
else init()
|
||||
}).catch(error => console.error("An error occurred while fetching comments: ", error))
|
||||
}
|
||||
Reference in New Issue
Block a user