From 4226bfc255dd827f8c90bb7a9cc6aa4649925de9 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Mon, 11 Jul 2022 14:32:19 +0800
Subject: [PATCH] fix
---
src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java | 52 ++++++++++++++++++----------------------------------
1 files changed, 18 insertions(+), 34 deletions(-)
diff --git a/src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java b/src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java
index f6b078a..1c3b7f6 100644
--- a/src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java
+++ b/src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java
@@ -2,6 +2,7 @@
import com.xcong.farmer.cms.core.node.PartNode;
import com.xcong.farmer.cms.core.node.Template;
+import lombok.extern.slf4j.Slf4j;
import org.jsoup.nodes.Document;
import java.io.File;
@@ -14,12 +15,13 @@
* @author wzy
* @date 2022-07-01
**/
+@Slf4j
public class TemplateConfiguration extends Configuration{
private TemplateLoader templateLoader;
- public TemplateConfiguration(String templatePath, String staticPath, String outputPath) {
- super(templatePath, staticPath, outputPath);
+ public TemplateConfiguration(String templatePath, String staticPath, String outputPath, String baseUrl, String staticUrl) {
+ super(templatePath, staticPath, outputPath, baseUrl, staticUrl);
}
public void templateLoader(TemplateLoader templateLoader) {
@@ -31,13 +33,24 @@
throw new RuntimeException("TemplateLoader do not able to be null");
}
+ log.info("解析开始执行--#类型:{}#--#模板名称:{}#--#ID:{}#", map.get("templateType"), templateName, map.get("id"));
this.templateLoader.data(map);
- output(template(templateName));
+ Template template = template(templateName);
+ template.output(outputPath);
+
+ // 判断是否有分页,有则执行。从第二页开始
+ int i = 2;
+ while(Template.HAS_PAGING) {
+ map.put("page", i);
+ this.templateLoader.data(map);
+ Template pageTemplate = template(templateName);
+ pageTemplate.output(outputPath);
+ i++;
+ }
}
-
public Template template(String templateName) {
- return template(new File(path(this.templatePath) + templateName));
+ return template(new File(path(templatePath) + templateName));
}
public Template template(File file) {
@@ -46,35 +59,6 @@
}
return this.templateLoader.template(file);
- }
-
-// public void columnProcess(Map<String, Object> data, String templateName) {
-// process;
-// }
-//
-//
-// public void articleProcess(Map<String, Object> data, String templateName) {
-// process(data, templateName);
-// }
-
- public void output(Template template) {
- Document document = template.getDocument();
- List<PartNode> partNodes = template.getPartNodes();
- StringBuilder sb = new StringBuilder();
- for (PartNode partNode : partNodes) {
- sb.append(partNode.getHtml());
- }
- document.body().empty().html(sb.toString());
- String outPath = path(this.outputPath);
-
- String html = document.html();
- try {
- FileOutputStream outputStream = new FileOutputStream(outPath + template.getName());
- outputStream.write(html.getBytes());
- outputStream.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
}
private String path(String path) {
--
Gitblit v1.9.1