🐛 bug修复

pull/33/merge
ruibaby 2018-09-22 22:24:23 +08:00
parent 378acf42f6
commit 919d7040cd
3 changed files with 17 additions and 5 deletions

View File

@ -1,7 +1,5 @@
package cc.ryanc.halo.config; 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.ArticleTagDirective;
import cc.ryanc.halo.model.tag.CommonTagDirective; import cc.ryanc.halo.model.tag.CommonTagDirective;
import cc.ryanc.halo.service.OptionsService; import cc.ryanc.halo.service.OptionsService;
@ -48,7 +46,6 @@ public class FreeMarkerConfig {
configuration.setSharedVariable("articleTag", articleTagDirective); configuration.setSharedVariable("articleTag", articleTagDirective);
configuration.setSharedVariable("options", optionsService.findAllOptions()); configuration.setSharedVariable("options", optionsService.findAllOptions());
configuration.setSharedVariable("user", userService.findUser()); configuration.setSharedVariable("user", userService.findUser());
configuration.setSharedVariable("themeName", HaloConst.OPTIONS.get(BlogPropertiesEnum.THEME.getProp()));
} catch (TemplateModelException e) { } catch (TemplateModelException e) {
log.error("自定义标签加载失败:{}", e.getMessage()); log.error("自定义标签加载失败:{}", e.getMessage());
} }

View File

@ -7,6 +7,7 @@ import cc.ryanc.halo.service.OptionsService;
import cc.ryanc.halo.utils.HaloUtils; import cc.ryanc.halo.utils.HaloUtils;
import cc.ryanc.halo.web.controller.core.BaseController; import cc.ryanc.halo.web.controller.core.BaseController;
import cn.hutool.cron.CronUtil; import cn.hutool.cron.CronUtil;
import freemarker.template.TemplateModelException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -33,9 +34,16 @@ public class StartupConfig implements ApplicationListener<ApplicationStartedEven
@Autowired @Autowired
private OptionsService optionsService; private OptionsService optionsService;
@Autowired
private freemarker.template.Configuration configuration;
@Override @Override
public void onApplicationEvent(ApplicationStartedEvent event) { public void onApplicationEvent(ApplicationStartedEvent event) {
try {
this.loadActiveTheme(); this.loadActiveTheme();
} catch (TemplateModelException e) {
e.printStackTrace();
}
this.loadOptions(); this.loadOptions();
this.loadThemes(); this.loadThemes();
this.loadOwo(); 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()); String themeValue = optionsService.findOneOption(BlogPropertiesEnum.THEME.getProp());
if (StringUtils.isNotEmpty(themeValue) && !StringUtils.equals(themeValue, null)) { if (StringUtils.isNotEmpty(themeValue) && !StringUtils.equals(themeValue, null)) {
BaseController.THEME = themeValue; BaseController.THEME = themeValue;
@ -55,6 +63,7 @@ public class StartupConfig implements ApplicationListener<ApplicationStartedEven
//以防万一 //以防万一
BaseController.THEME = "anatole"; BaseController.THEME = "anatole";
} }
configuration.setSharedVariable("themeName", BaseController.THEME);
} }
/** /**

View File

@ -19,6 +19,7 @@ import cn.hutool.core.io.file.FileWriter;
import cn.hutool.core.util.RuntimeUtil; import cn.hutool.core.util.RuntimeUtil;
import cn.hutool.core.util.ZipUtil; import cn.hutool.core.util.ZipUtil;
import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.extra.servlet.ServletUtil;
import freemarker.template.Configuration;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -53,6 +54,9 @@ public class ThemeController extends BaseController {
@Autowired @Autowired
private LogsService logsService; private LogsService logsService;
@Autowired
private Configuration configuration;
@Autowired @Autowired
private LocaleMessageUtil localeMessageUtil; private LocaleMessageUtil localeMessageUtil;
@ -92,6 +96,8 @@ public class ThemeController extends BaseController {
BaseController.THEME = siteTheme; BaseController.THEME = siteTheme;
HaloConst.OPTIONS.clear(); HaloConst.OPTIONS.clear();
HaloConst.OPTIONS = optionsService.findAllOptions(); HaloConst.OPTIONS = optionsService.findAllOptions();
configuration.setSharedVariable("themeName", siteTheme);
configuration.setSharedVariable("options", HaloConst.OPTIONS);
log.info("已将主题改变为:{}", siteTheme); log.info("已将主题改变为:{}", siteTheme);
logsService.saveByLogs( logsService.saveByLogs(
new Logs(LogsRecord.CHANGE_THEME, "更换为" + siteTheme, ServletUtil.getClientIP(request), DateUtil.date()) new Logs(LogsRecord.CHANGE_THEME, "更换为" + siteTheme, ServletUtil.getClientIP(request), DateUtil.date())