mirror of https://github.com/halo-dev/halo
Remove the THEME attribute from BaseContentController.
parent
1a6f549fbf
commit
4c5a586543
|
@ -11,7 +11,6 @@ import cc.ryanc.halo.service.OptionService;
|
||||||
import cc.ryanc.halo.service.ThemeService;
|
import cc.ryanc.halo.service.ThemeService;
|
||||||
import cc.ryanc.halo.service.UserService;
|
import cc.ryanc.halo.service.UserService;
|
||||||
import cc.ryanc.halo.utils.HaloUtils;
|
import cc.ryanc.halo.utils.HaloUtils;
|
||||||
import cc.ryanc.halo.web.controller.content.base.BaseContentController;
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
@ -30,6 +29,7 @@ import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static cc.ryanc.halo.model.support.HaloConst.ACTIVATED_THEME_NAME;
|
||||||
import static cc.ryanc.halo.model.support.HaloConst.DEFAULT_THEME_NAME;
|
import static cc.ryanc.halo.model.support.HaloConst.DEFAULT_THEME_NAME;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -113,10 +113,10 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
||||||
* Get active theme
|
* Get active theme
|
||||||
*/
|
*/
|
||||||
private void getActiveTheme() {
|
private void getActiveTheme() {
|
||||||
BaseContentController.THEME = optionService.getByProperty(PrimaryProperties.THEME).orElse(DEFAULT_THEME_NAME);
|
ACTIVATED_THEME_NAME = optionService.getByProperty(PrimaryProperties.THEME).orElse(DEFAULT_THEME_NAME);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
configuration.setSharedVariable("themeName", BaseContentController.THEME);
|
configuration.setSharedVariable("themeName", ACTIVATED_THEME_NAME);
|
||||||
} catch (TemplateModelException e) {
|
} catch (TemplateModelException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,11 @@ public class HaloConst {
|
||||||
*/
|
*/
|
||||||
public final static String DEFAULT_THEME_NAME = "anatole";
|
public final static String DEFAULT_THEME_NAME = "anatole";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Activated theme name.
|
||||||
|
*/
|
||||||
|
public static String ACTIVATED_THEME_NAME = "anatole";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* version constant
|
* version constant
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -7,7 +7,6 @@ import cc.ryanc.halo.model.support.ThemeFile;
|
||||||
import cc.ryanc.halo.model.support.ThemeProperties;
|
import cc.ryanc.halo.model.support.ThemeProperties;
|
||||||
import cc.ryanc.halo.service.ThemeService;
|
import cc.ryanc.halo.service.ThemeService;
|
||||||
import cc.ryanc.halo.utils.FilenameUtils;
|
import cc.ryanc.halo.utils.FilenameUtils;
|
||||||
import cc.ryanc.halo.web.controller.content.base.BaseContentController;
|
|
||||||
import cn.hutool.core.text.StrBuilder;
|
import cn.hutool.core.text.StrBuilder;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.setting.dialect.Props;
|
import cn.hutool.setting.dialect.Props;
|
||||||
|
@ -151,7 +150,7 @@ public class ThemeServiceImpl implements ThemeService {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isTemplateExist(String template) {
|
public boolean isTemplateExist(String template) {
|
||||||
StrBuilder templatePath = new StrBuilder(BaseContentController.THEME);
|
StrBuilder templatePath = new StrBuilder(HaloConst.ACTIVATED_THEME_NAME);
|
||||||
templatePath.append("/");
|
templatePath.append("/");
|
||||||
templatePath.append(template);
|
templatePath.append(template);
|
||||||
File file = new File(getThemeBasePath(), templatePath.toString());
|
File file = new File(getThemeBasePath(), templatePath.toString());
|
||||||
|
|
|
@ -3,11 +3,11 @@ package cc.ryanc.halo.web.controller.admin.api;
|
||||||
import cc.ryanc.halo.model.enums.OptionSource;
|
import cc.ryanc.halo.model.enums.OptionSource;
|
||||||
import cc.ryanc.halo.model.properties.PrimaryProperties;
|
import cc.ryanc.halo.model.properties.PrimaryProperties;
|
||||||
import cc.ryanc.halo.model.properties.PropertyEnum;
|
import cc.ryanc.halo.model.properties.PropertyEnum;
|
||||||
|
import cc.ryanc.halo.model.support.HaloConst;
|
||||||
import cc.ryanc.halo.model.support.Theme;
|
import cc.ryanc.halo.model.support.Theme;
|
||||||
import cc.ryanc.halo.model.support.ThemeFile;
|
import cc.ryanc.halo.model.support.ThemeFile;
|
||||||
import cc.ryanc.halo.service.OptionService;
|
import cc.ryanc.halo.service.OptionService;
|
||||||
import cc.ryanc.halo.service.ThemeService;
|
import cc.ryanc.halo.service.ThemeService;
|
||||||
import cc.ryanc.halo.web.controller.content.base.BaseContentController;
|
|
||||||
import freemarker.template.Configuration;
|
import freemarker.template.Configuration;
|
||||||
import freemarker.template.TemplateModelException;
|
import freemarker.template.TemplateModelException;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
@ -62,7 +62,7 @@ public class ThemeController {
|
||||||
*/
|
*/
|
||||||
@GetMapping("files")
|
@GetMapping("files")
|
||||||
public List<ThemeFile> listFiles() {
|
public List<ThemeFile> listFiles() {
|
||||||
return themeService.listThemeFolderBy(BaseContentController.THEME);
|
return themeService.listThemeFolderBy(HaloConst.ACTIVATED_THEME_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,7 +78,7 @@ public class ThemeController {
|
||||||
properties.put(PrimaryProperties.THEME, themeName);
|
properties.put(PrimaryProperties.THEME, themeName);
|
||||||
// TODO Refactor: saveProperties => saveProperty
|
// TODO Refactor: saveProperties => saveProperty
|
||||||
optionService.saveProperties(properties, OptionSource.SYSTEM);
|
optionService.saveProperties(properties, OptionSource.SYSTEM);
|
||||||
BaseContentController.THEME = themeName;
|
HaloConst.ACTIVATED_THEME_NAME = themeName;
|
||||||
configuration.setSharedVariable("themeName", themeName);
|
configuration.setSharedVariable("themeName", themeName);
|
||||||
configuration.setSharedVariable("options", optionService.listOptions());
|
configuration.setSharedVariable("options", optionService.listOptions());
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package cc.ryanc.halo.web.controller.content.base;
|
||||||
|
|
||||||
import cn.hutool.core.text.StrBuilder;
|
import cn.hutool.core.text.StrBuilder;
|
||||||
|
|
||||||
import static cc.ryanc.halo.model.support.HaloConst.DEFAULT_THEME_NAME;
|
import static cc.ryanc.halo.model.support.HaloConst.ACTIVATED_THEME_NAME;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Content base Controller
|
* Content base Controller
|
||||||
|
@ -12,12 +12,6 @@ import static cc.ryanc.halo.model.support.HaloConst.DEFAULT_THEME_NAME;
|
||||||
*/
|
*/
|
||||||
public abstract class BaseContentController {
|
public abstract class BaseContentController {
|
||||||
|
|
||||||
/**
|
|
||||||
* Default theme
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static String THEME = DEFAULT_THEME_NAME;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render page by template name
|
* Render page by template name
|
||||||
*
|
*
|
||||||
|
@ -26,7 +20,7 @@ public abstract class BaseContentController {
|
||||||
*/
|
*/
|
||||||
public String render(String pageName) {
|
public String render(String pageName) {
|
||||||
final StrBuilder themeStr = new StrBuilder("themes/");
|
final StrBuilder themeStr = new StrBuilder("themes/");
|
||||||
themeStr.append(THEME);
|
themeStr.append(ACTIVATED_THEME_NAME);
|
||||||
themeStr.append("/");
|
themeStr.append("/");
|
||||||
themeStr.append(pageName);
|
themeStr.append(pageName);
|
||||||
return themeStr.toString();
|
return themeStr.toString();
|
||||||
|
|
|
@ -3,7 +3,6 @@ package cc.ryanc.halo.web.controller.core;
|
||||||
import cc.ryanc.halo.model.entity.User;
|
import cc.ryanc.halo.model.entity.User;
|
||||||
import cc.ryanc.halo.model.support.HaloConst;
|
import cc.ryanc.halo.model.support.HaloConst;
|
||||||
import cc.ryanc.halo.service.ThemeService;
|
import cc.ryanc.halo.service.ThemeService;
|
||||||
import cc.ryanc.halo.web.controller.content.base.BaseContentController;
|
|
||||||
import cn.hutool.core.text.StrBuilder;
|
import cn.hutool.core.text.StrBuilder;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
@ -107,7 +106,7 @@ public class CommonController implements ErrorController {
|
||||||
return "common/error/404";
|
return "common/error/404";
|
||||||
}
|
}
|
||||||
StrBuilder path = new StrBuilder("themes/");
|
StrBuilder path = new StrBuilder("themes/");
|
||||||
path.append(BaseContentController.THEME);
|
path.append(HaloConst.ACTIVATED_THEME_NAME);
|
||||||
path.append("/404");
|
path.append("/404");
|
||||||
return path.toString();
|
return path.toString();
|
||||||
}
|
}
|
||||||
|
@ -123,7 +122,7 @@ public class CommonController implements ErrorController {
|
||||||
return "common/error/500";
|
return "common/error/500";
|
||||||
}
|
}
|
||||||
StrBuilder path = new StrBuilder("themes/");
|
StrBuilder path = new StrBuilder("themes/");
|
||||||
path.append(BaseContentController.THEME);
|
path.append(HaloConst.ACTIVATED_THEME_NAME);
|
||||||
path.append("/500");
|
path.append("/500");
|
||||||
return path.toString();
|
return path.toString();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue