feat: support set theme static source path type. (#535)

* feat: support set theme static source path type.

* refactor: global_absolute_path_enabled property.
pull/537/head
Ryan Wang 2020-02-01 15:39:21 +08:00 committed by GitHub
parent 474c2f369c
commit 6f6ed9ee07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 2 deletions

View File

@ -12,6 +12,7 @@ import run.halo.app.event.options.OptionUpdatedEvent;
import run.halo.app.event.theme.ThemeActivatedEvent;
import run.halo.app.event.user.UserUpdatedEvent;
import run.halo.app.handler.theme.config.support.ThemeProperty;
import run.halo.app.model.properties.OtherProperties;
import run.halo.app.model.support.HaloConst;
import run.halo.app.service.OptionService;
import run.halo.app.service.ThemeService;
@ -96,9 +97,14 @@ public class FreemarkerConfigAwareListener {
}
private void loadThemeConfig() throws TemplateModelException {
// Get current activated theme.
ThemeProperty activatedTheme = themeService.getActivatedTheme();
Boolean enabledAbsolutePath = optionService.getByPropertyOrDefault(OtherProperties.GLOBAL_ABSOLUTE_PATH_ENABLED, Boolean.class, true);
configuration.setSharedVariable("theme", activatedTheme);
configuration.setSharedVariable("static", optionService.getBlogBaseUrl() + "/" + activatedTheme.getFolderName());
configuration.setSharedVariable("static", (enabledAbsolutePath ? optionService.getBlogBaseUrl() : "") + "/" + activatedTheme.getFolderName());
configuration.setSharedVariable("settings", themeSettingService.listAsMapBy(themeService.getActivatedThemeId()));
log.debug("Loaded theme and settings");
}

View File

@ -0,0 +1,31 @@
package run.halo.app.model.enums;
/**
* Global path type.
*
* @author ryanwang
* @date 2020-02-01
*/
public enum GlobalPathType implements ValueEnum<Integer> {
/**
* Relative path.
*/
RELATIVE(0),
/**
* Absolute path.
*/
ABSOLUTE(1);
private Integer value;
GlobalPathType(Integer value) {
this.value = value;
}
@Override
public Integer getValue() {
return value;
}
}

View File

@ -22,7 +22,12 @@ public enum OtherProperties implements PropertyEnum {
/**
* Statistics platform code,such as Google Analytics.
*/
STATISTICS_CODE("blog_statistics_code", String.class, "");
STATISTICS_CODE("blog_statistics_code", String.class, ""),
/**
* Global absolute path enabled.
*/
GLOBAL_ABSOLUTE_PATH_ENABLED("global_absolute_path_enabled", Boolean.class, "true");
private final String value;