Skip to content

Commit

Permalink
Fixed: 修復相關文章 日期顯示錯誤bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jerryc127 committed Dec 31, 2019
1 parent c002fd0 commit 24269f4
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions scripts/related_post.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
const moment = require('moment-timezone');
const {
isMoment
} = moment;


const moment = require('moment');

hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
var relatedPosts = [];
Expand All @@ -16,7 +11,7 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
cover: post.cover,
weight: 1,
updated: post.updated,
created: post.created
created: post.date
};
var index = findItem(relatedPosts, 'path', post.path);
if (index != -1) {
Expand Down Expand Up @@ -64,9 +59,9 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
result += '<div class="relatedPosts_item"><a href="' + hexoConfig.root + relatedPosts[i].path + '" title="' + relatedPosts[i].title + '">';
result += '<img class="relatedPosts_cover ' + lazy_class + '"' + lazy_src + '="' + cover + '">';
if (date_type == 'created') {
result += '<div class="relatedPosts_main is-center"><div class="relatedPosts_date"><i class="fa fa-calendar fa-fw" aria-hidden="true"></i>' + ' ' + dateHelper(relatedPosts[i].created) + '</div>'
result += '<div class="relatedPosts_main is-center"><div class="relatedPosts_date"><i class="fa fa-calendar fa-fw" aria-hidden="true"></i>' + ' ' + date(relatedPosts[i].created) + '</div>'
} else {
result += '<div class="relatedPosts_main"><div class="relatedPosts_date"><i class="fa fa-history fa-fw" aria-hidden="true"></i>' + ' ' + dateHelper(relatedPosts[i].updated) + '</div>'
result += '<div class="relatedPosts_main is-center"><div class="relatedPosts_date"><i class="fa fa-history fa-fw" aria-hidden="true"></i>' + ' ' + date(relatedPosts[i].updated) + '</div>'
}
result += '<div class="relatedPosts_title">' + relatedPosts[i].title + '</div>';
result += '</div></a></div>'
Expand All @@ -77,9 +72,6 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {

}
});
hexo.extend.helper.register('echo', function (path) {
return path;
});

function isTagRelated(tagName, TBDtags) {
var result = false;
Expand Down Expand Up @@ -108,14 +100,8 @@ function compare(attr) {
}
}

function dateHelper(date) {
const moment = getMoment(date, hexo.theme.config.rootConfig.language);
return moment.format(hexo.theme.config.rootConfig.date_format);
function date(date) {
var config = hexo.theme.config.rootConfig
moment.locale(config.language)
return moment(date).format(config.date_format)
}

function getMoment(date, lang) {
if (date == null) date = moment();
if (!isMoment(date)) date = moment(isDate(date) ? date : new Date(date));
if (lang) date = date.locale(lang);
return date;
}

0 comments on commit 24269f4

Please sign in to comment.