From cd0513cf9aca6ecb510c1b8c4d2efd69dd4c4c21 Mon Sep 17 00:00:00 2001
From: ruibaby
Date: Wed, 31 Oct 2018 10:17:55 +0800
Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BB=AA=E8=A1=A8=E7=9B=98=E6=A0=B7?=
=?UTF-8?q?=E5=BC=8F=E4=BC=98=E5=8C=96?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/resources/templates/admin/admin_index.ftl | 4 ++--
.../resources/templates/admin/module/_header.ftl | 2 +-
.../resources/templates/admin/module/_macro.ftl | 1 +
.../templates/common/macro/common_macro.ftl | 14 ++++++++++++++
4 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/src/main/resources/templates/admin/admin_index.ftl b/src/main/resources/templates/admin/admin_index.ftl
index 7c8134694..2ca151435 100755
--- a/src/main/resources/templates/admin/admin_index.ftl
+++ b/src/main/resources/templates/admin/admin_index.ftl
@@ -238,7 +238,7 @@
<@spring.message code='common.status.recycle-bin' />
#if>
-
${post.postDate?if_exists?string("yyyy-MM-dd HH:mm")} |
+ <@common.timeline datetime="${post.postDate?if_exists}"?datetime /> |
#list>
<#else>
@@ -310,7 +310,7 @@
<#break >
#switch>
- ${comment.commentDate?string("yyyy-MM-dd HH:mm")} |
+ <@common.timeline datetime="${comment.commentDate}"?datetime /> |
#list>
<#else>
diff --git a/src/main/resources/templates/admin/module/_header.ftl b/src/main/resources/templates/admin/module/_header.ftl
index c206cdd53..4dc05b25d 100755
--- a/src/main/resources/templates/admin/module/_header.ftl
+++ b/src/main/resources/templates/admin/module/_header.ftl
@@ -35,7 +35,7 @@
${comment.commentAuthor}
- ${comment.commentDate?string("yyyy/MM/dd HH:mm")}
+ <@common.timeline datetime="${comment.commentDate}"?datetime />
diff --git a/src/main/resources/templates/admin/module/_macro.ftl b/src/main/resources/templates/admin/module/_macro.ftl
index 0b060fe90..2c6cfd914 100644
--- a/src/main/resources/templates/admin/module/_macro.ftl
+++ b/src/main/resources/templates/admin/module/_macro.ftl
@@ -1,4 +1,5 @@
<#macro head>
+<#import "/common/macro/common_macro.ftl" as common>
diff --git a/src/main/resources/templates/common/macro/common_macro.ftl b/src/main/resources/templates/common/macro/common_macro.ftl
index 896e372c5..6c56888d1 100644
--- a/src/main/resources/templates/common/macro/common_macro.ftl
+++ b/src/main/resources/templates/common/macro/common_macro.ftl
@@ -31,4 +31,18 @@
<#if options.blog_verification_qihu??>
#if>
+#macro>
+
+<#-- 时间格式化 几...前 -->
+<#macro timeline datetime=.now>
+ <#assign ct = (.now?long-datetime?long)/1000>
+ <#if ct gte 31104000>${(ct/31104000)?int}年前
+ <#t><#elseif ct gte 2592000>${(ct/2592000)?int}个月前
+ <#t><#elseif ct gte 86400*2>${(ct/86400)?int}天前
+ <#t><#elseif ct gte 86400>昨天
+ <#t><#elseif ct gte 3600>${(ct/3600)?int}小时前
+ <#t><#elseif ct gte 60>${(ct/60)?int}分钟前
+ <#t><#elseif ct gt 0>${ct?int}秒前
+ <#t><#else>刚刚
+ #if>
#macro>
\ No newline at end of file