hexo-theme-solitude 1.7.12 → 1.7.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_config.yml +8 -4
- package/languages/en.yml +4 -0
- package/languages/zh-CN.yml +4 -0
- package/languages/zh-TW.yml +4 -0
- package/layout/includes/head/config.pug +40 -39
- package/layout/includes/inject/body.pug +8 -11
- package/layout/includes/inject/head.pug +9 -36
- package/layout/includes/widgets/aside/asideInfoCard.pug +3 -2
- package/layout/includes/widgets/home/{leonus.pug → carousel.pug} +1 -1
- package/layout/includes/widgets/home/categoryGroup.pug +1 -1
- package/layout/includes/widgets/nav/right.pug +4 -41
- package/layout/includes/widgets/post/postMeta.pug +6 -0
- package/layout/includes/widgets/third-party/comments/artalk.pug +50 -0
- package/layout/includes/widgets/third-party/comments/comment.pug +3 -1
- package/layout/includes/widgets/third-party/comments/twikoo.pug +31 -2
- package/layout/includes/widgets/third-party/comments/valine.pug +44 -12
- package/layout/includes/widgets/third-party/comments/waline.pug +41 -14
- package/layout/includes/widgets/third-party/news-comment/artalk.pug +98 -0
- package/layout/includes/widgets/third-party/news-comment/newest-comment.pug +3 -1
- package/layout/includes/widgets/third-party/news-comment/twikoo.pug +9 -7
- package/layout/includes/widgets/third-party/news-comment/valine.pug +5 -5
- package/layout/includes/widgets/third-party/news-comment/waline.pug +5 -5
- package/layout/index.pug +2 -2
- package/package.json +1 -1
- package/plugins.yml +8 -4
- package/scripts/event/cdn.js +2 -12
- package/source/css/_layout/aside.styl +30 -26
- package/source/css/_layout/header.styl +48 -48
- package/source/css/_page/_home/carousel.styl +5 -2
- package/source/css/_page/_home/home-top.styl +2 -0
- package/source/js/barrage_comment.js +78 -0
- package/source/js/main.js +46 -1
- package/source/js/third_party/efu_ai.min.js +1 -1
- package/source/js/commentBarrage/twikoo.js +0 -151
- package/source/js/commentBarrage/valine.js +0 -156
- package/source/js/commentBarrage/waline.js +0 -153
package/_config.yml
CHANGED
@@ -64,7 +64,6 @@ nav:
|
|
64
64
|
right:
|
65
65
|
random: false # 随机文章跳转 / random post button
|
66
66
|
console: false #控制台 / console
|
67
|
-
top: false # 进度球 / Progress Ball
|
68
67
|
# 自定义按钮
|
69
68
|
# custom button
|
70
69
|
# 左至右
|
@@ -711,14 +710,14 @@ katex:
|
|
711
710
|
# comment
|
712
711
|
comment:
|
713
712
|
enable: false
|
714
|
-
type: # waline, twikoo
|
713
|
+
type: # waline, twikoo, valine, artalk
|
715
714
|
commentBarrage: false # 热评开关 / Hot comment switch
|
716
715
|
lazyload: true # 懒加载
|
717
716
|
count: true # 评论数展示
|
718
717
|
avatar: https://cravatar.cn # Gravatar link
|
719
718
|
newest_comment:
|
720
719
|
enable: false
|
721
|
-
storage:
|
720
|
+
storage: .5 # 缓存时间 1: 1天 / .5 : 半天
|
722
721
|
# twikoo 配置信息
|
723
722
|
# twikoo settings
|
724
723
|
twikoo: # https://twikoo.js.org/
|
@@ -740,7 +739,12 @@ comment:
|
|
740
739
|
avatar:
|
741
740
|
visitor: false
|
742
741
|
option: # options list
|
743
|
-
|
742
|
+
# artalk 配置信息
|
743
|
+
# artalk settings
|
744
|
+
artalk:
|
745
|
+
server: # server url / 后端地址
|
746
|
+
site: # site name / 站点名
|
747
|
+
option: # options
|
744
748
|
|
745
749
|
# 中控台扩展 : 最新评论 + 标签 + 文章
|
746
750
|
console_plus: false
|
package/languages/en.yml
CHANGED
package/languages/zh-CN.yml
CHANGED
package/languages/zh-TW.yml
CHANGED
@@ -26,43 +26,44 @@
|
|
26
26
|
|
27
27
|
let comment = false
|
28
28
|
|
29
|
-
if (theme.comment.
|
30
|
-
comment =
|
29
|
+
if (theme.comment.enable) {
|
30
|
+
comment = {
|
31
31
|
avatar: theme.comment.avatar,
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
32
|
+
commentBarrage: theme.comment.commentBarrage,
|
33
|
+
}
|
34
|
+
switch (theme.comment.type) {
|
35
|
+
case "twikoo":
|
36
|
+
comment.url = theme.comment.twikoo.envId
|
37
|
+
comment.accessToken = theme.comment.twikoo.accessToken
|
38
|
+
comment.owo = {
|
39
|
+
body: '.OwO-body',
|
40
|
+
item: '.OwO-items li'
|
41
|
+
}
|
42
|
+
break
|
43
|
+
case "waline":
|
44
|
+
comment.url = theme.comment.waline.envId
|
45
|
+
comment.owo = {
|
46
|
+
body: '.wl-emoji-popup',
|
47
|
+
item: '.wl-tab-wrapper button'
|
48
|
+
}
|
49
|
+
break
|
50
|
+
case "valine":
|
51
|
+
comment.url = theme.comment.valine.serverURLs
|
52
|
+
comment.appId = theme.comment.valine.appId
|
53
|
+
comment.appKey = theme.comment.valine.appKey
|
54
|
+
comment.owo = {
|
55
|
+
body: '.vwrap',
|
56
|
+
item: '.vemojis i'
|
57
|
+
}
|
58
|
+
break
|
59
|
+
case "artalk":
|
60
|
+
comment.owo = {
|
61
|
+
body: '.atk-grp',
|
62
|
+
item: '.atk-item'
|
63
|
+
}
|
64
|
+
default:
|
65
|
+
break
|
66
|
+
}
|
66
67
|
}
|
67
68
|
|
68
69
|
let post_ai = false
|
@@ -138,13 +139,13 @@
|
|
138
139
|
stop: _p('right_menu.music.stop'),
|
139
140
|
}
|
140
141
|
}
|
141
|
-
if(theme.comment.enable && theme.comment.commentBarrage){
|
142
|
+
if (theme.comment.enable && theme.comment.commentBarrage) {
|
142
143
|
rightMenu.barrage = {
|
143
144
|
open: _p('right_menu.barrage.open'),
|
144
145
|
close: _p('right_menu.barrage.close')
|
145
146
|
}
|
146
147
|
}
|
147
|
-
if(theme.right_menu.translate.enable){
|
148
|
+
if (theme.right_menu.translate.enable) {
|
148
149
|
rightMenu.translate = {
|
149
150
|
translateDelay: theme.right_menu.translate.translateDelay,
|
150
151
|
defaultEncoding: theme.right_menu.translate.defaultEncoding
|
@@ -185,7 +186,7 @@ script.
|
|
185
186
|
covercolor: {
|
186
187
|
enable: !{theme.post.covercolor.enable}
|
187
188
|
},
|
188
|
-
comment: !{comment},
|
189
|
+
comment: !{comment ? JSON.stringify(comment) : false},
|
189
190
|
lightbox: '!{ theme.mediumZoom ? "mediumZoom" : (theme.fancybox ? "fancybox" : "null")}',
|
190
191
|
post_ai: !{post_ai},
|
191
192
|
right_menu: !{rightMenu ? JSON.stringify(rightMenu) : false},
|
@@ -16,10 +16,6 @@ div
|
|
16
16
|
script(src=url_for(theme.cdn.waterfall))
|
17
17
|
script(src=url_for(theme.cdn.pjax))
|
18
18
|
|
19
|
-
if theme.comment.enable && theme.comment.type === 'valine'
|
20
|
-
// md5
|
21
|
-
script(src=url_for(theme.cdn.blueimp_md5))
|
22
|
-
|
23
19
|
if theme.mermaid
|
24
20
|
script(src=url_for(theme.cdn.mermaid_js))
|
25
21
|
|
@@ -73,14 +69,15 @@ div
|
|
73
69
|
case theme.comment.type
|
74
70
|
when 'twikoo'
|
75
71
|
script(src=url_for(theme.cdn.twikoo))
|
72
|
+
when 'waline'
|
73
|
+
script(src=url_for(theme.cdn.waline_js))
|
74
|
+
when 'valine'
|
75
|
+
script(src=url_for(theme.cdn.blueimp_md5))
|
76
|
+
script(src=url_for(theme.cdn.valine))
|
77
|
+
when 'artalk'
|
78
|
+
script(src=url_for(theme.cdn.artalk_js))
|
76
79
|
if theme.comment.commentBarrage
|
77
|
-
|
78
|
-
when 'twikoo'
|
79
|
-
script(src=url_for(theme.cdn.twikoo_commentBarrage))
|
80
|
-
when 'waline'
|
81
|
-
script(src=url_for(theme.cdn.waline_commentBarrage))
|
82
|
-
when 'valine'
|
83
|
-
script(src=url_for(theme.cdn.valine_commentBarrage))
|
80
|
+
script(src=url_for(theme.cdn.commentBarrage))
|
84
81
|
|
85
82
|
if theme.music.enable
|
86
83
|
script(src=url_for(theme.cdn.music_js))
|
@@ -17,6 +17,13 @@ if theme.lightbox && theme.fancybox
|
|
17
17
|
if theme.katex && theme.katex.enable
|
18
18
|
link(rel="stylesheet", href=url_for(theme.cdn.katex))
|
19
19
|
|
20
|
+
if theme.comment.enable
|
21
|
+
case theme.comment.type
|
22
|
+
when 'waline'
|
23
|
+
link(rel="stylesheet" href=url_for(theme.cdn.waline_css))
|
24
|
+
when 'artalk'
|
25
|
+
link(rel="stylesheet" href=url_for(theme.cdn.artalk_css))
|
26
|
+
|
20
27
|
// Open Graph
|
21
28
|
include ../head/opengraph.pug
|
22
29
|
|
@@ -34,7 +41,7 @@ script.
|
|
34
41
|
const expiryDay = ttl * 86400000
|
35
42
|
const item = {
|
36
43
|
value: value,
|
37
|
-
expiry: now.getTime() + expiryDay
|
44
|
+
expiry: now.getTime() + expiryDay
|
38
45
|
}
|
39
46
|
localStorage.setItem(key, JSON.stringify(item))
|
40
47
|
},
|
@@ -73,45 +80,11 @@ script.
|
|
73
80
|
document.documentElement.classList.remove('hide-aside')
|
74
81
|
}
|
75
82
|
}
|
76
|
-
|
77
|
-
win.getCSS = (url, id = false) => new Promise((resolve, reject) => {
|
78
|
-
const link = document.createElement('link')
|
79
|
-
link.rel = 'stylesheet'
|
80
|
-
link.href = url
|
81
|
-
if (id) link.id = id
|
82
|
-
link.onerror = reject
|
83
|
-
link.onload = link.onreadystatechange = function () {
|
84
|
-
const loadState = this.readyState
|
85
|
-
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
|
86
|
-
link.onload = link.onreadystatechange = null
|
87
|
-
resolve()
|
88
|
-
}
|
89
|
-
document.head.appendChild(link)
|
90
|
-
})
|
91
|
-
|
92
|
-
win.getScript = (url, attr = {}) => new Promise((resolve, reject) => {
|
93
|
-
const script = document.createElement('script')
|
94
|
-
script.src = url
|
95
|
-
script.async = true
|
96
|
-
script.onerror = reject
|
97
|
-
script.onload = script.onreadystatechange = function () {
|
98
|
-
const loadState = this.readyState
|
99
|
-
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
|
100
|
-
script.onload = script.onreadystatechange = null
|
101
|
-
resolve()
|
102
|
-
}
|
103
|
-
|
104
|
-
Object.keys(attr).forEach(key => {
|
105
|
-
script.setAttribute(key, attr[key])
|
106
|
-
})
|
107
|
-
|
108
|
-
document.head.appendChild(script)
|
109
|
-
})
|
110
83
|
}
|
111
84
|
)(window)
|
112
85
|
|
113
86
|
console.log(
|
114
|
-
"%c Program: Hexo %c Theme: Solitude %c Version: v1.7.
|
87
|
+
"%c Program: Hexo %c Theme: Solitude %c Version: v1.7.14",
|
115
88
|
"border-radius:5px 0 0 5px;padding: 5px 10px;color:white;background:#ff3842;",
|
116
89
|
"padding: 5px 10px;color:white;background:#3e9f50;",
|
117
90
|
"border-radius:0 5px 5px 0;padding: 5px 10px;background:#0084ff;color:white;"
|
@@ -5,8 +5,9 @@
|
|
5
5
|
.author-info__sayhi#author-info__sayhi(onclick="sco.changeSayHelloText()")= _p('sayhello.morning')
|
6
6
|
.avatar-img-group
|
7
7
|
img.avatar-img(alt=_p('aside.avatar'), src=theme.aside.card.author.img)
|
8
|
-
.
|
9
|
-
|
8
|
+
if theme.aside.card.author.sticker
|
9
|
+
.avatar-sticker
|
10
|
+
img.avatar-sticker-img(src=theme.aside.card.author.sticker, alt=_p('aside.sticker'))
|
10
11
|
.author-info__description_group
|
11
12
|
.author-info__description!= theme.aside.card.content
|
12
13
|
.author-info__description2!= theme.aside.card.content2
|
@@ -18,7 +18,7 @@ if recommends
|
|
18
18
|
.blog-slider__pagination.swiper-pagination-clickable.swiper-pagination-bullets
|
19
19
|
|
20
20
|
script.
|
21
|
-
function
|
21
|
+
function carousel_swiper() {
|
22
22
|
let e = new Swiper(".blog-slider", {
|
23
23
|
navigation: {
|
24
24
|
nextEl: ".swiper-button-next",
|
@@ -6,7 +6,7 @@ if group
|
|
6
6
|
each item in group
|
7
7
|
- var array = item[1].split('||')
|
8
8
|
.categoryItem
|
9
|
-
a.categoryButton(href=url_for(trim(array[0]))
|
9
|
+
a.categoryButton(href=url_for(trim(array[0])) style="background-image:" + array[2] + ";")
|
10
10
|
span.categoryButtonText= item[0]
|
11
11
|
if array[1]
|
12
12
|
i.solitude(class=trim(array[1]))
|
@@ -15,47 +15,10 @@ if theme.nav.right.console
|
|
15
15
|
.nav-button#nav-console
|
16
16
|
a.console_switchbutton(onclick="sco.showConsole()", title=_p('nav.console'), href="javascript:void(0);")
|
17
17
|
i.solitude.st-dashboard-fill
|
18
|
-
|
19
|
-
.
|
20
|
-
|
21
|
-
|
22
|
-
span#percent= "0"
|
23
|
-
|
24
|
-
script.
|
25
|
-
document.addEventListener('DOMContentLoaded', () => {
|
26
|
-
const percent = () => {
|
27
|
-
let scrollTop = document.documentElement.scrollTop || window.pageYOffset
|
28
|
-
let totalHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight, document.body.clientHeight, document.documentElement.clientHeight) - document.documentElement.clientHeight
|
29
|
-
let scrollPercent = Math.round(scrollTop / totalHeight * 100)
|
30
|
-
let percentElement = document.querySelector("#percent")
|
31
|
-
let viewportBottom = window.scrollY + document.documentElement.clientHeight
|
32
|
-
let remainingScroll = totalHeight - scrollTop
|
33
|
-
|
34
|
-
if ((document.getElementById("post-comment") || document.getElementById("footer")).offsetTop < viewportBottom || scrollPercent > 90) {
|
35
|
-
document.querySelector("#nav-totop").classList.add("long")
|
36
|
-
percentElement.innerHTML = GLOBAL_CONFIG.lang.backtop
|
37
|
-
} else {
|
38
|
-
document.querySelector("#nav-totop").classList.remove("long")
|
39
|
-
if (scrollPercent >= 0) {
|
40
|
-
percentElement.innerHTML = scrollPercent + ""
|
41
|
-
}
|
42
|
-
}
|
43
|
-
|
44
|
-
let elementsToHide = document.querySelectorAll(".needEndHide")
|
45
|
-
if (remainingScroll < 100) {
|
46
|
-
elementsToHide.forEach(function (element) {
|
47
|
-
element.classList.add("hide")
|
48
|
-
})
|
49
|
-
} else {
|
50
|
-
elementsToHide.forEach(function (element) {
|
51
|
-
element.classList.remove("hide")
|
52
|
-
})
|
53
|
-
}
|
54
|
-
|
55
|
-
window.onscroll = percent
|
56
|
-
}
|
57
|
-
percent()
|
58
|
-
})
|
18
|
+
.nav-button#nav-totop(onclick="sco.toTop()")
|
19
|
+
a.totopbtn
|
20
|
+
i.solitude.st-arrow-up-line
|
21
|
+
span#percent= "0"
|
59
22
|
#toggle-menu
|
60
23
|
a.site-page
|
61
24
|
i.solitude.st-menu-line
|
@@ -52,6 +52,9 @@
|
|
52
52
|
span.leancloud_visitors(id=url_for(page.path))
|
53
53
|
span.leancloud-visitors-count
|
54
54
|
i.solitude.st-loading-line
|
55
|
+
when 'artalk'
|
56
|
+
span#ArtalkPV
|
57
|
+
i.solitude.st-loading-line
|
55
58
|
else if theme.busuanzi
|
56
59
|
span#busuanzi_value_page_pv
|
57
60
|
i.solitude.st-loading-line
|
@@ -69,5 +72,8 @@
|
|
69
72
|
when "valine"
|
70
73
|
span.valine-comment-count(data-xid=url_for(page.path) itemprop="commentCount")
|
71
74
|
i.solitude.st-loading-line
|
75
|
+
when 'artalk'
|
76
|
+
span.waline-comment-count#ArtalkCount
|
77
|
+
i.solitude.st-loading-line
|
72
78
|
|
73
79
|
include ./wave
|
@@ -0,0 +1,50 @@
|
|
1
|
+
- const { server, site, option } = theme.comment.artalk
|
2
|
+
- const { lazyload, count } = theme.comment
|
3
|
+
|
4
|
+
script.
|
5
|
+
async function initComment() {
|
6
|
+
let artalkItem = null
|
7
|
+
const initArtalk = () => {
|
8
|
+
artalkItem = Artalk.init({
|
9
|
+
el: '#comment',
|
10
|
+
server: '!{server}',
|
11
|
+
site: "!{site}",
|
12
|
+
pageKey: location.pathname,
|
13
|
+
darkMode: document.documentElement.getAttribute('data-theme') === 'dark',
|
14
|
+
}, !{JSON.stringify(option)})
|
15
|
+
|
16
|
+
if (GLOBAL_CONFIG.lightbox === 'null') return
|
17
|
+
artalkItem.on('list-loaded', () => {
|
18
|
+
const array = []
|
19
|
+
artalkItem.ctx.get('list').getCommentNodes().forEach(comment => {
|
20
|
+
array.push({
|
21
|
+
nick: comment.data.nick,
|
22
|
+
content: comment.data.content_marked,
|
23
|
+
mailMd5: comment.data.email_encrypted,
|
24
|
+
})
|
25
|
+
const $content = comment.getRender().$content
|
26
|
+
utils.lightbox($content.querySelectorAll('img:not([atk-emoticon])'))
|
27
|
+
sco.owoBig()
|
28
|
+
})
|
29
|
+
GLOBAL_CONFIG.comment.commentBarrage && PAGE_CONFIG.comment && initializeCommentBarrage(array)
|
30
|
+
})
|
31
|
+
|
32
|
+
const destroyArtalk = () => {
|
33
|
+
artalkItem.destroy()
|
34
|
+
}
|
35
|
+
|
36
|
+
utils.addGlobalFn('pjax', destroyArtalk, 'destroyArtalk')
|
37
|
+
}
|
38
|
+
|
39
|
+
const artalkChangeMode = theme => {
|
40
|
+
const artalkWrap = document.getElementById('comment')
|
41
|
+
console.log(artalkWrap, artalkWrap.children.length)
|
42
|
+
if (!(artalkWrap && artalkWrap.children.length)) return
|
43
|
+
const isDark = theme === 'dark'
|
44
|
+
artalkItem.setDarkMode(!isDark)
|
45
|
+
}
|
46
|
+
|
47
|
+
utils.addGlobalFn('themeChange', artalkChangeMode, 'artalk')
|
48
|
+
|
49
|
+
initArtalk()
|
50
|
+
}
|
@@ -12,4 +12,6 @@
|
|
12
12
|
when 'waline'
|
13
13
|
!=partial('includes/widgets/third-party/comments/waline',{}, {cache: true})
|
14
14
|
when 'valine'
|
15
|
-
!=partial('includes/widgets/third-party/comments/valine',{}, {cache: true})
|
15
|
+
!=partial('includes/widgets/third-party/comments/valine',{}, {cache: true})
|
16
|
+
when 'artalk'
|
17
|
+
!=partial('includes/widgets/third-party/comments/artalk',{}, {cache: true})
|
@@ -1,12 +1,13 @@
|
|
1
1
|
script.
|
2
2
|
async function initComment() {
|
3
|
-
|
3
|
+
const initOptions = Object.assign(
|
4
4
|
!{JSON.stringify(theme.comment.twikoo || {})},
|
5
5
|
{
|
6
6
|
el: '#comment',
|
7
|
-
onCommentLoaded: function () {
|
7
|
+
onCommentLoaded: async function () {
|
8
8
|
GLOBAL_CONFIG.lightbox && utils.lightbox(document.querySelectorAll('#twikoo .tk-content img:not(.tk-owo-emotion)'))
|
9
9
|
sco.owoBig()
|
10
|
+
GLOBAL_CONFIG.comment.commentBarrage && PAGE_CONFIG.comment && initializeCommentBarrage(await fetchComments())
|
10
11
|
},
|
11
12
|
lang: '#{theme.comment.twikoo.lang}',
|
12
13
|
}
|
@@ -28,4 +29,32 @@ script.
|
|
28
29
|
document.getElementById('twikoo-count').innerText = '加载错误'
|
29
30
|
}
|
30
31
|
}
|
32
|
+
|
33
|
+
async function fetchComments() {
|
34
|
+
try {
|
35
|
+
const response = await fetch("!{theme.comment.twikoo.envId}", {
|
36
|
+
method: "POST",
|
37
|
+
headers: {
|
38
|
+
"Content-Type": "application/json"
|
39
|
+
},
|
40
|
+
body: JSON.stringify({
|
41
|
+
event: "COMMENT_GET",
|
42
|
+
accessToken: "!{theme.comment.twikoo.accessToken}",
|
43
|
+
url: window.location.pathname
|
44
|
+
})
|
45
|
+
});
|
46
|
+
if (!response.ok) {
|
47
|
+
throw new Error("HTTP error! status: " + response.status);
|
48
|
+
}
|
49
|
+
const data = await response.json();
|
50
|
+
return (data.data).map(item => Object.assign({
|
51
|
+
content: item.comment,
|
52
|
+
nick: item.nick,
|
53
|
+
mailMd5: item.mailMd5,
|
54
|
+
id: item.id
|
55
|
+
}))
|
56
|
+
} catch (error) {
|
57
|
+
console.error("An error occurred while fetching comments: ", error);
|
58
|
+
}
|
59
|
+
}
|
31
60
|
}
|
@@ -7,7 +7,7 @@ if site.data.valine
|
|
7
7
|
|
8
8
|
script.
|
9
9
|
async function initComment() {
|
10
|
-
const initValine = () => {
|
10
|
+
const initValine = async () => {
|
11
11
|
const valine = new Valine(Object.assign({
|
12
12
|
el: '#comment',
|
13
13
|
appId: '#{appId}',
|
@@ -25,20 +25,52 @@ script.
|
|
25
25
|
}
|
26
26
|
|
27
27
|
sco.owoBig();
|
28
|
-
|
29
|
-
|
30
|
-
const loadValine = async () => {
|
31
|
-
if (typeof Valine === 'function') initValine()
|
32
|
-
else {
|
33
|
-
await getScript('!{url_for(theme.cdn.valine)}')
|
34
|
-
initValine()
|
35
|
-
}
|
28
|
+
GLOBAL_CONFIG.comment.commentBarrage && PAGE_CONFIG.comment && initializeCommentBarrage(await fetchComments())
|
36
29
|
}
|
37
30
|
|
38
31
|
if (!!{lazyload}) {
|
39
|
-
if (!{lazyload}) utils.loadComment(document.getElementById('comment'),
|
40
|
-
else setTimeout(
|
32
|
+
if (!{lazyload}) utils.loadComment(document.getElementById('comment'), initValine)
|
33
|
+
else setTimeout(initValine, 0)
|
41
34
|
} else {
|
42
|
-
await
|
35
|
+
await initValine()
|
36
|
+
}
|
37
|
+
|
38
|
+
async function fetchComments() {
|
39
|
+
const url = new URL('#{serverURLs}' + '/1.1/classes/Comment');
|
40
|
+
const params = {
|
41
|
+
url: window.location.pathname,
|
42
|
+
order: '-createdAt'
|
43
|
+
};
|
44
|
+
|
45
|
+
for (const [key, value] of Object.entries(params)) {
|
46
|
+
url.searchParams.append(key, value);
|
47
|
+
}
|
48
|
+
|
49
|
+
try {
|
50
|
+
const response = await fetch(url, {
|
51
|
+
method: "GET",
|
52
|
+
headers: {
|
53
|
+
"X-LC-Id": "#{appId}",
|
54
|
+
"X-LC-Key": '#{appKey}',
|
55
|
+
"Content-Type": "application/json"
|
56
|
+
},
|
57
|
+
});
|
58
|
+
|
59
|
+
if (!response.ok) {
|
60
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
61
|
+
}
|
62
|
+
|
63
|
+
const data = await response.json();
|
64
|
+
return (data.results.filter(item => item.url === window.location.pathname)).map(item =>
|
65
|
+
Object.assign({
|
66
|
+
content: item.comment,
|
67
|
+
nick: item.nick,
|
68
|
+
mailMd5: md5(item.mail),
|
69
|
+
id: item.objectId
|
70
|
+
})
|
71
|
+
)
|
72
|
+
} catch (error) {
|
73
|
+
console.error("An error occurred while fetching comments: ", error);
|
74
|
+
}
|
43
75
|
}
|
44
76
|
}
|
@@ -19,27 +19,54 @@ script.
|
|
19
19
|
const walineInstance = Fn(walineOptions);
|
20
20
|
|
21
21
|
utils.addGlobalFn('pjax', () => walineInstance.destroy(), 'destroyWaline');
|
22
|
-
}
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
await getCSS('!{url_for(theme.cdn.waline_css)}');
|
27
|
-
const {init} = await import('!{url_for(theme.cdn.waline_js)}');
|
28
|
-
walineInitFunction = init || Waline.init;
|
29
|
-
window.walineFn = walineInitFunction;
|
23
|
+
if (GLOBAL_CONFIG.lightbox) {
|
24
|
+
utils.lightbox(document.querySelectorAll('#comment .wl-content img:not(.wl-emoji)'));
|
30
25
|
}
|
31
|
-
|
26
|
+
|
27
|
+
sco.owoBig();
|
28
|
+
|
29
|
+
GLOBAL_CONFIG.comment.commentBarrage && PAGE_CONFIG.comment && initializeCommentBarrage(await fetchComments())
|
32
30
|
}
|
33
31
|
|
34
32
|
if (isLazyLoad) {
|
35
|
-
utils.loadComment(document.getElementById('comment'),
|
33
|
+
utils.loadComment(document.getElementById('comment'), initWaline(walineInitFunction));
|
36
34
|
} else {
|
37
|
-
await
|
35
|
+
await initWaline(walineInitFunction);
|
38
36
|
}
|
39
37
|
|
40
|
-
|
41
|
-
|
42
|
-
|
38
|
+
async function fetchComments() {
|
39
|
+
const url = new URL('#{envId}/api/comment');
|
40
|
+
const params = {
|
41
|
+
path: window.location.pathname,
|
42
|
+
sortBy: 'insertedAt_asc'
|
43
|
+
};
|
43
44
|
|
44
|
-
|
45
|
+
for (const [key, value] of Object.entries(params)) {
|
46
|
+
url.searchParams.append(key, value);
|
47
|
+
}
|
48
|
+
|
49
|
+
try {
|
50
|
+
const response = await fetch(url, {
|
51
|
+
method: "GET",
|
52
|
+
headers: {
|
53
|
+
"Content-Type": "application/json"
|
54
|
+
},
|
55
|
+
});
|
56
|
+
|
57
|
+
if (!response.ok) {
|
58
|
+
throw new Error(`HTTP error! status: ${response.status}`);
|
59
|
+
}
|
60
|
+
|
61
|
+
const data = await response.json();
|
62
|
+
return (data.data).map(item => Object.assign({
|
63
|
+
nick: item.nick,
|
64
|
+
mailId: item.avatar,
|
65
|
+
content: item.comment,
|
66
|
+
id: item.objectId
|
67
|
+
}))
|
68
|
+
} catch (error) {
|
69
|
+
console.error("An error occurred while fetching comments: ", error);
|
70
|
+
}
|
71
|
+
}
|
45
72
|
}
|