mirror of https://github.com/halo-dev/halo
refactor: post month path type. (#635)
parent
22b24835aa
commit
437e59d8a2
|
@ -104,13 +104,21 @@ public class PostCommentServiceImpl extends BaseCommentServiceImpl<PostComment>
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private BasePostMinimalDTO buildPostFullPath(BasePostMinimalDTO basePostMinimalDTO) {
|
private BasePostMinimalDTO buildPostFullPath(BasePostMinimalDTO post) {
|
||||||
PostPermalinkType permalinkType = optionService.getPostPermalinkType();
|
PostPermalinkType permalinkType = optionService.getPostPermalinkType();
|
||||||
|
|
||||||
String pathSuffix = optionService.getPathSuffix();
|
String pathSuffix = optionService.getPathSuffix();
|
||||||
|
|
||||||
String archivesPrefix = optionService.getArchivesPrefix();
|
String archivesPrefix = optionService.getArchivesPrefix();
|
||||||
|
|
||||||
|
int month = DateUtil.month(post.getCreateTime()) + 1;
|
||||||
|
|
||||||
|
String monthString = month < 10 ? "0" + month : String.valueOf(month);
|
||||||
|
|
||||||
|
int day = DateUtil.dayOfMonth(post.getCreateTime());
|
||||||
|
|
||||||
|
String dayString = day < 10 ? "0" + day : String.valueOf(day);
|
||||||
|
|
||||||
StringBuilder fullPath = new StringBuilder();
|
StringBuilder fullPath = new StringBuilder();
|
||||||
|
|
||||||
if (optionService.isEnabledAbsolutePath()) {
|
if (optionService.isEnabledAbsolutePath()) {
|
||||||
|
@ -122,32 +130,32 @@ public class PostCommentServiceImpl extends BaseCommentServiceImpl<PostComment>
|
||||||
if (permalinkType.equals(PostPermalinkType.DEFAULT)) {
|
if (permalinkType.equals(PostPermalinkType.DEFAULT)) {
|
||||||
fullPath.append(archivesPrefix)
|
fullPath.append(archivesPrefix)
|
||||||
.append("/")
|
.append("/")
|
||||||
.append(basePostMinimalDTO.getSlug())
|
.append(post.getSlug())
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
} else if (permalinkType.equals(PostPermalinkType.ID)) {
|
} else if (permalinkType.equals(PostPermalinkType.ID)) {
|
||||||
fullPath.append("?p=")
|
fullPath.append("?p=")
|
||||||
.append(basePostMinimalDTO.getId());
|
.append(post.getId());
|
||||||
} else if (permalinkType.equals(PostPermalinkType.DATE)) {
|
} else if (permalinkType.equals(PostPermalinkType.DATE)) {
|
||||||
fullPath.append(DateUtil.year(basePostMinimalDTO.getCreateTime()))
|
fullPath.append(DateUtil.year(post.getCreateTime()))
|
||||||
.append("/")
|
.append("/")
|
||||||
.append(DateUtil.month(basePostMinimalDTO.getCreateTime()) + 1)
|
.append(monthString)
|
||||||
.append("/")
|
.append("/")
|
||||||
.append(basePostMinimalDTO.getSlug())
|
.append(post.getSlug())
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
} else if (permalinkType.equals(PostPermalinkType.DAY)) {
|
} else if (permalinkType.equals(PostPermalinkType.DAY)) {
|
||||||
fullPath.append(DateUtil.year(basePostMinimalDTO.getCreateTime()))
|
fullPath.append(DateUtil.year(post.getCreateTime()))
|
||||||
.append("/")
|
.append("/")
|
||||||
.append(DateUtil.month(basePostMinimalDTO.getCreateTime()) + 1)
|
.append(monthString)
|
||||||
.append("/")
|
.append("/")
|
||||||
.append(DateUtil.dayOfMonth(basePostMinimalDTO.getCreateTime()))
|
.append(dayString)
|
||||||
.append("/")
|
.append("/")
|
||||||
.append(basePostMinimalDTO.getSlug())
|
.append(post.getSlug())
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
}
|
}
|
||||||
|
|
||||||
basePostMinimalDTO.setFullPath(fullPath.toString());
|
post.setFullPath(fullPath.toString());
|
||||||
|
|
||||||
return basePostMinimalDTO;
|
return post;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -871,6 +871,14 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
||||||
|
|
||||||
String archivesPrefix = optionService.getArchivesPrefix();
|
String archivesPrefix = optionService.getArchivesPrefix();
|
||||||
|
|
||||||
|
int month = DateUtil.month(post.getCreateTime()) + 1;
|
||||||
|
|
||||||
|
String monthString = month < 10 ? "0" + month : String.valueOf(month);
|
||||||
|
|
||||||
|
int day = DateUtil.dayOfMonth(post.getCreateTime());
|
||||||
|
|
||||||
|
String dayString = day < 10 ? "0" + day : String.valueOf(day);
|
||||||
|
|
||||||
StringBuilder fullPath = new StringBuilder();
|
StringBuilder fullPath = new StringBuilder();
|
||||||
|
|
||||||
if (optionService.isEnabledAbsolutePath()) {
|
if (optionService.isEnabledAbsolutePath()) {
|
||||||
|
@ -890,16 +898,16 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
||||||
} else if (permalinkType.equals(PostPermalinkType.DATE)) {
|
} else if (permalinkType.equals(PostPermalinkType.DATE)) {
|
||||||
fullPath.append(DateUtil.year(post.getCreateTime()))
|
fullPath.append(DateUtil.year(post.getCreateTime()))
|
||||||
.append("/")
|
.append("/")
|
||||||
.append(DateUtil.month(post.getCreateTime()) + 1)
|
.append(monthString)
|
||||||
.append("/")
|
.append("/")
|
||||||
.append(post.getSlug())
|
.append(post.getSlug())
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
} else if (permalinkType.equals(PostPermalinkType.DAY)) {
|
} else if (permalinkType.equals(PostPermalinkType.DAY)) {
|
||||||
fullPath.append(DateUtil.year(post.getCreateTime()))
|
fullPath.append(DateUtil.year(post.getCreateTime()))
|
||||||
.append("/")
|
.append("/")
|
||||||
.append(DateUtil.month(post.getCreateTime()) + 1)
|
.append(monthString)
|
||||||
.append("/")
|
.append("/")
|
||||||
.append(DateUtil.dayOfMonth(post.getCreateTime()))
|
.append(dayString)
|
||||||
.append("/")
|
.append("/")
|
||||||
.append(post.getSlug())
|
.append(post.getSlug())
|
||||||
.append(pathSuffix);
|
.append(pathSuffix);
|
||||||
|
|
Loading…
Reference in New Issue