diff --git a/pom.xml b/pom.xml index 780935c6..d4bc1c9a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.otale tale - 1.3.1-beta + 1.3.1 UTF-8 diff --git a/src/main/java/com/tale/controller/admin/TemplateController.java b/src/main/java/com/tale/controller/admin/TemplateController.java new file mode 100644 index 00000000..f9ba1558 --- /dev/null +++ b/src/main/java/com/tale/controller/admin/TemplateController.java @@ -0,0 +1,106 @@ +package com.tale.controller.admin; + +import com.blade.ioc.annotation.Inject; +import com.blade.kit.StringKit; +import com.blade.mvc.Const; +import com.blade.mvc.annotation.*; +import com.blade.mvc.http.HttpMethod; +import com.blade.mvc.http.Request; +import com.blade.mvc.http.Response; +import com.blade.mvc.ui.RestResponse; +import com.tale.controller.BaseController; +import com.tale.extension.Commons; +import com.tale.service.ContentsService; +import com.tale.service.SiteService; +import lombok.extern.slf4j.Slf4j; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 编辑模板 + *

+ * Created by biezhi on 2017/2/21. + */ +@Slf4j +@Path("admin/template") +public class TemplateController extends BaseController { + + @Inject + private ContentsService contentsService; + + @Inject + private SiteService siteService; + + @Route(value = "", method = HttpMethod.GET) + public String index(Request request) { + String themePath = Const.CLASSPATH + File.separatorChar + "templates" + File.separatorChar + "themes" + File.separatorChar + Commons.site_theme(); + try { + List files = Files.list(Paths.get(themePath)) + .map(path -> path.getFileName().toString()) + .filter(path -> path.endsWith(".html")) + .collect(Collectors.toList()); + + List partial = Files.list(Paths.get(themePath + File.separatorChar + "partial")) + .map(path -> path.getFileName().toString()) + .filter(path -> path.endsWith(".html")) + .map(fileName -> "partial/" + fileName) + .collect(Collectors.toList()); + + List statics = Files.list(Paths.get(themePath + File.separatorChar + "static")) + .map(path -> path.getFileName().toString()) + .filter(path -> path.endsWith(".js") || path.endsWith(".css")) + .map(fileName -> "static/" + fileName) + .collect(Collectors.toList()); + + files.addAll(partial); + files.addAll(statics); + + request.attribute("tpls", files); + } catch (IOException e) { + log.error("找不到模板路径"); + } + return "admin/tpl_list"; + } + + @GetRoute("content") + public void getContent(@Param String fileName, Response response) { + try { + String themePath = Const.CLASSPATH + File.separatorChar + "templates" + File.separatorChar + "themes" + File.separatorChar + Commons.site_theme(); + String filePath = themePath + File.separatorChar + fileName; + String content = Files.readAllLines(Paths.get(filePath)).stream().collect(Collectors.joining("\n")); + response.text(content); + } catch (IOException e) { + log.error("获取模板文件失败", e); + } + } + + @Route(value = "save", method = HttpMethod.POST) + @JSON + public RestResponse saveTpl(@Param String fileName, @Param String content) { + if (StringKit.isBlank(fileName)) { + return RestResponse.fail("缺少参数,请重试"); + } + String themePath = Const.CLASSPATH + File.separatorChar + "templates" + File.separatorChar + "themes" + File.separatorChar + Commons.site_theme(); + String filePath = themePath + File.separatorChar + fileName; + try { + if (Files.exists(Paths.get(filePath))) { + byte[] rf_wiki_byte = content.getBytes("UTF-8"); + Files.write(Paths.get(filePath), rf_wiki_byte); + } else { + Files.createFile(Paths.get(filePath)); + byte[] rf_wiki_byte = content.getBytes("UTF-8"); + Files.write(Paths.get(filePath), rf_wiki_byte); + } + return RestResponse.ok(); + } catch (Exception e) { + log.error("写入文件失败", e); + return RestResponse.fail("写入文件失败: " + e.getMessage()); + } + } + +} diff --git a/src/main/java/com/tale/controller/admin/ThemeController.java b/src/main/java/com/tale/controller/admin/ThemeController.java index a019ec24..2d2708f3 100644 --- a/src/main/java/com/tale/controller/admin/ThemeController.java +++ b/src/main/java/com/tale/controller/admin/ThemeController.java @@ -69,7 +69,7 @@ public String index(Request request) { */ @GetRoute(value = "setting") public String setting(Request request) { - String currentTheme = TaleConst.OPTIONS.get("site_theme", "default"); + String currentTheme = Commons.site_theme(); String key = "theme_" + currentTheme + "_options"; String option = optionsService.getOption(key); @@ -94,7 +94,7 @@ public RestResponse saveSetting(Request request) { Map> query = request.parameters(); // theme_milk_options => { } - String currentTheme = TaleConst.OPTIONS.get("site_theme", "default"); + String currentTheme = Commons.site_theme(); String key = "theme_" + currentTheme + "_options"; Map options = new HashMap<>(); diff --git a/src/main/java/com/tale/extension/Theme.java b/src/main/java/com/tale/extension/Theme.java index 988e6dcc..96b0a0f4 100644 --- a/src/main/java/com/tale/extension/Theme.java +++ b/src/main/java/com/tale/extension/Theme.java @@ -680,7 +680,7 @@ public static String comments_num(String noComment, String value) { * @return */ public static String theme_option(String key) { - String theme = Commons.site_option("site_theme", "default"); + String theme = Commons.site_theme(); return TaleConst.OPTIONS.get("theme_" + theme + "_options") .filter(StringKit::isNotBlank) .map((String json) -> { diff --git a/src/main/resources/templates/admin/article_edit.html b/src/main/resources/templates/admin/article_edit.html index e55e1ae3..030e17d0 100644 --- a/src/main/resources/templates/admin/article_edit.html +++ b/src/main/resources/templates/admin/article_edit.html @@ -90,7 +90,7 @@

-
+ @@ -101,12 +101,12 @@

- +
-
diff --git a/src/main/resources/templates/admin/header.html b/src/main/resources/templates/admin/header.html index 8a867ecf..bc53716c 100644 --- a/src/main/resources/templates/admin/header.html +++ b/src/main/resources/templates/admin/header.html @@ -74,6 +74,10 @@ 文章管理 +
  • + 页面管理 +
  • +
  • 文件管理
  • @@ -81,15 +85,15 @@
  • 其他管理
  • diff --git a/src/main/resources/templates/admin/page_list.html b/src/main/resources/templates/admin/page_list.html index f1e6474b..2409df11 100644 --- a/src/main/resources/templates/admin/page_list.html +++ b/src/main/resources/templates/admin/page_list.html @@ -1,4 +1,4 @@ -#include('./header.html',{has_sub:'other', active:'page', title:'页面管理'}) +#include('./header.html',{active:'page', title:'页面管理'})

    文章管理

    diff --git a/src/main/resources/templates/admin/tpl_list.html b/src/main/resources/templates/admin/tpl_list.html new file mode 100644 index 00000000..8c9137f5 --- /dev/null +++ b/src/main/resources/templates/admin/tpl_list.html @@ -0,0 +1,59 @@ +#include('./header.html',{active:'template', title:'编辑模板'}) +
    +
    +

    编辑模板

    +
    +
    + + + + + +
    + +
    +
    +
    + +#include('./footer.html') + + + \ No newline at end of file