Helius
2022-07-07 95ef76d6440a5363c0b7981b1333f82f9345322d
fix template upload
7 files modified
55 ■■■■■ changed files
src/main/java/com/xcong/farmer/cms/configurations/CmsConfig.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java 9 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/core/template/Configuration.java 17 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/CmsTemplateServiceImpl.java 9 ●●●●● patch | view | raw | blame | history
src/main/resources/application-test.yml 10 ●●●● patch | view | raw | blame | history
src/main/resources/application.yml 4 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/farmer/cms/configurations/CmsConfig.java
@@ -23,7 +23,7 @@
    @Bean
    public TemplateConfiguration templateConfiguration() {
        log.info("CMS管理系统");
        TemplateConfiguration cfg = new TemplateConfiguration(cmsProperties.getTemplatePath(), cmsProperties.getStaticPath(), cmsProperties.getOutputPath());
        TemplateConfiguration cfg = new TemplateConfiguration(cmsProperties.getTemplatePath(), cmsProperties.getStaticPath(), cmsProperties.getOutputPath(), cmsProperties.getBaseUrl(), cmsProperties.getStaticUrl());
        TemplateLoader loader = new TemplateLoader(cfg);
        cfg.templateLoader(loader);
        return cfg;
src/main/java/com/xcong/farmer/cms/core/node/AttrNode.java
@@ -2,6 +2,7 @@
import cn.hutool.core.collection.CollUtil;
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;
@@ -77,6 +78,14 @@
        }
        this.element.empty();
        // 设置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);
            }
        }
        Attributes attributes = this.element.attributes();
        if (attributes.isEmpty()) {
            return;
src/main/java/com/xcong/farmer/cms/core/template/Configuration.java
@@ -6,17 +6,20 @@
public abstract class Configuration {
    public String staticPath;
    public String templatePath;
    public String outputPath;
    protected static String BASE_URL;
    protected static String STATIC_URL;
    protected static String staticPath;
    protected static String templatePath;
    protected static String outputPath;
    public Configuration() {
    }
    public Configuration(String templatePath, String staticPath, String outputPath) {
        this.staticPath = staticPath;
        this.templatePath = templatePath;
        this.outputPath = outputPath;
    public Configuration(String templatePath, String staticPath, String outputPath, String baseUrl, String staticUrl) {
        Configuration.staticPath = staticPath;
        Configuration.templatePath = templatePath;
        Configuration.outputPath = outputPath;
        Configuration.BASE_URL = baseUrl;
    }
    public static Map<String, String> templateCode = new HashMap<>();
src/main/java/com/xcong/farmer/cms/core/template/TemplateConfiguration.java
@@ -18,8 +18,8 @@
    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) {
src/main/java/com/xcong/farmer/cms/modules/system/service/Impl/CmsTemplateServiceImpl.java
@@ -45,14 +45,14 @@
public class CmsTemplateServiceImpl extends ServiceImpl<CmsTemplateMapper, CmsTemplateEntity> implements ICmsTemplateService {
    @Autowired
    private TemplateConfiguration cfg;
    private CmsProperties properties;
    private List<String> fileSuffix = Arrays.asList(".zip", ".html");
    @Override
    public void updateTemplate(MultipartFile upload) {
        String templatePath = cfg.templatePath;
        String staticPath = cfg.staticPath;
        String templatePath = properties.getTemplatePath();
        String staticPath = properties.getStaticPath();
        String filename = upload.getOriginalFilename();
        String suffix = filename.substring(filename.lastIndexOf("."));
@@ -78,6 +78,7 @@
                for (File templateFile : files) {
                    if (!templateFile.isFile()) {
                        FileUtil.move(templateFile, new File(FileUtils.path(staticPath, templateFile.getName())), true);
                        continue;
                    }
@@ -86,7 +87,7 @@
                    }
                    String name = templateFile.getName();
                    if (!name.endsWith(".list.html") && !name.endsWith(".article.html") && !name.endsWith(".index.html")) {
                    if (!name.endsWith(".list.html") && !name.endsWith(".article.html") && !name.endsWith("index.html")) {
                        continue;
                    }
src/main/resources/application-test.yml
@@ -93,9 +93,9 @@
    path: /home/javaweb/webresource/uploadeFile/image/
cms:
  base-url: http://localhost
  static-url: http://localhost
  template-path: /Users/helius/Desktop/template
  static-path:
  output-path: /Users/helius/Desktop/web/output
  base-url: http://120.27.238.55:8000/cms/output
  static-url: http://120.27.238.55:8000/cms/static
  template-path: /home/javaweb/webresource/cms/template
  static-path: /home/javaweb/webresource/cms/static
  output-path: /home/javaweb/webresource/cms/output
src/main/resources/application.yml
@@ -99,7 +99,7 @@
cms:
  base-url: http://localhost
  static-url: http://localhost
  template-path: /Users/helius/Desktop/template
  static-path:
  template-path: /Users/helius/Desktop/template/upload
  static-path: /Users/helius/Desktop/static
  output-path: /Users/helius/Desktop/web/output