pull/1176/head
Ryan Wang 2020-12-01 14:11:11 +08:00 committed by GitHub
parent a05c74ae38
commit dccd213e72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 28 deletions

View File

@ -109,13 +109,17 @@ public class ContentContentController {
Model model) { Model model) {
if (optionService.getArchivesPrefix().equals(prefix)) { if (optionService.getArchivesPrefix().equals(prefix)) {
return postModel.archives(page, model); return postModel.archives(page, model);
} else if (optionService.getJournalsPrefix().equals(prefix)) {
return journalModel.list(page, model);
} else if (optionService.getPhotosPrefix().equals(prefix)) {
return photoModel.list(page, model);
} else {
throw new NotFoundException("Not Found");
} }
if (optionService.getJournalsPrefix().equals(prefix)) {
return journalModel.list(page, model);
}
if (optionService.getPhotosPrefix().equals(prefix)) {
return photoModel.list(page, model);
}
throw new NotFoundException("Not Found");
} }
@GetMapping("{prefix}/{slug}") @GetMapping("{prefix}/{slug}")
@ -124,23 +128,36 @@ public class ContentContentController {
@RequestParam(value = "token", required = false) String token, @RequestParam(value = "token", required = false) String token,
Model model) { Model model) {
PostPermalinkType postPermalinkType = optionService.getPostPermalinkType(); PostPermalinkType postPermalinkType = optionService.getPostPermalinkType();
if (optionService.getArchivesPrefix().equals(prefix)) {
if (postPermalinkType.equals(PostPermalinkType.DEFAULT)) {
Post post = postService.getBySlug(slug);
return postModel.content(post, token, model);
}
if (postPermalinkType.equals(PostPermalinkType.ID_SLUG) && StringUtils.isNumeric(slug)) {
Post post = postService.getById(Integer.parseInt(slug));
return postModel.content(post, token, model);
}
}
if (postPermalinkType.equals(PostPermalinkType.DEFAULT) && optionService.getArchivesPrefix().equals(prefix)) { if (optionService.getSheetPrefix().equals(prefix)) {
Post post = postService.getBySlug(slug);
return postModel.content(post, token, model);
} else if (postPermalinkType.equals(PostPermalinkType.YEAR) && prefix.length() == 4 && StringUtils.isNumeric(prefix)) {
Post post = postService.getBy(Integer.parseInt(prefix), slug);
return postModel.content(post, token, model);
} else if (optionService.getSheetPrefix().equals(prefix)) {
Sheet sheet = sheetService.getBySlug(slug); Sheet sheet = sheetService.getBySlug(slug);
return sheetModel.content(sheet, token, model); return sheetModel.content(sheet, token, model);
} else if (optionService.getCategoriesPrefix().equals(prefix)) {
return categoryModel.listPost(model, slug, 1);
} else if (optionService.getTagsPrefix().equals(prefix)) {
return tagModel.listPost(model, slug, 1);
} else {
throw new NotFoundException("Not Found");
} }
if (optionService.getCategoriesPrefix().equals(prefix)) {
return categoryModel.listPost(model, slug, 1);
}
if (optionService.getTagsPrefix().equals(prefix)) {
return tagModel.listPost(model, slug, 1);
}
if (postPermalinkType.equals(PostPermalinkType.YEAR) && prefix.length() == 4 && StringUtils.isNumeric(prefix)) {
Post post = postService.getBy(Integer.parseInt(prefix), slug);
return postModel.content(post, token, model);
}
throw new NotFoundException("Not Found");
} }
@GetMapping("{prefix}/{slug}/page/{page:\\d+}") @GetMapping("{prefix}/{slug}/page/{page:\\d+}")
@ -150,11 +167,13 @@ public class ContentContentController {
Model model) { Model model) {
if (optionService.getCategoriesPrefix().equals(prefix)) { if (optionService.getCategoriesPrefix().equals(prefix)) {
return categoryModel.listPost(model, slug, page); return categoryModel.listPost(model, slug, page);
} else if (optionService.getTagsPrefix().equals(prefix)) {
return tagModel.listPost(model, slug, page);
} else {
throw new NotFoundException("Not Found");
} }
if (optionService.getTagsPrefix().equals(prefix)) {
return tagModel.listPost(model, slug, page);
}
throw new NotFoundException("Not Found");
} }
@GetMapping("{year:\\d+}/{month:\\d+}/{slug}") @GetMapping("{year:\\d+}/{month:\\d+}/{slug}")
@ -167,9 +186,9 @@ public class ContentContentController {
if (postPermalinkType.equals(PostPermalinkType.DATE)) { if (postPermalinkType.equals(PostPermalinkType.DATE)) {
Post post = postService.getBy(year, month, slug); Post post = postService.getBy(year, month, slug);
return postModel.content(post, token, model); return postModel.content(post, token, model);
} else {
throw new NotFoundException("Not Found");
} }
throw new NotFoundException("Not Found");
} }
@GetMapping("{year:\\d+}/{month:\\d+}/{day:\\d+}/{slug}") @GetMapping("{year:\\d+}/{month:\\d+}/{day:\\d+}/{slug}")
@ -183,9 +202,9 @@ public class ContentContentController {
if (postPermalinkType.equals(PostPermalinkType.DAY)) { if (postPermalinkType.equals(PostPermalinkType.DAY)) {
Post post = postService.getBy(year, month, day, slug); Post post = postService.getBy(year, month, day, slug);
return postModel.content(post, token, model); return postModel.content(post, token, model);
} else {
throw new NotFoundException("Not Found");
} }
throw new NotFoundException("Not Found");
} }
@PostMapping(value = "archives/{slug:.*}/password") @PostMapping(value = "archives/{slug:.*}/password")

View File

@ -31,7 +31,12 @@ public enum PostPermalinkType implements ValueEnum<Integer> {
/** /**
* /1970/${slug} * /1970/${slug}
*/ */
YEAR(4); YEAR(4),
/**
* archives/${id}
*/
ID_SLUG(5);
private final Integer value; private final Integer value;

View File

@ -158,6 +158,11 @@ public class PostCommentServiceImpl extends BaseCommentServiceImpl<PostComment>
.append(URL_SEPARATOR) .append(URL_SEPARATOR)
.append(post.getSlug()) .append(post.getSlug())
.append(pathSuffix); .append(pathSuffix);
} else if (permalinkType.equals(PostPermalinkType.ID_SLUG)) {
fullPath.append(archivesPrefix)
.append(URL_SEPARATOR)
.append(post.getId())
.append(pathSuffix);
} }
post.setFullPath(fullPath.toString()); post.setFullPath(fullPath.toString());

View File

@ -872,6 +872,11 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
.append(URL_SEPARATOR) .append(URL_SEPARATOR)
.append(post.getSlug()) .append(post.getSlug())
.append(pathSuffix); .append(pathSuffix);
} else if (permalinkType.equals(PostPermalinkType.ID_SLUG)) {
fullPath.append(archivesPrefix)
.append(URL_SEPARATOR)
.append(post.getId())
.append(pathSuffix);
} }
return fullPath.toString(); return fullPath.toString();
} }