From 72e4c1f558c3a0ae7a3730a3b80da11f3e7729a7 Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Sat, 09 Jul 2022 18:00:53 +0800 Subject: [PATCH] fix template upload --- src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java | 39 ++++++++++++++------------------------- 1 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java b/src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java index 783dfe1..436b082 100644 --- a/src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java +++ b/src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java @@ -2,10 +2,14 @@ import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateTime; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import com.xcong.farmer.cms.core.handler.DataParserHandler; import com.xcong.farmer.cms.core.tag.TagsEnum; +import com.xcong.farmer.cms.core.tag.model.TimeTag; import com.xcong.farmer.cms.core.template.Configuration; import com.xcong.farmer.cms.core.template.TemplateConfiguration; import com.xcong.farmer.cms.utils.GroovySingleton; @@ -18,6 +22,8 @@ import org.jsoup.nodes.Element; import org.jsoup.select.Elements; +import java.time.format.DateTimeFormatter; +import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.regex.Matcher; @@ -74,32 +80,7 @@ return false; } - public void staticPath() { - // 设置img的链接访问 - if ("img".equals(this.element.tagName())) { - String src = this.element.attr("src"); - if (StrUtil.isNotBlank(STATIC_URL)) { - this.element.attr("src", STATIC_URL + src); - } - } - - if ("link".equals(this.element.tagName())) { - String src = this.element.attr("href"); - if (StrUtil.isNotBlank(STATIC_URL)) { - this.element.attr("href", STATIC_URL + src); - } - } - - if ("script".equals(this.element.tagName())) { - String src = this.element.attr("src"); - if (StrUtil.isNotBlank(STATIC_URL)) { - this.element.attr("src", STATIC_URL + src); - } - } - } - public void parser() { - staticPath(); // 判断是否为最小节点,如果是且没有特殊标签,则跳过清空 if (!isNeedEmpty()) { return; @@ -183,6 +164,10 @@ this.element.text(result); } else if ("html".equals(key)) { this.element.html(result); + } else if ("time".equals(key)) { + TimeTag time = parserTag(result, TimeTag.class); + String timeStr = DateUtil.format(DateUtil.parse(time.getDate(), DatePattern.NORM_DATETIME_PATTERN), time.getFormat()); + this.element.text(timeStr); } else { this.element.attr(key, result); } @@ -214,6 +199,10 @@ Script parse = groovyShell.parse(group); parse.setBinding(binding); Object evaluate = parse.run(); + if (evaluate instanceof Date) { + evaluate = DateUtil.format((Date) evaluate, DatePattern.NORM_DATETIME_PATTERN); + } + if (evaluate == null) { targetData.put(group, ""); } else { -- Gitblit v1.9.1