diff --git a/src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java b/src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java index c12c74da7..807886690 100644 --- a/src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java +++ b/src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java @@ -43,7 +43,7 @@ import static run.halo.app.model.support.HaloConst.HALO_ADMIN_RELATIVE_PATH; import static run.halo.app.utils.HaloUtils.*; /** - * Mvc configuration. + * Spring mvc configuration. * * @author ryanwang * @date 2018-01-02 @@ -90,12 +90,17 @@ public class WebMvcAutoConfiguration implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { String workDir = FILE_PROTOCOL + ensureSuffix(haloProperties.getWorkDir(), FILE_SEPARATOR); + + // register /** resource handler. registry.addResourceHandler("/**") - .addResourceLocations(workDir + "templates/themes/") .addResourceLocations(workDir + "templates/admin/") .addResourceLocations("classpath:/admin/") .addResourceLocations(workDir + "static/"); + // register /themes/** resource handler. + registry.addResourceHandler("/themes/**") + .addResourceLocations(workDir + "templates/themes/"); + String uploadUrlPattern = ensureBoth(haloProperties.getUploadUrlPrefix(), URL_SEPARATOR) + "**"; String adminPathPattern = ensureSuffix(haloProperties.getAdminPath(), URL_SEPARATOR) + "**"; @@ -159,7 +164,7 @@ public class WebMvcAutoConfiguration implements WebMvcConfigurer { configurer.setConfiguration(configuration); // Set layout variable - Map freemarkerVariables = new HashMap<>(5); + Map freemarkerVariables = new HashMap<>(3); freemarkerVariables.put("layout", freemarkerLayoutDirectives()); diff --git a/src/main/java/run/halo/app/listener/freemarker/FreemarkerConfigAwareListener.java b/src/main/java/run/halo/app/listener/freemarker/FreemarkerConfigAwareListener.java index e52bfc9b0..dd7bb0912 100644 --- a/src/main/java/run/halo/app/listener/freemarker/FreemarkerConfigAwareListener.java +++ b/src/main/java/run/halo/app/listener/freemarker/FreemarkerConfigAwareListener.java @@ -103,8 +103,15 @@ public class FreemarkerConfigAwareListener { 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("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())); log.debug("Loaded theme and settings"); }