mirror of https://github.com/halo-dev/halo
Refactor ThemeService
parent
ad069a1812
commit
8fb7057cd4
|
@ -111,7 +111,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
|
|||
*/
|
||||
private void cacheActiveTheme() {
|
||||
try {
|
||||
configuration.setSharedVariable("themeName", optionService.getTheme());
|
||||
configuration.setSharedVariable("themeName", themeService.getTheme());
|
||||
} catch (TemplateModelException e) {
|
||||
log.error("", e);
|
||||
}
|
||||
|
|
|
@ -280,12 +280,4 @@ public interface OptionService extends CrudService<Option, Integer> {
|
|||
@NonNull
|
||||
Locale getLocale();
|
||||
|
||||
/**
|
||||
* Gets current active theme.
|
||||
*
|
||||
* @return current active theme
|
||||
*/
|
||||
@NonNull
|
||||
String getTheme();
|
||||
|
||||
}
|
||||
|
|
|
@ -129,4 +129,12 @@ public interface ThemeService {
|
|||
@NonNull
|
||||
String render(@NonNull String pageName);
|
||||
|
||||
/**
|
||||
* Gets current theme name.
|
||||
*
|
||||
* @return current theme name
|
||||
*/
|
||||
@NonNull
|
||||
String getTheme();
|
||||
|
||||
}
|
||||
|
|
|
@ -290,9 +290,4 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
}
|
||||
}).orElseGet(Locale::getDefault);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTheme() {
|
||||
return getByProperty(PrimaryProperties.THEME).orElse(DEFAULT_THEME_NAME);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public class ThemeController {
|
|||
*/
|
||||
@GetMapping("files")
|
||||
public List<ThemeFile> 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<String> 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<Object> fetchConfig(@RequestParam("name") String name) {
|
||||
return BaseResponse.ok(themeService.fetchConfig(name));
|
||||
public BaseResponse<Object> fetchConfig() {
|
||||
return BaseResponse.ok(themeService.fetchConfig(themeService.getTheme()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue