Fix theme render build error

pull/146/head
johnniang 2019-04-20 16:10:27 +08:00
parent ff4f9c4bd6
commit feeecc30b2
3 changed files with 45 additions and 13 deletions

View File

@ -5,6 +5,7 @@ import run.halo.app.model.dto.base.InputConverter;
import run.halo.app.model.entity.Attachment; import run.halo.app.model.entity.Attachment;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
/** /**
* Attachment params. * Attachment params.
@ -16,5 +17,7 @@ import javax.validation.constraints.NotBlank;
public class AttachmentParam implements InputConverter<Attachment> { public class AttachmentParam implements InputConverter<Attachment> {
@NotBlank(message = "Attachment name must not be blank") @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; private String name;
} }

View File

@ -195,6 +195,14 @@ public interface ThemeService {
@NonNull @NonNull
String getActivatedThemeId(); String getActivatedThemeId();
/**
* Gets activated theme property.
*
* @return activated theme property
*/
@NonNull
ThemeProperty getActivatedTheme();
/** /**
* Actives a theme. * Actives a theme.
* *

View File

@ -79,6 +79,11 @@ public class ThemeServiceImpl implements ThemeService {
*/ */
private String activatedThemeId; private String activatedThemeId;
/**
* Activated theme property.
*/
private ThemeProperty activatedTheme;
public ThemeServiceImpl(HaloProperties haloProperties, public ThemeServiceImpl(HaloProperties haloProperties,
OptionService optionService, OptionService optionService,
StringCacheStore cacheStore, StringCacheStore cacheStore,
@ -275,15 +280,20 @@ public class ThemeServiceImpl implements ThemeService {
@Override @Override
public String render(String pageName) { 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 @Override
public String getActivatedThemeId() { public String getActivatedThemeId() {
if (StringUtils.isBlank(activatedThemeId)) { if (activatedThemeId == null) {
synchronized (this) { synchronized (this) {
if (StringUtils.isBlank(activatedThemeId)) { if (activatedThemeId == null) {
return optionService.getByProperty(PrimaryProperties.THEME).orElse(DEFAULT_THEME_ID); activatedThemeId = optionService.getByProperty(PrimaryProperties.THEME).orElse(DEFAULT_THEME_ID);
} }
} }
} }
@ -291,6 +301,20 @@ public class ThemeServiceImpl implements ThemeService {
return activatedThemeId; return activatedThemeId;
} }
@Override
public ThemeProperty getActivatedTheme() {
if (activatedTheme == null) {
synchronized (this) {
if (activatedTheme == null) {
// Get theme property
activatedTheme = getThemeOfNonNullBy(getActivatedThemeId());
}
}
}
return activatedTheme;
}
@Override @Override
public ThemeProperty activeTheme(String themeId) { public ThemeProperty activeTheme(String themeId) {
// Check existence of the theme // Check existence of the theme
@ -299,9 +323,8 @@ public class ThemeServiceImpl implements ThemeService {
// Save the theme to database // Save the theme to database
optionService.saveProperty(PrimaryProperties.THEME, themeId); optionService.saveProperty(PrimaryProperties.THEME, themeId);
// Set activated theme
// Set the activated theme id setActivatedTheme(themeProperty);
setActivatedThemeId(themeId);
// Clear the cache // Clear the cache
clearThemeCache(); clearThemeCache();
@ -404,8 +427,6 @@ public class ThemeServiceImpl implements ThemeService {
cloneFromGit(uri, themeTmpPath); cloneFromGit(uri, themeTmpPath);
} else { } else {
downloadZipAndUnzip(uri, themeTmpPath); downloadZipAndUnzip(uri, themeTmpPath);
// } else {
// throw new UnsupportedMediaTypeException("Unsupported download type: " + uri);
} }
return add(themeTmpPath); 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) { private void setActivatedTheme(@Nullable ThemeProperty activatedTheme) {
this.activatedThemeId = themeId; this.activatedTheme = activatedTheme;
} }
/** /**