mirror of
https://github.com/jerryc127/hexo-theme-butterfly.git
synced 2026-04-17 04:40:53 +08:00
Fixed: 修復相關文章 日期顯示錯誤bug
This commit is contained in:
@@ -1,9 +1,4 @@
|
|||||||
const moment = require('moment-timezone');
|
const moment = require('moment');
|
||||||
const {
|
|
||||||
isMoment
|
|
||||||
} = moment;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
|
hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
|
||||||
var relatedPosts = [];
|
var relatedPosts = [];
|
||||||
@@ -16,7 +11,7 @@ hexo.extend.helper.register('related_posts', function (currentPost, allPosts) {
|
|||||||
cover: post.cover,
|
cover: post.cover,
|
||||||
weight: 1,
|
weight: 1,
|
||||||
updated: post.updated,
|
updated: post.updated,
|
||||||
created: post.created
|
created: post.date
|
||||||
};
|
};
|
||||||
var index = findItem(relatedPosts, 'path', post.path);
|
var index = findItem(relatedPosts, 'path', post.path);
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
@@ -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 += '<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 + '">';
|
result += '<img class="relatedPosts_cover ' + lazy_class + '"' + lazy_src + '="' + cover + '">';
|
||||||
if (date_type == 'created') {
|
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 {
|
} 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 class="relatedPosts_title">' + relatedPosts[i].title + '</div>';
|
||||||
result += '</div></a></div>'
|
result += '</div></a></div>'
|
||||||
@@ -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) {
|
function isTagRelated(tagName, TBDtags) {
|
||||||
var result = false;
|
var result = false;
|
||||||
@@ -108,14 +100,8 @@ function compare(attr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dateHelper(date) {
|
function date(date) {
|
||||||
const moment = getMoment(date, hexo.theme.config.rootConfig.language);
|
var config = hexo.theme.config.rootConfig
|
||||||
return moment.format(hexo.theme.config.rootConfig.date_format);
|
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;
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user