Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: #1103 #1173

Merged
merged 1 commit into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,17 @@ public String content(@PathVariable("prefix") String prefix,
Model model) {
if (optionService.getArchivesPrefix().equals(prefix)) {
return postModel.archives(page, model);
} else if (optionService.getJournalsPrefix().equals(prefix)) {
}

if (optionService.getJournalsPrefix().equals(prefix)) {
return journalModel.list(page, model);
} else if (optionService.getPhotosPrefix().equals(prefix)) {
}

if (optionService.getPhotosPrefix().equals(prefix)) {
return photoModel.list(page, model);
} else {
throw new NotFoundException("Not Found");
}

throw new NotFoundException("Not Found");
}

@GetMapping("{prefix}/{slug}")
Expand All @@ -124,23 +128,36 @@ public String content(@PathVariable("prefix") String prefix,
@RequestParam(value = "token", required = false) String token,
Model model) {
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)) {
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)) {
if (optionService.getSheetPrefix().equals(prefix)) {
Sheet sheet = sheetService.getBySlug(slug);
return sheetModel.content(sheet, token, model);
} else if (optionService.getCategoriesPrefix().equals(prefix)) {
}

if (optionService.getCategoriesPrefix().equals(prefix)) {
return categoryModel.listPost(model, slug, 1);
} else if (optionService.getTagsPrefix().equals(prefix)) {
}

if (optionService.getTagsPrefix().equals(prefix)) {
return tagModel.listPost(model, slug, 1);
} else {
throw new NotFoundException("Not Found");
}

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+}")
Expand All @@ -150,11 +167,13 @@ public String content(@PathVariable("prefix") String prefix,
Model model) {
if (optionService.getCategoriesPrefix().equals(prefix)) {
return categoryModel.listPost(model, slug, page);
} else if (optionService.getTagsPrefix().equals(prefix)) {
}

if (optionService.getTagsPrefix().equals(prefix)) {
return tagModel.listPost(model, slug, page);
} else {
throw new NotFoundException("Not Found");
}

throw new NotFoundException("Not Found");
}

@GetMapping("{year:\\d+}/{month:\\d+}/{slug}")
Expand All @@ -167,9 +186,9 @@ public String content(@PathVariable("year") Integer year,
if (postPermalinkType.equals(PostPermalinkType.DATE)) {
Post post = postService.getBy(year, month, slug);
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}")
Expand All @@ -183,9 +202,9 @@ public String content(@PathVariable("year") Integer year,
if (postPermalinkType.equals(PostPermalinkType.DAY)) {
Post post = postService.getBy(year, month, day, slug);
return postModel.content(post, token, model);
} else {
throw new NotFoundException("Not Found");
}

throw new NotFoundException("Not Found");
}

@PostMapping(value = "archives/{slug:.*}/password")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ public enum PostPermalinkType implements ValueEnum<Integer> {
/**
* /1970/${slug}
*/
YEAR(4);
YEAR(4),

/**
* archives/${id}
*/
ID_SLUG(5);

private final Integer value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ private BasePostMinimalDTO buildPostFullPath(BasePostMinimalDTO post) {
.append(URL_SEPARATOR)
.append(post.getSlug())
.append(pathSuffix);
} else if (permalinkType.equals(PostPermalinkType.ID_SLUG)) {
fullPath.append(archivesPrefix)
.append(URL_SEPARATOR)
.append(post.getId())
.append(pathSuffix);
}

post.setFullPath(fullPath.toString());
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/run/halo/app/service/impl/PostServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,11 @@ private String buildFullPath(Post post) {
.append(URL_SEPARATOR)
.append(post.getSlug())
.append(pathSuffix);
} else if (permalinkType.equals(PostPermalinkType.ID_SLUG)) {
fullPath.append(archivesPrefix)
.append(URL_SEPARATOR)
.append(post.getId())
.append(pathSuffix);
}
return fullPath.toString();
}
Expand Down