diff --git a/src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java b/src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java index 3d209392c..172a4032e 100644 --- a/src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java +++ b/src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java @@ -242,6 +242,7 @@ public class WebMvcAutoConfiguration extends WebMvcConfigurationSupport { blackPatterns.add("/fonts/**"); blackPatterns.add("/css/**"); blackPatterns.add("/assets/**"); + blackPatterns.add("/color.less"); blackPatterns.add("/swagger-ui.html"); blackPatterns.add("/csrf"); blackPatterns.add("/webjars/**"); diff --git a/src/main/java/run/halo/app/controller/content/ContentContentController.java b/src/main/java/run/halo/app/controller/content/ContentContentController.java index 5a77ed174..4f6af7d23 100644 --- a/src/main/java/run/halo/app/controller/content/ContentContentController.java +++ b/src/main/java/run/halo/app/controller/content/ContentContentController.java @@ -83,7 +83,7 @@ public class ContentContentController { public String content(@PathVariable("prefix") String prefix, Model model) { if (optionService.getArchivesPrefix().equals(prefix)) { - return postModel.list(1, model, "is_archives", "archives"); + return postModel.archives(1, model); } else if (optionService.getCategoriesPrefix().equals(prefix)) { return categoryModel.list(model); } else if (optionService.getTagsPrefix().equals(prefix)) { @@ -105,7 +105,7 @@ public class ContentContentController { @PathVariable(value = "page") Integer page, Model model) { if (optionService.getArchivesPrefix().equals(prefix)) { - return postModel.list(page, model, "is_archives", "archives"); + return postModel.archives(page, model); } else if (optionService.getJournalsPrefix().equals(prefix)) { return journalModel.list(page, model); } else if (optionService.getPhotosPrefix().equals(prefix)) { diff --git a/src/main/java/run/halo/app/controller/content/ContentIndexController.java b/src/main/java/run/halo/app/controller/content/ContentIndexController.java index 555549a84..15e8c1fdc 100644 --- a/src/main/java/run/halo/app/controller/content/ContentIndexController.java +++ b/src/main/java/run/halo/app/controller/content/ContentIndexController.java @@ -70,6 +70,6 @@ public class ContentIndexController { @GetMapping(value = "page/{page}") public String index(Model model, @PathVariable(value = "page") Integer page) { - return postModel.list(page, model, "is_index", "index"); + return postModel.list(page, model); } } diff --git a/src/main/java/run/halo/app/controller/content/model/PostModel.java b/src/main/java/run/halo/app/controller/content/model/PostModel.java index 197e13d2d..3f1189310 100644 --- a/src/main/java/run/halo/app/controller/content/model/PostModel.java +++ b/src/main/java/run/halo/app/controller/content/model/PostModel.java @@ -5,6 +5,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.stereotype.Component; import org.springframework.ui.Model; import run.halo.app.cache.StringCacheStore; @@ -17,6 +18,7 @@ import run.halo.app.model.enums.PostEditorType; import run.halo.app.model.enums.PostStatus; import run.halo.app.model.support.HaloConst; import run.halo.app.model.vo.AdjacentPostVO; +import run.halo.app.model.vo.ArchiveYearVO; import run.halo.app.model.vo.PostListVO; import run.halo.app.service.*; import run.halo.app.utils.MarkdownUtils; @@ -119,7 +121,7 @@ public class PostModel { return themeService.render("post"); } - public String list(Integer page, Model model, String decide, String template) { + public String list(Integer page, Model model) { int pageSize = optionService.getPostPageSize(); Pageable pageable = PageRequest .of(page >= 1 ? page - 1 : page, pageSize, postService.getPostDefaultSort()); @@ -151,12 +153,62 @@ public class PostModel { .append(optionService.getPathSuffix()); } - model.addAttribute(decide, true); + model.addAttribute("is_index", true); model.addAttribute("posts", posts); model.addAttribute("rainbow", rainbow); model.addAttribute("pageRainbow", rainbow); model.addAttribute("nextPageFullPath", nextPageFullPath.toString()); model.addAttribute("prePageFullPath", prePageFullPath.toString()); - return themeService.render(template); + return themeService.render("index"); + } + + public String archives(Integer page, Model model) { + int pageSize = optionService.getPostPageSize(); + Pageable pageable = PageRequest + .of(page >= 1 ? page - 1 : page, pageSize, Sort.by(Sort.Direction.DESC, "createTime")); + + Page postPage = postService.pageBy(PostStatus.PUBLISHED, pageable); + + Page posts = postService.convertToListVo(postPage); + + List archives = postService.convertToYearArchives(postPage.getContent()); + + // TODO remove this variable + int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3); + + // Next page and previous page url. + StringBuilder nextPageFullPath = new StringBuilder(); + StringBuilder prePageFullPath = new StringBuilder(); + + if (optionService.isEnabledAbsolutePath()) { + nextPageFullPath.append(optionService.getBlogBaseUrl()); + prePageFullPath.append(optionService.getBlogBaseUrl()); + } + + nextPageFullPath.append("/") + .append(optionService.getArchivesPrefix()); + prePageFullPath.append("/") + .append(optionService.getArchivesPrefix()); + + nextPageFullPath.append("/page/") + .append(posts.getNumber() + 2) + .append(optionService.getPathSuffix()); + + if (posts.getNumber() == 1) { + prePageFullPath.append("/"); + } else { + prePageFullPath.append("/page/") + .append(posts.getNumber()) + .append(optionService.getPathSuffix()); + } + + model.addAttribute("is_archives", true); + model.addAttribute("posts", posts); + model.addAttribute("archives", archives); + model.addAttribute("rainbow", rainbow); + model.addAttribute("pageRainbow", rainbow); + model.addAttribute("nextPageFullPath", nextPageFullPath.toString()); + model.addAttribute("prePageFullPath", prePageFullPath.toString()); + return themeService.render("archives"); } } diff --git a/src/main/java/run/halo/app/model/vo/ArchiveYearVO.java b/src/main/java/run/halo/app/model/vo/ArchiveYearVO.java index 525012c86..30b3f16f7 100644 --- a/src/main/java/run/halo/app/model/vo/ArchiveYearVO.java +++ b/src/main/java/run/halo/app/model/vo/ArchiveYearVO.java @@ -3,7 +3,6 @@ package run.halo.app.model.vo; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -import run.halo.app.model.dto.post.BasePostMinimalDTO; import java.util.Comparator; import java.util.List; @@ -21,7 +20,7 @@ public class ArchiveYearVO { private Integer year; - private List posts; + private List posts; public static class ArchiveComparator implements Comparator { diff --git a/src/main/java/run/halo/app/service/PostService.java b/src/main/java/run/halo/app/service/PostService.java index ced1e9fe0..587ed381c 100755 --- a/src/main/java/run/halo/app/service/PostService.java +++ b/src/main/java/run/halo/app/service/PostService.java @@ -167,6 +167,22 @@ public interface PostService extends BasePostService { @NonNull List listMonthArchives(); + /** + * Convert to year archives + * + * @param posts posts must not be null + * @return list of ArchiveYearVO + */ + List convertToYearArchives(@NonNull List posts); + + /** + * Convert to month archives + * + * @param posts posts must not be null + * @return list of ArchiveMonthVO + */ + List convertToMonthArchives(@NonNull List posts); + /** * Import post from markdown document. * diff --git a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java index bb4bfe597..63da40e2f 100644 --- a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java @@ -242,6 +242,20 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe List posts = postRepository .findAllByStatus(PostStatus.PUBLISHED, Sort.by(DESC, "createTime")); + return convertToYearArchives(posts); + } + + @Override + public List listMonthArchives() { + // Get all posts + List posts = postRepository + .findAllByStatus(PostStatus.PUBLISHED, Sort.by(DESC, "createTime")); + + return convertToMonthArchives(posts); + } + + @Override + public List convertToYearArchives(List posts) { Map> yearPostMap = new HashMap<>(8); posts.forEach(post -> { @@ -256,7 +270,7 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe // Build archive ArchiveYearVO archive = new ArchiveYearVO(); archive.setYear(year); - archive.setPosts(convertToMinimal(postList)); + archive.setPosts(convertToListVo(postList)); // Add archive archives.add(archive); @@ -269,10 +283,7 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe } @Override - public List listMonthArchives() { - // Get all posts - List posts = postRepository - .findAllByStatus(PostStatus.PUBLISHED, Sort.by(DESC, "createTime")); + public List convertToMonthArchives(List posts) { Map>> yearMonthPostMap = new HashMap<>(8); @@ -292,7 +303,7 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe ArchiveMonthVO archive = new ArchiveMonthVO(); archive.setYear(year); archive.setMonth(month); - archive.setPosts(convertToMinimal(postList)); + archive.setPosts(convertToListVo(postList)); archives.add(archive); })); diff --git a/src/main/resources/templates/themes/anatole b/src/main/resources/templates/themes/anatole index 9d604ccaa..b50e52376 160000 --- a/src/main/resources/templates/themes/anatole +++ b/src/main/resources/templates/themes/anatole @@ -1 +1 @@ -Subproject commit 9d604ccaac74c4a3a93c71d6c294cf799910ce22 +Subproject commit b50e52376237f47b9da289d8feafe891332e0943