mirror of https://github.com/halo-dev/halo
🐛 bug修复
parent
378acf42f6
commit
919d7040cd
|
@ -1,7 +1,5 @@
|
|||
package cc.ryanc.halo.config;
|
||||
|
||||
import cc.ryanc.halo.model.dto.HaloConst;
|
||||
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
|
||||
import cc.ryanc.halo.model.tag.ArticleTagDirective;
|
||||
import cc.ryanc.halo.model.tag.CommonTagDirective;
|
||||
import cc.ryanc.halo.service.OptionsService;
|
||||
|
@ -48,7 +46,6 @@ public class FreeMarkerConfig {
|
|||
configuration.setSharedVariable("articleTag", articleTagDirective);
|
||||
configuration.setSharedVariable("options", optionsService.findAllOptions());
|
||||
configuration.setSharedVariable("user", userService.findUser());
|
||||
configuration.setSharedVariable("themeName", HaloConst.OPTIONS.get(BlogPropertiesEnum.THEME.getProp()));
|
||||
} catch (TemplateModelException e) {
|
||||
log.error("自定义标签加载失败:{}", e.getMessage());
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import cc.ryanc.halo.service.OptionsService;
|
|||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cc.ryanc.halo.web.controller.core.BaseController;
|
||||
import cn.hutool.cron.CronUtil;
|
||||
import freemarker.template.TemplateModelException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -33,9 +34,16 @@ public class StartupConfig implements ApplicationListener<ApplicationStartedEven
|
|||
@Autowired
|
||||
private OptionsService optionsService;
|
||||
|
||||
@Autowired
|
||||
private freemarker.template.Configuration configuration;
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationStartedEvent event) {
|
||||
this.loadActiveTheme();
|
||||
try {
|
||||
this.loadActiveTheme();
|
||||
} catch (TemplateModelException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.loadOptions();
|
||||
this.loadThemes();
|
||||
this.loadOwo();
|
||||
|
@ -47,7 +55,7 @@ public class StartupConfig implements ApplicationListener<ApplicationStartedEven
|
|||
/**
|
||||
* 加载主题设置
|
||||
*/
|
||||
private void loadActiveTheme() {
|
||||
private void loadActiveTheme() throws TemplateModelException {
|
||||
String themeValue = optionsService.findOneOption(BlogPropertiesEnum.THEME.getProp());
|
||||
if (StringUtils.isNotEmpty(themeValue) && !StringUtils.equals(themeValue, null)) {
|
||||
BaseController.THEME = themeValue;
|
||||
|
@ -55,6 +63,7 @@ public class StartupConfig implements ApplicationListener<ApplicationStartedEven
|
|||
//以防万一
|
||||
BaseController.THEME = "anatole";
|
||||
}
|
||||
configuration.setSharedVariable("themeName", BaseController.THEME);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,7 @@ import cn.hutool.core.io.file.FileWriter;
|
|||
import cn.hutool.core.util.RuntimeUtil;
|
||||
import cn.hutool.core.util.ZipUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import freemarker.template.Configuration;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -53,6 +54,9 @@ public class ThemeController extends BaseController {
|
|||
@Autowired
|
||||
private LogsService logsService;
|
||||
|
||||
@Autowired
|
||||
private Configuration configuration;
|
||||
|
||||
@Autowired
|
||||
private LocaleMessageUtil localeMessageUtil;
|
||||
|
||||
|
@ -92,6 +96,8 @@ public class ThemeController extends BaseController {
|
|||
BaseController.THEME = siteTheme;
|
||||
HaloConst.OPTIONS.clear();
|
||||
HaloConst.OPTIONS = optionsService.findAllOptions();
|
||||
configuration.setSharedVariable("themeName", siteTheme);
|
||||
configuration.setSharedVariable("options", HaloConst.OPTIONS);
|
||||
log.info("已将主题改变为:{}", siteTheme);
|
||||
logsService.saveByLogs(
|
||||
new Logs(LogsRecord.CHANGE_THEME, "更换为" + siteTheme, ServletUtil.getClientIP(request), DateUtil.date())
|
||||
|
|
Loading…
Reference in New Issue