feat: change themes assets base path (#538)

* feat: change theme resources base path.

* feat: add new variable about theme base path.
pull/539/head
Ryan Wang 2020-02-01 21:07:58 +08:00 committed by GitHub
parent 63122ef625
commit e40de371d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -43,7 +43,7 @@ import static run.halo.app.model.support.HaloConst.HALO_ADMIN_RELATIVE_PATH;
import static run.halo.app.utils.HaloUtils.*; import static run.halo.app.utils.HaloUtils.*;
/** /**
* Mvc configuration. * Spring mvc configuration.
* *
* @author ryanwang * @author ryanwang
* @date 2018-01-02 * @date 2018-01-02
@ -90,12 +90,17 @@ public class WebMvcAutoConfiguration implements WebMvcConfigurer {
@Override @Override
public void addResourceHandlers(ResourceHandlerRegistry registry) { public void addResourceHandlers(ResourceHandlerRegistry registry) {
String workDir = FILE_PROTOCOL + ensureSuffix(haloProperties.getWorkDir(), FILE_SEPARATOR); String workDir = FILE_PROTOCOL + ensureSuffix(haloProperties.getWorkDir(), FILE_SEPARATOR);
// register /** resource handler.
registry.addResourceHandler("/**") registry.addResourceHandler("/**")
.addResourceLocations(workDir + "templates/themes/")
.addResourceLocations(workDir + "templates/admin/") .addResourceLocations(workDir + "templates/admin/")
.addResourceLocations("classpath:/admin/") .addResourceLocations("classpath:/admin/")
.addResourceLocations(workDir + "static/"); .addResourceLocations(workDir + "static/");
// register /themes/** resource handler.
registry.addResourceHandler("/themes/**")
.addResourceLocations(workDir + "templates/themes/");
String uploadUrlPattern = ensureBoth(haloProperties.getUploadUrlPrefix(), URL_SEPARATOR) + "**"; String uploadUrlPattern = ensureBoth(haloProperties.getUploadUrlPrefix(), URL_SEPARATOR) + "**";
String adminPathPattern = ensureSuffix(haloProperties.getAdminPath(), URL_SEPARATOR) + "**"; String adminPathPattern = ensureSuffix(haloProperties.getAdminPath(), URL_SEPARATOR) + "**";
@ -159,7 +164,7 @@ public class WebMvcAutoConfiguration implements WebMvcConfigurer {
configurer.setConfiguration(configuration); configurer.setConfiguration(configuration);
// Set layout variable // Set layout variable
Map<String, Object> freemarkerVariables = new HashMap<>(5); Map<String, Object> freemarkerVariables = new HashMap<>(3);
freemarkerVariables.put("layout", freemarkerLayoutDirectives()); freemarkerVariables.put("layout", freemarkerLayoutDirectives());

View File

@ -103,8 +103,15 @@ public class FreemarkerConfigAwareListener {
Boolean enabledAbsolutePath = optionService.getByPropertyOrDefault(OtherProperties.GLOBAL_ABSOLUTE_PATH_ENABLED, Boolean.class, true); Boolean enabledAbsolutePath = optionService.getByPropertyOrDefault(OtherProperties.GLOBAL_ABSOLUTE_PATH_ENABLED, Boolean.class, true);
String themeBasePath = (enabledAbsolutePath ? optionService.getBlogBaseUrl() : "") + "/themes/" + activatedTheme.getFolderName();
configuration.setSharedVariable("theme", activatedTheme); configuration.setSharedVariable("theme", activatedTheme);
configuration.setSharedVariable("static", (enabledAbsolutePath ? optionService.getBlogBaseUrl() : "") + "/" + activatedTheme.getFolderName());
// TODO: It will be removed in future versions
configuration.setSharedVariable("static", themeBasePath);
configuration.setSharedVariable("theme_base", themeBasePath);
configuration.setSharedVariable("settings", themeSettingService.listAsMapBy(themeService.getActivatedThemeId())); configuration.setSharedVariable("settings", themeSettingService.listAsMapBy(themeService.getActivatedThemeId()));
log.debug("Loaded theme and settings"); log.debug("Loaded theme and settings");
} }