-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: 部分css調整和html優化 improvements: 刪除pwa中的theme-color配置,默認生成meta theme-color close #340 improvements: 優化最後更新時間顯示(1小時內顯示 剛剛,1小時到24小時 顯示 xx小時前,1天到365天 顯示 xx天前,365天后直接顯示日期)
- Loading branch information
Showing
23 changed files
with
420 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
layout/includes/third-party/newest-comments/disqus-comment.pug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
script. | ||
window.addEventListener('load', () => { | ||
const changeContent = (content) => { | ||
if (content === '') return content | ||
|
||
content = content.replace(/<[^>]+>/g,"") // remove html tag | ||
content = content.replace(/(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|jpeg|gif|png|webp)/g, '') // remove image link | ||
content = content.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi, '') // remove url | ||
|
||
if (content.length > 150) { | ||
content = content.substring(0,150) + '...' | ||
} | ||
return content | ||
} | ||
|
||
const getDisqusComment = () => { | ||
let disqusArray = [] | ||
$.getJSON('https://disqus.com/api/3.0/forums/listPosts.json?forum=!{theme.newest_comments.disqus.forum}&related=thread&limit=!{theme.newest_comments.limit}&api_key=!{theme.newest_comments.disqus.api_key}', function(data){ | ||
$.each(data.response, (i, item) => { | ||
disqusArray.push({ | ||
'avatar': item.author.avatar.cache, | ||
'content': changeContent(item.message), | ||
'nick': item.author.name, | ||
'url': item.url, | ||
'date': item.createdAt | ||
}) | ||
}) | ||
// set expiry to 10 min | ||
saveToLocal.set('disqus-newest-comments', JSON.stringify(disqusArray), 10/(60*24)) | ||
generateHtml(disqusArray) | ||
}) | ||
} | ||
|
||
const generateHtml = array => { | ||
let result = '' | ||
|
||
for (let i = 0; i < array.length; i++) { | ||
result += '<div class=\'aside-list-item\'>' | ||
|
||
if (!{theme.newest_comments.avatar}) { | ||
result += `<a href='${array[i].url}' class="thumbnail"><img src='${array[i].avatar}'></a>` | ||
} | ||
|
||
result += `<div class='content'> | ||
<a class='comment' href='${array[i].url}'>${array[i].content}</a> | ||
<div class='name'><span>${array[i].nick}</span><time> / ${diffDate(array[i].date, true)}</time></div> | ||
</div></div>` | ||
} | ||
|
||
let $dom = document.querySelector('.card-newest-comments .aside-list') | ||
$dom.innerHTML= result | ||
window.pjax && window.pjax.refresh($dom) | ||
} | ||
|
||
const newestCommentInit = () => { | ||
if (document.querySelector('.card-newest-comments .aside-list')) { | ||
const data = saveToLocal.get('disqus-newest-comments') | ||
if (data) { | ||
generateHtml(JSON.parse(data)) | ||
} else { | ||
getDisqusComment() | ||
} | ||
} | ||
} | ||
|
||
newestCommentInit() | ||
document.addEventListener('pjax:complete', newestCommentInit) | ||
}) | ||
|
||
|
||
|
71 changes: 71 additions & 0 deletions
71
layout/includes/third-party/newest-comments/github-issues.pug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
script. | ||
window.addEventListener('load', () => { | ||
const changeContent = (content) => { | ||
if (content === '') return content | ||
|
||
content = content.replace(/<[^>]+>/g,"") // remove html tag | ||
content = content.replace(/(http(s?):)([/|.|\w|\s|-])*\.(?:jpg|jpeg|gif|png|webp)/g, '') // remove image link | ||
content = content.replace(/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi, '') // remove url | ||
|
||
if (content.length > 150) { | ||
content = content.substring(0,150) + '...' | ||
} | ||
return content | ||
} | ||
|
||
const getGithubIssues = () => { | ||
let githubArray = [] | ||
$.getJSON('https://api.github.com/repos/!{theme.newest_comments.github_issues.repo}/issues/comments?sort=updated&direction=desc&per_page=!{theme.newest_comments.limit}&page=1', (data) => { | ||
$.each(data, (index, item) => { | ||
githubArray.push({ | ||
'avatar': item.user.avatar_url, | ||
'content': changeContent(item.body), | ||
'nick': item.user.login, | ||
'url': item.html_url, | ||
'date': item.updated_at | ||
}) | ||
}) | ||
saveToLocal.set('github-newest-comments', JSON.stringify(githubArray), 10/(60*24)) | ||
generateHtml(githubArray) | ||
}) | ||
} | ||
|
||
const generateHtml = array => { | ||
let result = '' | ||
|
||
for (let i = 0; i < array.length; i++) { | ||
result += '<div class=\'aside-list-item\'>' | ||
|
||
if (!{theme.newest_comments.avatar}) { | ||
result += `<a href='${array[i].url}' class="thumbnail"><img src='${array[i].avatar}'></a>` | ||
} | ||
|
||
result += `<div class='content'> | ||
<a class='comment' href='${array[i].url}'>${array[i].content}</a> | ||
<div class='name'><span>${array[i].nick}</span><time> / ${diffDate(array[i].date, true)}</time></div> | ||
</div></div>` | ||
} | ||
|
||
let $dom = document.querySelector('.card-newest-comments .aside-list') | ||
$dom.innerHTML= result | ||
window.pjax && window.pjax.refresh($dom) | ||
} | ||
|
||
const newestCommentInit = () => { | ||
if (document.querySelector('.card-newest-comments .aside-list')) { | ||
const data = saveToLocal.get('github-newest-comments') | ||
if (data) { | ||
generateHtml(JSON.parse(data)) | ||
} else { | ||
getGithubIssues() | ||
} | ||
} | ||
} | ||
|
||
newestCommentInit() | ||
document.addEventListener('pjax:complete', newestCommentInit) | ||
}) | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
if theme.newest_comments.leancloud.enable | ||
include ./leancloud.pug | ||
else if theme.newest_comments.github_issues.enable | ||
include ./github-issues.pug | ||
else if theme.newest_comments.disqus.enable | ||
include ./disqus-comment.pug |
Oops, something went wrong.