posts) {
+ Assert.notEmpty(posts, "post mut not be empty");
+
String head = "\n";
String urlBody = "";
String urlItem;
String urlPath = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/";
for (Post post : posts) {
- urlItem = "" + urlPath + post.getPostUrl() + "" + DateUtil.format(post.getPostDate(), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX") + "" + "";
+ urlItem = "" + urlPath + post.getPostUrl() + ""
+ + DateUtil.format(post.getPostDate(), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX") + "" + "";
urlBody += urlItem;
}
return head + urlBody + "";
@@ -365,6 +374,8 @@ public class HaloUtils {
* @return String
*/
public static String getHttpResponse(String enterUrl) {
+ Assert.hasText(enterUrl, "enter url must not be blank");
+
BufferedReader in = null;
StringBuffer result = null;
try {
@@ -396,7 +407,6 @@ public class HaloUtils {
return null;
}
-
/**
* 百度主动推送
*
@@ -406,29 +416,33 @@ public class HaloUtils {
* @return String
*/
public static String baiduPost(String blogUrl, String token, String urls) {
+ Assert.hasText(blogUrl, "blog url must not be blank");
+ Assert.hasText(token, "token must not be blank");
+ Assert.hasText(urls, "urls must not be blank");
+
String url = "http://data.zz.baidu.com/urls?site=" + blogUrl + "&token=" + token;
String result = "";
PrintWriter out = null;
BufferedReader in = null;
try {
- //建立URL之间的连接
+ // 建立URL之间的连接
URLConnection conn = new URL(url).openConnection();
- //设置通用的请求属性
+ // 设置通用的请求属性
conn.setRequestProperty("Host", "data.zz.baidu.com");
conn.setRequestProperty("User-Agent", "curl/7.12.1");
conn.setRequestProperty("Content-Length", "83");
conn.setRequestProperty("Content-Type", "text/plain");
- //发送POST请求必须设置如下两行
+ // 发送POST请求必须设置如下两行
conn.setDoInput(true);
conn.setDoOutput(true);
- //获取conn对应的输出流
+ // 获取conn对应的输出流
out = new PrintWriter(conn.getOutputStream());
out.print(urls.trim());
- //进行输出流的缓冲
+ // 进行输出流的缓冲
out.flush();
- //通过BufferedReader输入流来读取Url的响应
+ // 通过BufferedReader输入流来读取Url的响应
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
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