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.
Files changed (33) hide show
  1. package/README.md +25 -25
  2. package/{README_zh-cn.md → README_en.md} +25 -25
  3. package/README_zh-tw.md +3 -3
  4. package/_config.yml +41 -34
  5. package/layout/includes/body/mode.pug +6 -3
  6. package/layout/includes/head/config.pug +0 -33
  7. package/layout/includes/head/page_config.pug +9 -0
  8. package/layout/includes/head.pug +4 -1
  9. package/layout/includes/inject/body.pug +1 -26
  10. package/layout/includes/inject/head.pug +11 -60
  11. package/layout/includes/widgets/post/postMeta.pug +24 -24
  12. package/layout/includes/widgets/third-party/comments/artalk.pug +29 -18
  13. package/layout/includes/widgets/third-party/comments/comment.pug +48 -12
  14. package/layout/includes/widgets/third-party/comments/twikoo.pug +61 -39
  15. package/layout/includes/widgets/third-party/comments/valine.pug +36 -38
  16. package/layout/includes/widgets/third-party/comments/waline.pug +39 -44
  17. package/layout/includes/widgets/third-party/news-comment/artalk.pug +57 -67
  18. package/layout/includes/widgets/third-party/news-comment/newest-comment.pug +6 -6
  19. package/layout/includes/widgets/third-party/news-comment/twikoo.pug +41 -48
  20. package/layout/includes/widgets/third-party/news-comment/valine.pug +5 -5
  21. package/layout/includes/widgets/third-party/news-comment/waline.pug +3 -3
  22. package/layout/includes/widgets/third-party/pjax.pug +1 -0
  23. package/package.json +1 -1
  24. package/plugins.yml +2 -2
  25. package/scripts/event/merge_config.js +280 -255
  26. package/scripts/filter/comment.js +13 -0
  27. package/source/css/_comments/comment.styl +73 -12
  28. package/source/css/_comments/valine.styl +1 -1
  29. package/source/css/_highlight/index.styl +1 -0
  30. package/source/css/_tags/link.styl +7 -2
  31. package/source/js/main.js +42 -18
  32. package/source/js/tw_cn.js +3 -3
  33. package/source/js/utils.js +62 -0
@@ -1,18 +1,17 @@
1
- - const { server, site, option } = theme.comment.artalk
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
- async function initComment() {
5
+ !function () {
6
6
  let artalkItem = null
7
7
  const initArtalk = () => {
8
8
  artalkItem = Artalk.init({
9
- el: '#comment',
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
- GLOBAL_CONFIG.comment.commentBarrage && PAGE_CONFIG.comment && initializeCommentBarrage(array)
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('comment')
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
- initArtalk()
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
- span
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
- #comment
9
- case theme.comment.type
10
- when 'twikoo'
11
- !=partial('includes/widgets/third-party/comments/twikoo',{}, {cache: true})
12
- when 'waline'
13
- !=partial('includes/widgets/third-party/comments/waline',{}, {cache: true})
14
- when 'valine'
15
- !=partial('includes/widgets/third-party/comments/valine',{}, {cache: true})
16
- when 'artalk'
17
- !=partial('includes/widgets/third-party/comments/artalk',{}, {cache: true})
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
- async function initComment() {
3
- const initOptions = Object.assign(
4
- !{JSON.stringify(theme.comment.twikoo || {})},
5
- {
6
- el: '#comment',
7
- onCommentLoaded: async function () {
8
- GLOBAL_CONFIG.lightbox && utils.lightbox(document.querySelectorAll('#twikoo .tk-content img:not(.tk-owo-emotion)'))
9
- sco.owoBig()
10
- GLOBAL_CONFIG.comment.commentBarrage && PAGE_CONFIG.comment && initializeCommentBarrage(await fetchComments())
11
- },
12
- lang: '#{theme.comment.twikoo.lang}',
13
- }
14
- )
15
- await twikoo.init(initOptions)
16
- if (#{theme.post.meta.comment && is_post()}) {
17
- var countOptions = Object.assign(
18
- !{JSON.stringify(theme.comment.twikoo || {})},
19
- {
20
- urls: [window.location.pathname],
21
- includeReply: false
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
- const res = await twikoo.getCommentsCount(countOptions)
25
- try {
26
- document.getElementById('twikoo-count').innerText = res[0].count
27
- document.querySelector('.comment-headline span:last-child').innerText = ` (${res[0].count})`
28
- } catch (e) {
29
- document.getElementById('twikoo-count').innerText = '加载错误'
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
- async function fetchComments() {
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("!{theme.comment.twikoo.envId}", {
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: "!{theme.comment.twikoo.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
- return (data.data).map(item => Object.assign({
51
- content: item.comment,
52
- nick: item.nick,
53
- mailMd5: item.mailMd5,
54
- id: item.id
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.comment.valine
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
- async function initComment() {
10
- const initValine = async () => {
11
- const valine = new Valine(Object.assign({
12
- el: '#comment',
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
- if (GLOBAL_CONFIG.lightbox) {
24
- utils.lightbox(document.querySelectorAll('#comment .vcontent img:not(.vemoji)'));
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
- if (!!{lazyload}) {
32
- if (!{lazyload}) utils.loadComment(document.getElementById('comment'), initValine)
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
- await initValine()
36
+ window.loadTwoComment = loadValine
36
37
  }
38
+ }()
37
39
 
38
- async function fetchComments() {
39
- const url = new URL('#{serverURLs}' + '/1.1/classes/Comment');
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": '#{appKey}',
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
- const data = await response.json();
64
- return (data.results.filter(item => item.url === window.location.pathname)).map(item =>
65
- Object.assign({
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
- async function initComment() {
6
- const isLazyLoad = !!{lazyload};
7
- let walineInitFunction = window.walineFn || null;
5
+ !function () {
6
+ let walineInitFunction = window.walineFn || null
8
7
 
9
- async function initWaline(Fn) {
8
+ function initWaline(initFn) {
10
9
  const walineOptions = {
11
- el: '#comment',
10
+ el: '#waline-wrap',
12
11
  serverURL: '!{envId}',
13
- pageview: !isLazyLoad,
12
+ pageview: !{pageview},
14
13
  dark: 'html[data-theme="dark"]',
15
14
  path: window.location.pathname,
16
- comment: !isLazyLoad,
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
- sco.owoBig();
28
-
29
- GLOBAL_CONFIG.comment.commentBarrage && PAGE_CONFIG.comment && initializeCommentBarrage(await fetchComments())
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
- if (isLazyLoad) {
33
- utils.loadComment(document.getElementById('comment'), initWaline(walineInitFunction));
34
- } else {
35
- await initWaline(walineInitFunction);
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
- async function fetchComments() {
39
- const url = new URL('#{envId}/api/comment');
40
- const params = {
41
- path: window.location.pathname,
42
- sortBy: 'insertedAt_asc'
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
- return (data.data).map(item => Object.assign({
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.comment.artalk
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 = (content) => {
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
- {regex: /<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi,replacement: '[!{_p("console.newest_comment.link")}]'},
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 = replacements.reduce((str, {regex, replacement}) => str.replace(regex, replacement), 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
- const $asideList = document.querySelector('#card-newest-comments .aside-list')
23
-
24
- const generateHtml = array => {
25
- $asideList.innerHTML = array.length ? array.map(item => `
26
- <div class='aside-list-item'>
27
- <a onclick='pjax.loadUrl("${item.url}")' class='thumbnail'>
28
- <img src='${item.avatar}' alt='${item.nick}'>
29
- <div class='name'><span>${item.nick}</span></div>
30
- </a>
31
- <div class='content'>
32
- <a class='comment' onclick='pjax.loadUrl("${item.url}")'>${item.content}</a>
33
- <time class="datetime" datetime="${item.date}"></time>
34
- </div>
35
- </div>
36
- `).join('') : "!{_p('newest_comment.zero')}"
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.log(e)
44
+ console.error(e)
45
+ return null
48
46
  }
49
47
  }
50
48
 
51
- const headerList = {
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 res = await fetch(`!{server}/api/v2/stats/latest_comments?${searchParams}`, headerList)
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 avatarStr = await getSetting()
65
- const {mirror, params, default: defaults} = avatarStr.frontend_conf.gravatar
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(function (e) {
70
- return {
71
- 'avatar': `${avatarCdn}${e.email_encrypted}?${avatarDefault}`,
72
- 'content': changeContent(e.content_marked),
73
- 'nick': e.nick,
74
- 'url': e.page_url,
75
- 'date': e.date,
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.log(e)
82
- $asideList.textContent = "!{_p('newest_comment.error')}"
69
+ console.error(e);
70
+ asideList.textContent = "!{_p('newest_comment.error')}"
83
71
  }
84
- }
72
+ };
85
73
 
86
- const newestCommentInit = () => {
87
- if ($asideList) {
88
- const data = saveToLocal.get('artalk-newest-comments')
89
- if (data) {
90
- generateHtml(data)
91
- } else {
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
- newestCommentInit()
97
- utils.addGlobalFn('pjaxComplete', newestCommentInit, 'artalk_newestComment')
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
+ });