Skip to content

Commit 7c0665e

Browse files
committed
feat: support set datetime format in home post block (#300)
1 parent 0d23aa6 commit 7c0665e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

layout/_partial/post/post-meta-info.ejs

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ const home_category_limit_number = 3
33
const home_tag_limit_number = 5
44
55
const show_home_post_block_datetime = theme.home.hasOwnProperty('post_datetime') ? !!theme.home.post_datetime : true
6-
const post_datetime_value = (theme.home.hasOwnProperty('post_datetime') ? theme.home?.post_datetime : 'updated') || 'updated'
6+
const home_post_datetime_value = (theme.home.hasOwnProperty('post_datetime') ? theme.home?.post_datetime : 'updated') || 'updated'
7+
const home_post_datetime_format = (theme.home.hasOwnProperty('post_datetime_format') ? theme.home?.post_datetime_format : 'ago') || 'ago'
78
8-
const post_datetime_split_list = post_datetime_value?.split('||')
9+
const post_datetime_split_list = home_post_datetime_value?.split('||')
910
const post_datetime_type = post_datetime_split_list[0]?.trim()?.toLowerCase()
1011
const post_datetime_icon = post_datetime_split_list[1]?.trim()?.toLowerCase()
1112
@@ -20,7 +21,9 @@ const home_post_block_datetime = post_datetime_type === 'created' ? post.date :
2021
<div class="post-meta-info border-box">
2122
<% if (page_type === 'home' && show_home_post_block_datetime) { %>
2223
<span class="meta-info-item border-box">
23-
<i class="icon <%= home_post_block_datetime_icon %>"></i>&nbsp;<span class="home-post-history" data-updated="<%= home_post_block_datetime %>"><%= date(home_post_block_datetime, 'YYYY-MM-DD HH:mm:ss') %></span>
24+
<i class="icon <%= home_post_block_datetime_icon %>"></i>&nbsp;<span class="home-post-history"
25+
data-updated="<%= home_post_block_datetime %>"
26+
><%= date(home_post_block_datetime, home_post_datetime_format === 'ago' ? 'YYYY-MM-DD HH:mm:ss' : home_post_datetime_format) %></span>
2427
</span>
2528
<% } %>
2629

source/js/utils.js

+6
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,12 @@ KEEP.initUtils = () => {
332332

333333
// set how long age in home post block
334334
setHowLongAgoInHome() {
335+
const { post_datetime_format } = KEEP.theme_config?.home || {}
336+
337+
if (post_datetime_format && post_datetime_format !== 'ago') {
338+
return
339+
}
340+
335341
const post = document.querySelectorAll('.post-meta-info .home-post-history')
336342
post &&
337343
post.forEach((v) => {

0 commit comments

Comments
 (0)