diff --git a/src/main/java/run/halo/app/listener/StartedListener.java b/src/main/java/run/halo/app/listener/StartedListener.java index fddd7fcbf..f8c6e018e 100644 --- a/src/main/java/run/halo/app/listener/StartedListener.java +++ b/src/main/java/run/halo/app/listener/StartedListener.java @@ -111,7 +111,7 @@ public class StartedListener implements ApplicationListener { @NonNull Locale getLocale(); - /** - * Gets current active theme. - * - * @return current active theme - */ - @NonNull - String getTheme(); - } diff --git a/src/main/java/run/halo/app/service/ThemeService.java b/src/main/java/run/halo/app/service/ThemeService.java index 1911e2fa7..fa3cb5e05 100644 --- a/src/main/java/run/halo/app/service/ThemeService.java +++ b/src/main/java/run/halo/app/service/ThemeService.java @@ -129,4 +129,12 @@ public interface ThemeService { @NonNull String render(@NonNull String pageName); + /** + * Gets current theme name. + * + * @return current theme name + */ + @NonNull + String getTheme(); + } diff --git a/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java b/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java index 2e8d11a07..bf1f26b75 100644 --- a/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/OptionServiceImpl.java @@ -290,9 +290,4 @@ public class OptionServiceImpl extends AbstractCrudService impl } }).orElseGet(Locale::getDefault); } - - @Override - public String getTheme() { - return getByProperty(PrimaryProperties.THEME).orElse(DEFAULT_THEME_NAME); - } } diff --git a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java index e37dbee87..061d53844 100644 --- a/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/ThemeServiceImpl.java @@ -9,11 +9,11 @@ import cn.hutool.setting.dialect.Props; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import lombok.extern.slf4j.Slf4j; -import org.springframework.lang.NonNull; import org.springframework.stereotype.Service; import org.springframework.util.Assert; import run.halo.app.config.properties.HaloProperties; import run.halo.app.exception.NotFoundException; +import run.halo.app.model.properties.PrimaryProperties; import run.halo.app.model.support.HaloConst; import run.halo.app.model.support.Theme; import run.halo.app.model.support.ThemeFile; @@ -31,6 +31,8 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import static run.halo.app.model.support.HaloConst.DEFAULT_THEME_NAME; + /** * @author : RYAN0UP * @date : 2019/3/26 @@ -206,7 +208,7 @@ public class ThemeServiceImpl implements ThemeService { */ @Override public boolean isTemplateExist(String template) { - StrBuilder templatePath = new StrBuilder(getThemeName()); + StrBuilder templatePath = new StrBuilder(getTheme()); templatePath.append("/"); templatePath.append(template); File file = new File(getThemeBasePath(), templatePath.toString()); @@ -332,16 +334,12 @@ public class ThemeServiceImpl implements ThemeService { @Override public String render(String pageName) { - return String.format(RENDER_TEMPLATE, optionService.getTheme(), pageName); + return String.format(RENDER_TEMPLATE, getTheme(), pageName); } - /** - * Gets theme name. - * - * @return theme name. - */ - @NonNull - private String getThemeName() { - return optionService.getTheme(); + @Override + public String getTheme() { + return optionService.getByProperty(PrimaryProperties.THEME).orElse(DEFAULT_THEME_NAME); } + } diff --git a/src/main/java/run/halo/app/web/controller/admin/api/ThemeController.java b/src/main/java/run/halo/app/web/controller/admin/api/ThemeController.java index 1b83e447a..7e8fe1720 100644 --- a/src/main/java/run/halo/app/web/controller/admin/api/ThemeController.java +++ b/src/main/java/run/halo/app/web/controller/admin/api/ThemeController.java @@ -56,7 +56,7 @@ public class ThemeController { */ @GetMapping("files") public List listFiles() { - return themeService.listThemeFolderBy(optionService.getTheme()); + return themeService.listThemeFolderBy(themeService.getTheme()); } @GetMapping("files/content") @@ -72,7 +72,7 @@ public class ThemeController { @GetMapping("files/custom") public List customTemplate() { - return themeService.getCustomTpl(optionService.getTheme()); + return themeService.getCustomTpl(themeService.getTheme()); } /** @@ -103,7 +103,7 @@ public class ThemeController { @GetMapping("configurations") @ApiOperation("Fetches theme configuration") - public BaseResponse fetchConfig(@RequestParam("name") String name) { - return BaseResponse.ok(themeService.fetchConfig(name)); + public BaseResponse fetchConfig() { + return BaseResponse.ok(themeService.fetchConfig(themeService.getTheme())); } } diff --git a/src/main/java/run/halo/app/web/controller/content/base/BaseContentController.java b/src/main/java/run/halo/app/web/controller/content/base/BaseContentController.java deleted file mode 100644 index f14e3a6f1..000000000 --- a/src/main/java/run/halo/app/web/controller/content/base/BaseContentController.java +++ /dev/null @@ -1,11 +0,0 @@ -package run.halo.app.web.controller.content.base; - -/** - * Content base Controller - * - * @author : RYAN0UP - * @date : 2017/12/15 - */ -public abstract class BaseContentController { - -} diff --git a/src/main/java/run/halo/app/web/controller/core/CommonController.java b/src/main/java/run/halo/app/web/controller/core/CommonController.java index ea5422170..1dd025578 100644 --- a/src/main/java/run/halo/app/web/controller/core/CommonController.java +++ b/src/main/java/run/halo/app/web/controller/core/CommonController.java @@ -114,7 +114,7 @@ public class CommonController implements ErrorController { return "common/error/404"; } StrBuilder path = new StrBuilder("themes/"); - path.append(optionService.getTheme()); + path.append(themeService.getTheme()); path.append("/404"); return path.toString(); } @@ -130,7 +130,7 @@ public class CommonController implements ErrorController { return "common/error/500"; } StrBuilder path = new StrBuilder("themes/"); - path.append(optionService.getTheme()); + path.append(themeService.getTheme()); path.append("/500"); return path.toString(); }