mirror of https://github.com/halo-dev/halo
parent
dccd213e72
commit
7de339571d
|
@ -15,6 +15,7 @@ import run.halo.app.model.entity.Post;
|
|||
import run.halo.app.model.entity.Sheet;
|
||||
import run.halo.app.model.enums.PostPermalinkType;
|
||||
import run.halo.app.model.enums.PostStatus;
|
||||
import run.halo.app.model.enums.SheetPermalinkType;
|
||||
import run.halo.app.service.OptionService;
|
||||
import run.halo.app.service.PostService;
|
||||
import run.halo.app.service.SheetService;
|
||||
|
@ -81,7 +82,12 @@ public class ContentContentController {
|
|||
|
||||
@GetMapping("{prefix}")
|
||||
public String content(@PathVariable("prefix") String prefix,
|
||||
@RequestParam(value = "token", required = false) String token,
|
||||
Model model) {
|
||||
if (optionService.getSheetPermalinkType().equals(SheetPermalinkType.ROOT)) {
|
||||
Sheet sheet = sheetService.getBySlug(prefix);
|
||||
return sheetModel.content(sheet, token, model);
|
||||
}
|
||||
if (optionService.getArchivesPrefix().equals(prefix)) {
|
||||
return postModel.archives(1, model);
|
||||
}
|
||||
|
@ -139,7 +145,7 @@ public class ContentContentController {
|
|||
}
|
||||
}
|
||||
|
||||
if (optionService.getSheetPrefix().equals(prefix)) {
|
||||
if (optionService.getSheetPermalinkType().equals(SheetPermalinkType.SECONDARY) && optionService.getSheetPrefix().equals(prefix)) {
|
||||
Sheet sheet = sheetService.getBySlug(slug);
|
||||
return sheetModel.content(sheet, token, model);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package run.halo.app.model.enums;
|
||||
|
||||
/**
|
||||
* Sheet Permalink type enum.
|
||||
*
|
||||
* @author ryanwang
|
||||
* @date 2020-12-01
|
||||
*/
|
||||
public enum SheetPermalinkType implements ValueEnum<Integer> {
|
||||
|
||||
/**
|
||||
* /{@link run.halo.app.model.properties.PermalinkProperties#SHEET_PREFIX}/${slug}
|
||||
*/
|
||||
SECONDARY(0),
|
||||
|
||||
/**
|
||||
* /${slug}
|
||||
*/
|
||||
ROOT(1);
|
||||
|
||||
private final Integer value;
|
||||
|
||||
SheetPermalinkType(Integer value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package run.halo.app.model.properties;
|
||||
|
||||
import run.halo.app.model.enums.PostPermalinkType;
|
||||
import run.halo.app.model.enums.SheetPermalinkType;
|
||||
|
||||
/**
|
||||
* Permalink properties enum.
|
||||
|
@ -15,6 +16,11 @@ public enum PermalinkProperties implements PropertyEnum {
|
|||
*/
|
||||
POST_PERMALINK_TYPE("post_permalink_type", PostPermalinkType.class, PostPermalinkType.DEFAULT.name()),
|
||||
|
||||
/**
|
||||
* Sheet Permalink type.
|
||||
*/
|
||||
SHEET_PERMALINK_TYPE("sheet_permalink_type", SheetPermalinkType.class, SheetPermalinkType.SECONDARY.name()),
|
||||
|
||||
/**
|
||||
* Categories prefix
|
||||
* such as: /categories or /categories/${slug}
|
||||
|
|
|
@ -12,6 +12,7 @@ import run.halo.app.model.dto.OptionDTO;
|
|||
import run.halo.app.model.dto.OptionSimpleDTO;
|
||||
import run.halo.app.model.entity.Option;
|
||||
import run.halo.app.model.enums.PostPermalinkType;
|
||||
import run.halo.app.model.enums.SheetPermalinkType;
|
||||
import run.halo.app.model.enums.ValueEnum;
|
||||
import run.halo.app.model.params.OptionParam;
|
||||
import run.halo.app.model.params.OptionQuery;
|
||||
|
@ -392,6 +393,13 @@ public interface OptionService extends CrudService<Option, Integer> {
|
|||
*/
|
||||
PostPermalinkType getPostPermalinkType();
|
||||
|
||||
/**
|
||||
* Get sheet permalink type.
|
||||
*
|
||||
* @return SheetPermalinkType
|
||||
*/
|
||||
SheetPermalinkType getSheetPermalinkType();
|
||||
|
||||
/**
|
||||
* Get sheet custom prefix.
|
||||
*
|
||||
|
|
|
@ -23,6 +23,7 @@ import run.halo.app.model.dto.OptionDTO;
|
|||
import run.halo.app.model.dto.OptionSimpleDTO;
|
||||
import run.halo.app.model.entity.Option;
|
||||
import run.halo.app.model.enums.PostPermalinkType;
|
||||
import run.halo.app.model.enums.SheetPermalinkType;
|
||||
import run.halo.app.model.enums.ValueEnum;
|
||||
import run.halo.app.model.params.OptionParam;
|
||||
import run.halo.app.model.params.OptionQuery;
|
||||
|
@ -518,6 +519,11 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
return getEnumByPropertyOrDefault(PermalinkProperties.POST_PERMALINK_TYPE, PostPermalinkType.class, PostPermalinkType.DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SheetPermalinkType getSheetPermalinkType() {
|
||||
return getEnumByPropertyOrDefault(PermalinkProperties.SHEET_PERMALINK_TYPE, SheetPermalinkType.class, SheetPermalinkType.SECONDARY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSheetPrefix() {
|
||||
return getByPropertyOrDefault(PermalinkProperties.SHEET_PREFIX, String.class, PermalinkProperties.SHEET_PREFIX.defaultValue());
|
||||
|
|
|
@ -11,6 +11,7 @@ import run.halo.app.exception.NotFoundException;
|
|||
import run.halo.app.model.dto.post.BasePostMinimalDTO;
|
||||
import run.halo.app.model.entity.Sheet;
|
||||
import run.halo.app.model.entity.SheetComment;
|
||||
import run.halo.app.model.enums.SheetPermalinkType;
|
||||
import run.halo.app.model.vo.SheetCommentWithSheetVO;
|
||||
import run.halo.app.repository.SheetCommentRepository;
|
||||
import run.halo.app.repository.SheetRepository;
|
||||
|
@ -95,15 +96,23 @@ public class SheetCommentServiceImpl extends BaseCommentServiceImpl<SheetComment
|
|||
private BasePostMinimalDTO buildSheetFullPath(BasePostMinimalDTO basePostMinimalDTO) {
|
||||
StringBuilder fullPath = new StringBuilder();
|
||||
|
||||
SheetPermalinkType permalinkType = optionService.getSheetPermalinkType();
|
||||
|
||||
if (optionService.isEnabledAbsolutePath()) {
|
||||
fullPath.append(optionService.getBlogBaseUrl());
|
||||
}
|
||||
|
||||
if (permalinkType.equals(SheetPermalinkType.SECONDARY)) {
|
||||
fullPath.append(URL_SEPARATOR)
|
||||
.append(optionService.getSheetPrefix())
|
||||
.append(URL_SEPARATOR)
|
||||
.append(basePostMinimalDTO.getSlug())
|
||||
.append(optionService.getPathSuffix());
|
||||
} else if (permalinkType.equals(SheetPermalinkType.ROOT)) {
|
||||
fullPath.append(URL_SEPARATOR)
|
||||
.append(basePostMinimalDTO.getSlug())
|
||||
.append(optionService.getPathSuffix());
|
||||
}
|
||||
|
||||
basePostMinimalDTO.setFullPath(fullPath.toString());
|
||||
return basePostMinimalDTO;
|
||||
|
|
|
@ -20,6 +20,7 @@ import run.halo.app.model.entity.SheetComment;
|
|||
import run.halo.app.model.entity.SheetMeta;
|
||||
import run.halo.app.model.enums.LogType;
|
||||
import run.halo.app.model.enums.PostStatus;
|
||||
import run.halo.app.model.enums.SheetPermalinkType;
|
||||
import run.halo.app.model.vo.SheetDetailVO;
|
||||
import run.halo.app.model.vo.SheetListVO;
|
||||
import run.halo.app.repository.SheetRepository;
|
||||
|
@ -346,15 +347,23 @@ public class SheetServiceImpl extends BasePostServiceImpl<Sheet> implements Shee
|
|||
private String buildFullPath(Sheet sheet) {
|
||||
StringBuilder fullPath = new StringBuilder();
|
||||
|
||||
SheetPermalinkType permalinkType = optionService.getSheetPermalinkType();
|
||||
|
||||
if (optionService.isEnabledAbsolutePath()) {
|
||||
fullPath.append(optionService.getBlogBaseUrl());
|
||||
}
|
||||
|
||||
if (permalinkType.equals(SheetPermalinkType.SECONDARY)) {
|
||||
fullPath.append(URL_SEPARATOR)
|
||||
.append(optionService.getSheetPrefix())
|
||||
.append(URL_SEPARATOR)
|
||||
.append(sheet.getSlug())
|
||||
.append(optionService.getPathSuffix());
|
||||
} else if (permalinkType.equals(SheetPermalinkType.ROOT)) {
|
||||
fullPath.append(URL_SEPARATOR)
|
||||
.append(sheet.getSlug())
|
||||
.append(optionService.getPathSuffix());
|
||||
}
|
||||
|
||||
return fullPath.toString();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue