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 @@
-