feat: 增加 aside 最新評論部件

style: 部分css調整和html優化
improvements: 刪除pwa中的theme-color配置,默認生成meta theme-color  close #340
improvements: 優化最後更新時間顯示(1小時內顯示 剛剛,1小時到24小時 顯示 xx小時前,1天到365天 顯示 xx天前,365天后直接顯示日期)
This commit is contained in:
Jerry
2020-08-29 01:11:11 +08:00
Unverified
parent ee6f62f4bc
commit fe97d2e63f
23 changed files with 420 additions and 86 deletions

View File

@@ -618,9 +618,9 @@ const addCopyright = () => {
* 網頁運行時間
*/
const addRuntime = () => {
const $runtimeCount = $('#webinfo-runtime-count')
const $runtimeCount = $('#runtimeshow')
if ($runtimeCount.length) {
const publishDate = $runtimeCount.attr('publish_date')
const publishDate = $runtimeCount.attr('data-publishDate')
$runtimeCount.text(diffDate(publishDate) + ' ' + GLOBAL_CONFIG.runtime)
}
}
@@ -629,17 +629,12 @@ const addRuntime = () => {
* 最後一次更新時間
*/
const addLastPushDate = () => {
const $lastPushDateItem = $('.webinfo-last-push-date')
const $lastPushDateItem = $('#last-push-date')
if ($lastPushDateItem.length) {
const lastPushDate = $lastPushDateItem.attr('last-push-date')
const diffDay = diffDate(lastPushDate)
if (diffDay < 1) {
$lastPushDateItem.text(GLOBAL_CONFIG.last_push_date.zeroDay)
} else if (diffDay > 365) {
$lastPushDateItem.text(lastPushDate)
} else {
$lastPushDateItem.text(diffDay + ' ' + GLOBAL_CONFIG.last_push_date.suffix)
}
const lastPushDate = $lastPushDateItem.attr('data-lastPushDate')
const diffDay = diffDate(lastPushDate, true)
console.log(diffDay)
$lastPushDateItem.text(diffDay)
}
}
@@ -810,7 +805,7 @@ const refreshFn = function () {
addLightBox()
scrollFn()
GLOBAL_CONFIG.runtime && addRuntime()
GLOBAL_CONFIG.last_push_date !== undefined && addLastPushDate()
addLastPushDate()
addTableWrap()
clickFnOfTagHide()
tabsFn.clickFnOfTabs()

View File

@@ -97,12 +97,26 @@ const initJustifiedGallery = function (selector) {
})
}
const diffDate = d => {
const diffDate = (d, more = false) => {
const dateNow = new Date()
const datePost = new Date(d.replace(/-/g, '/'))
const datePost = new Date(d)
const dateDiff = dateNow.getTime() - datePost.getTime()
const dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000))
return dayDiff
let result
if (more) {
if (dateDiff <= 3600000) { // < 1 hour
result = GLOBAL_CONFIG.date_suffix.one_hour
} else if (dateDiff < 3600000 * 24) { // 1 hour < x < 24 hours
result = Math.floor(dateDiff / 3600000) + ' ' + GLOBAL_CONFIG.date_suffix.hours
} else if (dayDiff >= 1 || dayDiff < 365) { // 1 day < x < 365 days
result = dayDiff + ' ' + GLOBAL_CONFIG.date_suffix.day
} else { // > 365 days
result = d.toLocaleDateString().replace(/\//g, '-')
}
} else {
result = dayDiff
}
return result
}
const loadComment = (dom, callback) => {