Create initTheme method for StartedListener

pull/137/head
ruibaby 2019-03-26 20:49:16 +08:00
parent 888c218643
commit f041dfede4
3 changed files with 32 additions and 8 deletions

View File

@ -8,6 +8,7 @@ import cc.ryanc.halo.service.OptionService;
import cc.ryanc.halo.service.ThemeService; import cc.ryanc.halo.service.ThemeService;
import cc.ryanc.halo.utils.HaloUtils; import cc.ryanc.halo.utils.HaloUtils;
import cc.ryanc.halo.web.controller.content.base.BaseContentController; import cc.ryanc.halo.web.controller.content.base.BaseContentController;
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;
import freemarker.template.TemplateModelException; import freemarker.template.TemplateModelException;
@ -19,6 +20,7 @@ import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.util.ResourceUtils; import org.springframework.util.ResourceUtils;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -63,6 +65,7 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
this.cacheOwo(); this.cacheOwo();
this.getActiveTheme(); this.getActiveTheme();
this.printStartInfo(); this.printStartInfo();
this.initThemes();
} }
/** /**
@ -134,4 +137,25 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
// TODO Consider to throw an exception // TODO Consider to throw an exception
} }
} }
/**
* Init internal themes
*/
private void initThemes() {
// Whether the blog is initialized
String isInstall = optionService.getByKeyOfNullable(BlogProperties.IS_INSTALL.getValue());
try {
if (null == isInstall) {
File internalThemePath = new File(ResourceUtils.getURL("classpath:").getPath(), "templates/themes");
File[] internalThemes = internalThemePath.listFiles();
if (null != internalThemes) {
for (File theme : internalThemes) {
FileUtil.copy(theme, themeService.getThemeBasePath(), true);
}
}
}
} catch (Exception e) {
throw new RuntimeException("Init internal theme to user path error");
}
}
} }

View File

@ -23,10 +23,10 @@ spring:
password: 123456 password: 123456
#MySql配置 #MySql配置
# driver-class-name: com.mysql.cj.jdbc.Driver # driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://127.0.0.1:3306/halodb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai # url: jdbc:mysql://127.0.0.1:3306/halodb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
# username: root # username: root
# password: 123456 # password: 123456
h2: h2:
console: console:

View File

@ -23,10 +23,10 @@ spring:
password: 123456 password: 123456
#MySql配置 #MySql配置
# driver-class-name: com.mysql.cj.jdbc.Driver # driver-class-name: com.mysql.cj.jdbc.Driver
# url: jdbc:mysql://127.0.0.1:3306/halodb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai # url: jdbc:mysql://127.0.0.1:3306/halodb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai
# username: root # username: root
# password: 123456 # password: 123456
h2: h2:
console: console: