mirror of https://github.com/halo-dev/halo
Fix theme render build error
parent
ff4f9c4bd6
commit
feeecc30b2
|
@ -5,6 +5,7 @@ import run.halo.app.model.dto.base.InputConverter;
|
|||
import run.halo.app.model.entity.Attachment;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
/**
|
||||
* Attachment params.
|
||||
|
@ -16,5 +17,7 @@ import javax.validation.constraints.NotBlank;
|
|||
public class AttachmentParam implements InputConverter<Attachment> {
|
||||
|
||||
@NotBlank(message = "Attachment name must not be blank")
|
||||
@Size(max = 255, message = "Length of attachment name must not be more than {max}")
|
||||
private String name;
|
||||
|
||||
}
|
||||
|
|
|
@ -195,6 +195,14 @@ public interface ThemeService {
|
|||
@NonNull
|
||||
String getActivatedThemeId();
|
||||
|
||||
/**
|
||||
* Gets activated theme property.
|
||||
*
|
||||
* @return activated theme property
|
||||
*/
|
||||
@NonNull
|
||||
ThemeProperty getActivatedTheme();
|
||||
|
||||
/**
|
||||
* Actives a theme.
|
||||
*
|
||||
|
|
|
@ -79,6 +79,11 @@ public class ThemeServiceImpl implements ThemeService {
|
|||
*/
|
||||
private String activatedThemeId;
|
||||
|
||||
/**
|
||||
* Activated theme property.
|
||||
*/
|
||||
private ThemeProperty activatedTheme;
|
||||
|
||||
public ThemeServiceImpl(HaloProperties haloProperties,
|
||||
OptionService optionService,
|
||||
StringCacheStore cacheStore,
|
||||
|
@ -275,15 +280,20 @@ public class ThemeServiceImpl implements ThemeService {
|
|||
|
||||
@Override
|
||||
public String render(String pageName) {
|
||||
return String.format(RENDER_TEMPLATE, getActivatedThemeId(), pageName);
|
||||
// Get activated theme
|
||||
ThemeProperty activatedTheme = getActivatedTheme();
|
||||
// Get theme folder name
|
||||
String themeFolderName = Paths.get(activatedTheme.getThemePath()).getFileName().toString();
|
||||
// Build render url
|
||||
return String.format(RENDER_TEMPLATE, themeFolderName, pageName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActivatedThemeId() {
|
||||
if (StringUtils.isBlank(activatedThemeId)) {
|
||||
if (activatedThemeId == null) {
|
||||
synchronized (this) {
|
||||
if (StringUtils.isBlank(activatedThemeId)) {
|
||||
return optionService.getByProperty(PrimaryProperties.THEME).orElse(DEFAULT_THEME_ID);
|
||||
if (activatedThemeId == null) {
|
||||
activatedThemeId = optionService.getByProperty(PrimaryProperties.THEME).orElse(DEFAULT_THEME_ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -291,6 +301,20 @@ public class ThemeServiceImpl implements ThemeService {
|
|||
return activatedThemeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThemeProperty getActivatedTheme() {
|
||||
if (activatedTheme == null) {
|
||||
synchronized (this) {
|
||||
if (activatedTheme == null) {
|
||||
// Get theme property
|
||||
activatedTheme = getThemeOfNonNullBy(getActivatedThemeId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return activatedTheme;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ThemeProperty activeTheme(String themeId) {
|
||||
// Check existence of the theme
|
||||
|
@ -299,9 +323,8 @@ public class ThemeServiceImpl implements ThemeService {
|
|||
// Save the theme to database
|
||||
optionService.saveProperty(PrimaryProperties.THEME, themeId);
|
||||
|
||||
|
||||
// Set the activated theme id
|
||||
setActivatedThemeId(themeId);
|
||||
// Set activated theme
|
||||
setActivatedTheme(themeProperty);
|
||||
|
||||
// Clear the cache
|
||||
clearThemeCache();
|
||||
|
@ -404,8 +427,6 @@ public class ThemeServiceImpl implements ThemeService {
|
|||
cloneFromGit(uri, themeTmpPath);
|
||||
} else {
|
||||
downloadZipAndUnzip(uri, themeTmpPath);
|
||||
// } else {
|
||||
// throw new UnsupportedMediaTypeException("Unsupported download type: " + uri);
|
||||
}
|
||||
|
||||
return add(themeTmpPath);
|
||||
|
@ -486,12 +507,12 @@ public class ThemeServiceImpl implements ThemeService {
|
|||
}
|
||||
|
||||
/**
|
||||
* Set activated theme id.
|
||||
* Sets activated theme.
|
||||
*
|
||||
* @param themeId theme id
|
||||
* @param activatedTheme activated theme
|
||||
*/
|
||||
private void setActivatedThemeId(@Nullable String themeId) {
|
||||
this.activatedThemeId = themeId;
|
||||
private void setActivatedTheme(@Nullable ThemeProperty activatedTheme) {
|
||||
this.activatedTheme = activatedTheme;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue