hexo-theme-solitude 1.7.14 → 1.8.0
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/README.md +25 -25
- package/{README_zh-cn.md → README_en.md} +25 -25
- package/README_zh-tw.md +3 -3
- package/_config.yml +41 -34
- package/layout/includes/body/mode.pug +6 -3
- package/layout/includes/head/config.pug +0 -33
- package/layout/includes/head/page_config.pug +9 -0
- package/layout/includes/head.pug +4 -1
- package/layout/includes/inject/body.pug +1 -26
- package/layout/includes/inject/head.pug +11 -60
- package/layout/includes/widgets/post/postMeta.pug +24 -24
- package/layout/includes/widgets/third-party/comments/artalk.pug +29 -18
- package/layout/includes/widgets/third-party/comments/comment.pug +48 -12
- package/layout/includes/widgets/third-party/comments/twikoo.pug +61 -39
- package/layout/includes/widgets/third-party/comments/valine.pug +36 -38
- package/layout/includes/widgets/third-party/comments/waline.pug +39 -44
- package/layout/includes/widgets/third-party/news-comment/artalk.pug +57 -67
- package/layout/includes/widgets/third-party/news-comment/newest-comment.pug +6 -6
- package/layout/includes/widgets/third-party/news-comment/twikoo.pug +41 -48
- package/layout/includes/widgets/third-party/news-comment/valine.pug +5 -5
- package/layout/includes/widgets/third-party/news-comment/waline.pug +3 -3
- package/layout/includes/widgets/third-party/pjax.pug +1 -0
- package/package.json +1 -1
- package/plugins.yml +2 -2
- package/scripts/event/merge_config.js +280 -255
- package/scripts/filter/comment.js +13 -0
- package/source/css/_comments/comment.styl +73 -12
- package/source/css/_comments/valine.styl +1 -1
- package/source/css/_highlight/index.styl +1 -0
- package/source/css/_tags/link.styl +7 -2
- package/source/js/main.js +42 -18
- package/source/js/tw_cn.js +3 -3
- package/source/js/utils.js +62 -0
@@ -1,18 +1,17 @@
|
|
1
|
-
- const { server, site, option } = theme.
|
2
|
-
- const { lazyload, count } = theme.comment
|
1
|
+
- const { server, site, option } = theme.artalk
|
2
|
+
- const { lazyload, count ,use} = theme.comment
|
3
3
|
|
4
4
|
script.
|
5
|
-
|
5
|
+
!function () {
|
6
6
|
let artalkItem = null
|
7
7
|
const initArtalk = () => {
|
8
8
|
artalkItem = Artalk.init({
|
9
|
-
el: '#
|
9
|
+
el: '#artalk-wrap',
|
10
10
|
server: '!{server}',
|
11
11
|
site: "!{site}",
|
12
12
|
pageKey: location.pathname,
|
13
13
|
darkMode: document.documentElement.getAttribute('data-theme') === 'dark',
|
14
14
|
}, !{JSON.stringify(option)})
|
15
|
-
|
16
15
|
if (GLOBAL_CONFIG.lightbox === 'null') return
|
17
16
|
artalkItem.on('list-loaded', () => {
|
18
17
|
const array = []
|
@@ -24,27 +23,39 @@ script.
|
|
24
23
|
})
|
25
24
|
const $content = comment.getRender().$content
|
26
25
|
utils.lightbox($content.querySelectorAll('img:not([atk-emoticon])'))
|
27
|
-
sco.owoBig()
|
26
|
+
sco.owoBig({body: '.atk-grp', item: '.atk-item'})
|
28
27
|
})
|
29
|
-
|
28
|
+
!{commentBarrage} && getBarrage(array)
|
30
29
|
})
|
31
|
-
|
32
|
-
const destroyArtalk = () => {
|
33
|
-
artalkItem.destroy()
|
34
|
-
}
|
35
|
-
|
30
|
+
const destroyArtalk = () => artalkItem.destroy()
|
36
31
|
utils.addGlobalFn('pjax', destroyArtalk, 'destroyArtalk')
|
37
32
|
}
|
38
|
-
|
33
|
+
const loadArtalk = async () => {
|
34
|
+
if (typeof Artalk === 'object') await initArtalk()
|
35
|
+
else {
|
36
|
+
await utils.getCSS('!{theme.cdn.artalk_css}')
|
37
|
+
await utils.getScript('!{theme.cdn.artalk_js}').then(initArtalk)
|
38
|
+
}
|
39
|
+
}
|
39
40
|
const artalkChangeMode = theme => {
|
40
|
-
const artalkWrap = document.getElementById('
|
41
|
-
console.log(artalkWrap, artalkWrap.children.length)
|
41
|
+
const artalkWrap = document.getElementById('artalk-wrap')
|
42
42
|
if (!(artalkWrap && artalkWrap.children.length)) return
|
43
43
|
const isDark = theme === 'dark'
|
44
44
|
artalkItem.setDarkMode(!isDark)
|
45
45
|
}
|
46
|
-
|
47
46
|
utils.addGlobalFn('themeChange', artalkChangeMode, 'artalk')
|
47
|
+
if ('!{use[0]}' === 'Artalk' || !{lazyload}) {
|
48
|
+
if (!{lazyload}) utils.loadComment(document.getElementById('artalk-wrap'), loadArtalk)
|
49
|
+
else loadArtalk()
|
50
|
+
} else {
|
51
|
+
window.loadTwoComment = loadArtalk
|
52
|
+
}
|
53
|
+
}()
|
48
54
|
|
49
|
-
|
50
|
-
|
55
|
+
if commentBarrage
|
56
|
+
script.
|
57
|
+
async function getBarrage(array) {
|
58
|
+
await utils.getScript('!{url_for(theme.cdn.commentBarrage)}').then(() => {
|
59
|
+
initializeCommentBarrage(array)
|
60
|
+
})
|
61
|
+
}
|
@@ -1,17 +1,53 @@
|
|
1
|
+
- const {use,count} = theme.comment
|
2
|
+
|
1
3
|
#post-comment
|
2
4
|
.comment-head
|
3
5
|
.comment-headline
|
4
6
|
i.solitude.st-chat-fill
|
5
|
-
span=_p('comment.title')
|
6
|
-
|
7
|
+
span=' ' + _p('comment.title')
|
8
|
+
if count
|
9
|
+
span.count
|
10
|
+
= ' ('
|
11
|
+
each name in use
|
12
|
+
case name
|
13
|
+
when "Twikoo"
|
14
|
+
span.twikoo-count
|
15
|
+
i.solitude.st-loading-line
|
16
|
+
when "Waline"
|
17
|
+
span.waline-comment-count
|
18
|
+
i.solitude.st-loading-line
|
19
|
+
when "Valine"
|
20
|
+
span.valine-comment-count(data-xid=url_for(page.path) itemprop="commentCount")
|
21
|
+
i.solitude.st-loading-line
|
22
|
+
when "Artalk"
|
23
|
+
span.artalk-count
|
24
|
+
| )
|
25
|
+
|
26
|
+
if use.length > 1
|
27
|
+
.comment-switch
|
28
|
+
span.first=use[0]
|
29
|
+
span#switch-btn
|
30
|
+
span.second=use[1]
|
31
|
+
|
7
32
|
.comment-wrap
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
33
|
+
each name in use
|
34
|
+
case name
|
35
|
+
when 'Valine'
|
36
|
+
#vcomment.vcomment
|
37
|
+
when 'Twikoo'
|
38
|
+
#twikoo-wrap
|
39
|
+
when 'Waline'
|
40
|
+
#waline-wrap
|
41
|
+
when 'Artalk'
|
42
|
+
#artalk-wrap
|
43
|
+
|
44
|
+
each name in use
|
45
|
+
case name
|
46
|
+
when 'Twikoo'
|
47
|
+
!=partial('includes/widgets/third-party/comments/twikoo', {}, {cache: true})
|
48
|
+
when 'Waline'
|
49
|
+
!=partial('includes/widgets/third-party/comments/waline', {}, {cache: true})
|
50
|
+
when 'Valine'
|
51
|
+
!=partial('includes/widgets/third-party/comments/valine', {}, {cache: true})
|
52
|
+
when 'Artalk'
|
53
|
+
!=partial('includes/widgets/third-party/comments/artalk', {}, {cache: true})
|
@@ -1,45 +1,66 @@
|
|
1
|
+
- const { envId, region, option ,accessToken } = theme.twikoo
|
2
|
+
- const { lazyload, count, use,commentBarrage } = theme.comment
|
3
|
+
|
1
4
|
script.
|
2
|
-
|
3
|
-
const
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
}
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
5
|
+
!function () {
|
6
|
+
const getCount = () => {
|
7
|
+
const ele = document.querySelectorAll('.twikoo-count')
|
8
|
+
if (!ele) return
|
9
|
+
twikoo.getCommentsCount({
|
10
|
+
envId: '!{envId}',
|
11
|
+
region: '!{region}',
|
12
|
+
urls: [window.location.pathname],
|
13
|
+
includeReply: false
|
14
|
+
}).then(res => {
|
15
|
+
ele.forEach(item => item.textContent=res[0].count)
|
16
|
+
}).catch(err => {
|
17
|
+
console.error(err)
|
18
|
+
})
|
19
|
+
}
|
20
|
+
const init = async () => {
|
21
|
+
twikoo.init(Object.assign({
|
22
|
+
el: '#twikoo-wrap',
|
23
|
+
envId: '!{envId}',
|
24
|
+
region: '!{region}',
|
25
|
+
onCommentLoaded: () => {
|
26
|
+
utils.lightbox(document.querySelectorAll('#twikoo .tk-content img:not(.tk-owo-emotion)'))
|
22
27
|
}
|
23
|
-
)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
}, !{JSON.stringify(option)}))
|
29
|
+
|
30
|
+
!{count ? ' && getCount()' : ''}
|
31
|
+
sco.owoBig({
|
32
|
+
body: '.OwO-body',
|
33
|
+
item: '.OwO-items li'
|
34
|
+
})
|
35
|
+
|
36
|
+
!{commentBarrage} && getBarrage()
|
37
|
+
}
|
38
|
+
|
39
|
+
const loadTwikoo = () => {
|
40
|
+
if (typeof twikoo === 'object') init()
|
41
|
+
else utils.getScript('!{url_for(theme.cdn.twikoo)}').then(init)
|
31
42
|
}
|
32
43
|
|
33
|
-
|
44
|
+
if ('!{use[0]}' === 'Twikoo' || !{lazyload}) {
|
45
|
+
if (!{lazyload}) utils.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo)
|
46
|
+
else loadTwikoo()
|
47
|
+
} else {
|
48
|
+
window.loadTwoComment = init
|
49
|
+
}
|
50
|
+
}()
|
51
|
+
|
52
|
+
if commentBarrage
|
53
|
+
script.
|
54
|
+
async function getBarrage() {
|
34
55
|
try {
|
35
|
-
const response = await fetch("!{
|
56
|
+
const response = await fetch("!{envId}", {
|
36
57
|
method: "POST",
|
37
58
|
headers: {
|
38
59
|
"Content-Type": "application/json"
|
39
60
|
},
|
40
61
|
body: JSON.stringify({
|
41
62
|
event: "COMMENT_GET",
|
42
|
-
accessToken: "!{
|
63
|
+
accessToken: "!{accessToken}",
|
43
64
|
url: window.location.pathname
|
44
65
|
})
|
45
66
|
});
|
@@ -47,14 +68,15 @@ script.
|
|
47
68
|
throw new Error("HTTP error! status: " + response.status);
|
48
69
|
}
|
49
70
|
const data = await response.json();
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
71
|
+
await utils.getScript('!{url_for(theme.cdn.commentBarrage)}').then(() => {
|
72
|
+
initializeCommentBarrage((data.data).map(item => Object.assign({
|
73
|
+
content: item.comment,
|
74
|
+
nick: item.nick,
|
75
|
+
mailMd5: item.mailMd5,
|
76
|
+
id: item.id
|
77
|
+
})))
|
78
|
+
})
|
56
79
|
} catch (error) {
|
57
80
|
console.error("An error occurred while fetching comments: ", error);
|
58
81
|
}
|
59
|
-
}
|
60
|
-
}
|
82
|
+
}
|
@@ -1,15 +1,15 @@
|
|
1
|
-
- const { lazyload, count } = theme.comment
|
2
|
-
- const { appId, appKey, avatar, serverURLs, visitor, option } = theme.
|
1
|
+
- const { lazyload, count, use,commentBarrage } = theme.comment
|
2
|
+
- const { appId, appKey, avatar, serverURLs, visitor, option } = theme.valine
|
3
3
|
- let emojiMaps = '""'
|
4
4
|
|
5
5
|
if site.data.valine
|
6
6
|
- emojiMaps = JSON.stringify(site.data.valine)
|
7
7
|
|
8
8
|
script.
|
9
|
-
|
10
|
-
const initValine =
|
11
|
-
const valine = new Valine(
|
12
|
-
el: '#
|
9
|
+
!function () {
|
10
|
+
const initValine = () => {
|
11
|
+
const valine = new Valine({
|
12
|
+
el: '#vcomment',
|
13
13
|
appId: '#{appId}',
|
14
14
|
appKey: '#{appKey}',
|
15
15
|
avatar: '#{avatar}',
|
@@ -18,59 +18,57 @@ script.
|
|
18
18
|
path: window.location.pathname,
|
19
19
|
visitor: #{visitor},
|
20
20
|
...!{JSON.stringify(option)}
|
21
|
-
})
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
})
|
22
|
+
GLOBAL_CONFIG.lightbox && utils.lightbox(document.querySelectorAll('#comment .vcontent img:not(.vemoji)'))
|
23
|
+
sco.owoBig({body: '.vwrap', item: '.vemojis i'})
|
24
|
+
}
|
25
|
+
const loadValine = async () => {
|
26
|
+
if (typeof Valine === 'function') await initValine()
|
27
|
+
else {
|
28
|
+
await utils.getScript('!{url_for(theme.cdn.valine)}').then(initValine)
|
25
29
|
}
|
26
|
-
|
27
|
-
sco.owoBig();
|
28
|
-
GLOBAL_CONFIG.comment.commentBarrage && PAGE_CONFIG.comment && initializeCommentBarrage(await fetchComments())
|
30
|
+
!{commentBarrage} && getBarrage()
|
29
31
|
}
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
else setTimeout(initValine, 0)
|
32
|
+
if ('!{use[0]}' === 'Valine' || !{lazyload}) {
|
33
|
+
if (!{lazyload}) utils.loadComment(document.getElementById('vcomment'), loadValine)
|
34
|
+
else loadValine()
|
34
35
|
} else {
|
35
|
-
|
36
|
+
window.loadTwoComment = loadValine
|
36
37
|
}
|
38
|
+
}()
|
37
39
|
|
38
|
-
|
39
|
-
|
40
|
+
if commentBarrage
|
41
|
+
script.
|
42
|
+
async function getBarrage() {
|
43
|
+
const url = new URL('!{serverURLs}/1.1/classes/Comment')
|
40
44
|
const params = {
|
41
45
|
url: window.location.pathname,
|
42
46
|
order: '-createdAt'
|
43
|
-
};
|
44
|
-
|
45
|
-
for (const [key, value] of Object.entries(params)) {
|
46
|
-
url.searchParams.append(key, value);
|
47
47
|
}
|
48
|
-
|
48
|
+
Object.entries(params).forEach(([key, value]) => url.searchParams.append(key, value))
|
49
49
|
try {
|
50
50
|
const response = await fetch(url, {
|
51
51
|
method: "GET",
|
52
52
|
headers: {
|
53
53
|
"X-LC-Id": "#{appId}",
|
54
|
-
"X-LC-Key":
|
54
|
+
"X-LC-Key": "#{appKey}",
|
55
55
|
"Content-Type": "application/json"
|
56
56
|
},
|
57
|
-
})
|
58
|
-
|
57
|
+
})
|
59
58
|
if (!response.ok) {
|
60
|
-
throw new Error(`HTTP error! status: ${response.status}`)
|
59
|
+
throw new Error(`HTTP error! status: ${response.status}`)
|
61
60
|
}
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
const data = await response.json()
|
62
|
+
await utils.getScript('!{url_for(theme.cdn.commentBarrage)}')
|
63
|
+
initializeCommentBarrage(data.results
|
64
|
+
.filter(item => item.url === window.location.pathname)
|
65
|
+
.map(item => ({
|
66
66
|
content: item.comment,
|
67
67
|
nick: item.nick,
|
68
68
|
mailMd5: md5(item.mail),
|
69
69
|
id: item.objectId
|
70
|
-
})
|
71
|
-
)
|
70
|
+
})))
|
72
71
|
} catch (error) {
|
73
|
-
console.error("An error occurred while fetching comments: ", error)
|
72
|
+
console.error("An error occurred while fetching comments: ", error)
|
74
73
|
}
|
75
|
-
}
|
76
|
-
}
|
74
|
+
}
|
@@ -1,72 +1,67 @@
|
|
1
1
|
- const { envId, option ,pageview } = theme.comment.waline
|
2
|
-
- const { lazyload, count } = theme.comment
|
2
|
+
- const { lazyload, count, commentBarrage } = theme.comment
|
3
3
|
|
4
4
|
script.
|
5
|
-
|
6
|
-
|
7
|
-
let walineInitFunction = window.walineFn || null;
|
5
|
+
!function () {
|
6
|
+
let walineInitFunction = window.walineFn || null
|
8
7
|
|
9
|
-
|
8
|
+
function initWaline(initFn) {
|
10
9
|
const walineOptions = {
|
11
|
-
el: '#
|
10
|
+
el: '#waline-wrap',
|
12
11
|
serverURL: '!{envId}',
|
13
|
-
pageview: !
|
12
|
+
pageview: !{pageview},
|
14
13
|
dark: 'html[data-theme="dark"]',
|
15
14
|
path: window.location.pathname,
|
16
|
-
comment: !
|
15
|
+
comment: !{count},
|
17
16
|
...!{JSON.stringify(option)}
|
18
|
-
};
|
19
|
-
const walineInstance = Fn(walineOptions);
|
20
|
-
|
21
|
-
utils.addGlobalFn('pjax', () => walineInstance.destroy(), 'destroyWaline');
|
22
|
-
|
23
|
-
if (GLOBAL_CONFIG.lightbox) {
|
24
|
-
utils.lightbox(document.querySelectorAll('#comment .wl-content img:not(.wl-emoji)'));
|
25
17
|
}
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
18
|
+
const walineInstance = initFn(walineOptions)
|
19
|
+
utils.addGlobalFn('pjax', () => walineInstance.destroy(), 'destroyWaline')
|
20
|
+
GLOBAL_CONFIG.lightbox && utils.lightbox(document.querySelectorAll('#comment .wl-content img:not(.wl-emoji)'))
|
21
|
+
sco.owoBig()
|
30
22
|
}
|
31
23
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
24
|
+
async function loadWaline() {
|
25
|
+
if (walineInitFunction) initWaline(walineInitFunction)
|
26
|
+
else {
|
27
|
+
await utils.getCSS('!{url_for(theme.cdn.waline_css)}')
|
28
|
+
const {init} = await import('!{url_for(theme.cdn.waline_js)}')
|
29
|
+
walineInitFunction = init || Waline.init
|
30
|
+
initWaline(walineInitFunction)
|
31
|
+
window.walineFn = walineInitFunction
|
32
|
+
}
|
33
|
+
if (!{commentBarrage}) getBarrage()
|
36
34
|
}
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
};
|
44
|
-
|
45
|
-
for (const [key, value] of Object.entries(params)) {
|
46
|
-
url.searchParams.append(key, value);
|
47
|
-
}
|
36
|
+
if ('!{use[0]}' === 'Valine' || !{lazyload}) {
|
37
|
+
if (!{lazyload}) utils.loadComment(document.getElementById('waline-wrap'), loadWaline)
|
38
|
+
else loadWaline()
|
39
|
+
} else window.loadTwoComment = loadWaline
|
40
|
+
}()
|
48
41
|
|
42
|
+
if commentBarrage
|
43
|
+
script.
|
44
|
+
async function getBarrage() {
|
45
|
+
const url = new URL('!{envId}/api/comment')
|
46
|
+
const params = {path: window.location.pathname, sortBy: 'insertedAt_asc'}
|
47
|
+
Object.entries(params).forEach(([key, value]) => url.searchParams.append(key, value))
|
49
48
|
try {
|
50
49
|
const response = await fetch(url, {
|
51
50
|
method: "GET",
|
52
51
|
headers: {
|
53
52
|
"Content-Type": "application/json"
|
54
53
|
},
|
55
|
-
})
|
56
|
-
|
57
|
-
if (!response.ok) {
|
58
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
59
|
-
}
|
60
|
-
|
54
|
+
})
|
55
|
+
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`)
|
61
56
|
const data = await response.json();
|
62
|
-
|
57
|
+
await utils.getScript('!{url_for(theme.cdn.commentBarrage)}')
|
58
|
+
initializeCommentBarrage(data.data.map(item => ({
|
63
59
|
nick: item.nick,
|
64
60
|
mailId: item.avatar,
|
65
61
|
content: item.comment,
|
66
62
|
id: item.objectId
|
67
|
-
}))
|
63
|
+
})))
|
68
64
|
} catch (error) {
|
69
|
-
console.error("An error occurred while fetching comments: ", error)
|
65
|
+
console.error("An error occurred while fetching comments: ", error)
|
70
66
|
}
|
71
|
-
}
|
72
|
-
}
|
67
|
+
}
|
@@ -1,42 +1,39 @@
|
|
1
|
-
- const { server, site, option } = theme.
|
1
|
+
- const { server, site, option } = theme.artalk
|
2
2
|
- const avatarCdn = option !== null && option.gravatar && option.gravatar.mirror
|
3
3
|
- const avatarDefault = option !== null && option.gravatar && (option.gravatar.params || option.gravatar.default)
|
4
4
|
|
5
5
|
script.
|
6
6
|
window.addEventListener('load', () => {
|
7
|
-
const changeContent =
|
7
|
+
const changeContent = content => {
|
8
8
|
if (content === '') return content
|
9
|
-
|
10
9
|
const replacements = [
|
11
10
|
{regex: /<img.*?src="(.*?)"?[^\>]+>/ig, replacement: '[!{_p("console.newest_comment.image")}]'},
|
12
|
-
{
|
11
|
+
{
|
12
|
+
regex: /<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi,
|
13
|
+
replacement: '[!{_p("console.newest_comment.link")}]'
|
14
|
+
},
|
13
15
|
{regex: /<pre><code>.*?<\/pre>/gi, replacement: '[!{_p("console.newest_comment.code")}]'},
|
14
16
|
{regex: /<[^>]+>/g, replacement: ''}
|
15
|
-
]
|
16
|
-
|
17
|
-
content
|
18
|
-
|
19
|
-
return content.length > 150 ? content.substring(0, 150) + '...' : content;
|
17
|
+
]
|
18
|
+
content = replacements.reduce((str, {regex, replacement}) => str.replace(regex, replacement), content)
|
19
|
+
return content.length > 150 ? content.substring(0, 150) + '...' : content
|
20
20
|
}
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
window.lazyLoadInstance && window.lazyLoadInstance.update()
|
38
|
-
window.pjax && window.pjax.refresh()
|
39
|
-
sco && sco.changeTimeFormat(document.querySelectorAll('.aside-list-item time'))
|
21
|
+
const generateHtml = (array, asideList) => {
|
22
|
+
asideList.innerHTML = array.length ? array.map(item => `
|
23
|
+
<div class='aside-list-item'>
|
24
|
+
<a onclick='pjax.loadUrl("${item.url}")' class='thumbnail'>
|
25
|
+
<img src='${item.avatar}' alt='${item.nick}'>
|
26
|
+
<div class='name'><span>${item.nick}</span></div>
|
27
|
+
</a>
|
28
|
+
<div class='content'>
|
29
|
+
<a class='comment' onclick='pjax.loadUrl("${item.url}")'>${item.content}</a>
|
30
|
+
<time class="datetime" datetime="${item.date}"></time>
|
31
|
+
</div>
|
32
|
+
</div>
|
33
|
+
`).join('') : "!{_p('newest_comment.zero')}"
|
34
|
+
window.lazyLoadInstance?.update()
|
35
|
+
window.pjax?.refresh()
|
36
|
+
sco?.changeTimeFormat(document.querySelectorAll('.aside-list-item time'))
|
40
37
|
}
|
41
38
|
|
42
39
|
const getSetting = async () => {
|
@@ -44,55 +41,48 @@ script.
|
|
44
41
|
const res = await fetch('!{server}/api/v2/conf', {method: 'GET'})
|
45
42
|
return await res.json()
|
46
43
|
} catch (e) {
|
47
|
-
console.
|
44
|
+
console.error(e)
|
45
|
+
return null
|
48
46
|
}
|
49
47
|
}
|
50
48
|
|
51
|
-
const
|
52
|
-
method: 'GET',
|
53
|
-
}
|
54
|
-
|
55
|
-
const searchParams = new URLSearchParams({
|
56
|
-
'site_name': "!{site}",
|
57
|
-
'limit': '6',
|
58
|
-
})
|
59
|
-
|
60
|
-
const getComment = async () => {
|
49
|
+
const getComment = async (asideList) => {
|
61
50
|
try {
|
62
|
-
const
|
51
|
+
const searchParams = new URLSearchParams({'site_name': "!{site}", 'limit': '6'})
|
52
|
+
const res = await fetch(`!{server}/api/v2/stats/latest_comments?${searchParams}`, {method: 'GET'})
|
63
53
|
const result = await res.json()
|
64
|
-
const
|
65
|
-
const {mirror, params, default: defaults} =
|
54
|
+
const avatarConfig = await getSetting()
|
55
|
+
const {mirror, params, default: defaults} = avatarConfig.frontend_conf.gravatar
|
66
56
|
const avatarCdn = !{avatarCdn} || mirror
|
67
57
|
let avatarDefault = !{avatarDefault} || params || defaults
|
68
58
|
avatarDefault = avatarDefault.startsWith('d=') ? avatarDefault : `d=${avatarDefault}`
|
69
|
-
const artalk = result.data.map(
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
saveToLocal.set('artalk-newest-comments', artalk, !{theme.comment.newest_comment.storage})
|
79
|
-
generateHtml(artalk)
|
59
|
+
const artalk = result.data.map(e => ({
|
60
|
+
avatar: `${avatarCdn}${e.email_encrypted}?${avatarDefault}`,
|
61
|
+
content: changeContent(e.content_marked),
|
62
|
+
nick: e.nick,
|
63
|
+
url: e.page_key,
|
64
|
+
date: e.date,
|
65
|
+
}))
|
66
|
+
utils.saveToLocal.set('artalk-newest-comments', artalk, !{theme.comment.newest_comment.storage})
|
67
|
+
generateHtml(artalk, asideList)
|
80
68
|
} catch (e) {
|
81
|
-
console.
|
82
|
-
|
69
|
+
console.error(e);
|
70
|
+
asideList.textContent = "!{_p('newest_comment.error')}"
|
83
71
|
}
|
84
|
-
}
|
72
|
+
};
|
85
73
|
|
86
|
-
const newestCommentInit = () => {
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
getComment()
|
93
|
-
}
|
74
|
+
const newestCommentInit = (asideList) => {
|
75
|
+
const data = utils.saveToLocal.get('artalk-newest-comments')
|
76
|
+
if (data) {
|
77
|
+
generateHtml(data, asideList)
|
78
|
+
} else {
|
79
|
+
getComment(asideList)
|
94
80
|
}
|
95
81
|
}
|
96
|
-
|
97
|
-
|
98
|
-
|
82
|
+
|
83
|
+
const $asideList = document.querySelector('#card-newest-comments .aside-list')
|
84
|
+
if ($asideList) {
|
85
|
+
newestCommentInit($asideList)
|
86
|
+
utils.addGlobalFn('pjaxComplete', () => newestCommentInit($asideList), 'artalk_newestComment')
|
87
|
+
}
|
88
|
+
});
|