From 97641c088c44dd60f63e697466c73613a1c63262 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Sat, 02 Jul 2022 21:37:01 +0800
Subject: [PATCH] Merge branch 'master' of http://120.27.238.55:7000/r/farmer-cms
---
src/main/java/com/xcong/farmer/cms/cms/template/TemplateConfiguration.java | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 105 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/xcong/farmer/cms/cms/template/TemplateConfiguration.java b/src/main/java/com/xcong/farmer/cms/cms/template/TemplateConfiguration.java
new file mode 100644
index 0000000..4162af3
--- /dev/null
+++ b/src/main/java/com/xcong/farmer/cms/cms/template/TemplateConfiguration.java
@@ -0,0 +1,105 @@
+package com.xcong.farmer.cms.cms.template;
+
+import cn.hutool.core.collection.CollUtil;
+import com.xcong.farmer.cms.cms.node.PartNode;
+import com.xcong.farmer.cms.cms.tag.TagsEnum;
+import org.jsoup.nodes.Document;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author wzy
+ * @date 2022-07-01
+ **/
+public class TemplateConfiguration extends Configuration{
+
+ private TemplateLoader templateLoader;
+
+ public TemplateConfiguration(String templatePath, String staticPath, String outputPath) {
+ super(templatePath, staticPath, outputPath);
+ }
+
+ public void templateLoader(TemplateLoader templateLoader) {
+ this.templateLoader = templateLoader;
+ }
+
+ public void process() {
+ if (this.templateLoader == null) {
+ throw new RuntimeException("TemplateLoader do not able to be null");
+ }
+
+ List<Template> templates = templateLoader.templates();
+
+ if (CollUtil.isEmpty(templates)) {
+ return;
+ }
+
+ for (Template template : templates) {
+ output(template);
+ }
+ }
+
+ public List<Template> templates() {
+ return this.templateLoader.templates();
+ }
+
+ public Template template(String templateName) {
+ return template(new File(path(this.templatePath) + templateName));
+ }
+
+ public Template template(File file) {
+ if (file == null) {
+ throw new RuntimeException("template not exist");
+ }
+
+ return this.templateLoader.template(file);
+ }
+
+ public void columnProcess(Long id, String templateName) {
+ Template template = template(templateName);
+ }
+
+ public void columnProcess(String code, String templateName) {
+
+ }
+
+ public void articleProcess(Long id, String templateName) {
+ Map<String, Map<String, Object>> map = new HashMap<>();
+
+ Map<String, Object> data = new HashMap<>();
+ data.put("id", id);
+ map.put(TagsEnum.ARTICLE.getName(), data);
+ }
+
+ 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) {
+ if (!path.endsWith("/")) {
+ path = path + "/";
+ }
+ return path;
+ }
+}
--
Gitblit v1.9.1