diff --git a/src/main/java/run/halo/app/controller/content/ContentFeedController.java b/src/main/java/run/halo/app/controller/content/ContentFeedController.java index 13b790130..f11052078 100644 --- a/src/main/java/run/halo/app/controller/content/ContentFeedController.java +++ b/src/main/java/run/halo/app/controller/content/ContentFeedController.java @@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer; import run.halo.app.model.entity.Post; import run.halo.app.model.enums.PostStatus; -import run.halo.app.model.vo.PostListVO; +import run.halo.app.model.vo.PostDetailVO; import run.halo.app.service.OptionService; import run.halo.app.service.PostService; @@ -79,7 +79,7 @@ public class ContentFeedController { @GetMapping(value = {"atom", "atom.xml"}, produces = XML_MEDIA_TYPE) @ResponseBody public String atom(Model model) throws IOException, TemplateException { - model.addAttribute("posts", buildPosts(buildPostPageable(optionService.getPostPageSize()))); + model.addAttribute("posts", buildPosts(buildPostPageable(optionService.getRssPageSize()))); Template template = freeMarker.getConfiguration().getTemplate("common/web/atom.ftl"); return FreeMarkerTemplateUtils.processTemplateIntoString(template, model); } @@ -146,9 +146,9 @@ public class ContentFeedController { * @param pageable pageable * @return List */ - private List buildPosts(@NonNull Pageable pageable) { + private List buildPosts(@NonNull Pageable pageable) { Page postPage = postService.pageBy(PostStatus.PUBLISHED, pageable); - Page posts = postService.convertToListVo(postPage); + Page posts = postService.convertToDetailVo(postPage); posts.getContent().forEach(postListVO -> { try { // Encode post url diff --git a/src/main/java/run/halo/app/model/properties/PostProperties.java b/src/main/java/run/halo/app/model/properties/PostProperties.java index 0c9db35ea..5b7146dd6 100644 --- a/src/main/java/run/halo/app/model/properties/PostProperties.java +++ b/src/main/java/run/halo/app/model/properties/PostProperties.java @@ -8,12 +8,29 @@ package run.halo.app.model.properties; */ public enum PostProperties implements PropertyEnum { + /** + * Post summary words length. + */ SUMMARY_LENGTH("post_summary_length", Integer.class, "150"), + /** + * Rss page size. + */ RSS_PAGE_SIZE("rss_page_size", Integer.class, "20"), + /** + * Rss content type,full or summary. + */ + RSS_CONTENT_TYPE("rss_content_type", Integer.class, "full"), + + /** + * Post index page size. + */ INDEX_PAGE_SIZE("post_index_page_size", Integer.class, "10"), + /** + * Post index sort. + */ INDEX_SORT("post_index_sort", String.class, "createTime"); private final String value; diff --git a/src/main/java/run/halo/app/service/PostService.java b/src/main/java/run/halo/app/service/PostService.java index ee2e08b7e..e9bb6c29a 100755 --- a/src/main/java/run/halo/app/service/PostService.java +++ b/src/main/java/run/halo/app/service/PostService.java @@ -3,6 +3,7 @@ package run.halo.app.service; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.lang.NonNull; +import run.halo.app.model.dto.post.BasePostDetailDTO; import run.halo.app.model.entity.Post; import run.halo.app.model.entity.PostMeta; import run.halo.app.model.enums.PostStatus; @@ -166,4 +167,19 @@ public interface PostService extends BasePostService { @NonNull Page convertToListVo(@NonNull Page postPage); + /** + * Converts to a page of post detail dto. + * + * @param postPage post page must not be null + * @return a page of post detail dto + */ + Page convertToDetailDto(@NonNull Page postPage); + + /** + * Converts to a page of detail vo. + * + * @param postPage post page must not be null + * @return a page of post detail vo + */ + Page convertToDetailVo(@NonNull Page postPage); } 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 373f93699..e427ccced 100644 --- a/src/main/java/run/halo/app/service/impl/PostServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/PostServiceImpl.java @@ -21,6 +21,7 @@ import run.halo.app.event.post.PostVisitEvent; import run.halo.app.model.dto.BaseMetaDTO; import run.halo.app.model.dto.CategoryDTO; import run.halo.app.model.dto.TagDTO; +import run.halo.app.model.dto.post.BasePostDetailDTO; import run.halo.app.model.entity.*; import run.halo.app.model.enums.LogType; import run.halo.app.model.enums.PostStatus; @@ -485,6 +486,25 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe }); } + @Override + public Page convertToDetailDto(Page postPage) { + Assert.notNull(postPage, "Post page must not be null"); + + return postPage.map(post -> { + BasePostDetailDTO postDetailDTO = new BasePostDetailDTO().convertFrom(post); + if (StringUtils.isBlank(postDetailDTO.getSummary())) { + postDetailDTO.setSummary(generateSummary(post.getFormatContent())); + } + return postDetailDTO; + }); + } + + @Override + public Page convertToDetailVo(Page postPage) { + Assert.notNull(postPage, "Post page must not be null"); + return postPage.map(this::convertToDetailVo); + } + /** * Converts to post detail vo. * @@ -501,6 +521,10 @@ public class PostServiceImpl extends BasePostServiceImpl implements PostSe // Convert to base detail vo PostDetailVO postDetailVO = new PostDetailVO().convertFrom(post); + if (StringUtils.isBlank(postDetailVO.getSummary())) { + postDetailVO.setSummary(generateSummary(post.getFormatContent())); + } + // Extract ids Set tagIds = ServiceUtils.fetchProperty(tags, Tag::getId); Set categoryIds = ServiceUtils.fetchProperty(categories, Category::getId); diff --git a/src/main/resources/templates/common/web/atom.ftl b/src/main/resources/templates/common/web/atom.ftl index e837b966e..a8ac4eb18 100644 --- a/src/main/resources/templates/common/web/atom.ftl +++ b/src/main/resources/templates/common/web/atom.ftl @@ -14,7 +14,7 @@ zh-CN hourly 1 - https://github.com/halo-dev/halo + https://halo.run <#if posts?? && posts?size gt 0> <#list posts as post> @@ -26,8 +26,8 @@ <#if post.categories?? && post.categories?size gt 0> - <#list post.categories as cate> - + <#list post.categories as category> + @@ -37,10 +37,13 @@ + ${post.formatContent!} + <#else> + ${post.summary!} + ]]> - ${post.commentCount!0} diff --git a/src/main/resources/templates/common/web/rss.ftl b/src/main/resources/templates/common/web/rss.ftl index b8e799141..54a96be3f 100644 --- a/src/main/resources/templates/common/web/rss.ftl +++ b/src/main/resources/templates/common/web/rss.ftl @@ -18,7 +18,11 @@ ${options.blog_url}/archives/${post.url!} + ${post.formatContent!} + <#else> + ${post.summary!} + ]]> ${post.createTime} diff --git a/src/main/resources/templates/common/web/sitemap_html.ftl b/src/main/resources/templates/common/web/sitemap_html.ftl index 9e24e0f09..cb15b1e7e 100644 --- a/src/main/resources/templates/common/web/sitemap_html.ftl +++ b/src/main/resources/templates/common/web/sitemap_html.ftl @@ -18,7 +18,7 @@ see https://gitee.com/yadong.zhang/DBlog/blob/master/blog-web/src/main/java/com/ font-size: 14px; } - #myTable { + #contentTable { list-style: none; margin: 10px 0 10px 0; padding: 0; @@ -26,7 +26,7 @@ see https://gitee.com/yadong.zhang/DBlog/blob/master/blog-web/src/main/java/com/ min-width: 804px; } - #myTable li { + #contentTable li { list-style-type: none; width: 100%; min-width: 404px; @@ -42,39 +42,39 @@ see https://gitee.com/yadong.zhang/DBlog/blob/master/blog-web/src/main/java/com/ float: right!important; } - #myTable li .T1-h { + #contentTable li .T1-h { font-weight: bold; min-width: 300px; } - #myTable li .T2-h { + #contentTable li .T2-h { width: 200px; font-weight: bold; } - #myTable li .T3-h { + #contentTable li .T3-h { width: 200px; font-weight: bold; } - #myTable li .T4-h { + #contentTable li .T4-h { width: 100px; font-weight: bold; } - #myTable li .T1 { + #contentTable li .T1 { min-width: 300px; } - #myTable li .T2 { + #contentTable li .T2 { width: 200px; } - #myTable li .T3 { + #contentTable li .T3 { width: 200px; } - #myTable li .T4 { + #contentTable li .T4 { width: 100px; } @@ -90,7 +90,7 @@ see https://gitee.com/yadong.zhang/DBlog/blob/master/blog-web/src/main/java/com/ color: gray; } - .myClear { + .clear { clear: both; } @@ -107,7 +107,7 @@ see https://gitee.com/yadong.zhang/DBlog/blob/master/blog-web/src/main/java/com/ .T2-h, .T3-h, .T4-h, .T2, .T3, .T4 { display: none; } - #myTable, #footer, #myTable li .T1, #myTable li, #myTable li .T1-h, #myTable li .T1 { + #contentTable, #footer, #contentTable li .T1, #contentTable li, #contentTable li .T1-h, #contentTable li .T1 { max-width: 100%; min-width: auto; white-space: nowrap; @@ -123,21 +123,21 @@ see https://gitee.com/yadong.zhang/DBlog/blob/master/blog-web/src/main/java/com/

最新文章

-
    +
    • URL
      Last Change
      Change Frequency
      Priority
    • -
      +
    • ${options.blog_start!}
      daily
      1
    • -
      +
      <#if posts?? && posts?size gt 0> <#list posts as post>
    • @@ -146,14 +146,14 @@ see https://gitee.com/yadong.zhang/DBlog/blob/master/blog-web/src/main/java/com/
      daily
      0.6
    • -
      +

分类目录

-
    +
      <@categoryTag method="list"> <#if categories?? && categories?size gt 0> <#list categories as cate> @@ -163,7 +163,7 @@ see https://gitee.com/yadong.zhang/DBlog/blob/master/blog-web/src/main/java/com/
      daily
      0.6
      -
      +
      @@ -171,7 +171,7 @@ see https://gitee.com/yadong.zhang/DBlog/blob/master/blog-web/src/main/java/com/

标签目录

-
    +
      <@tagTag method="list"> <#if tags?? && tags?size gt 0> <#list tags as tag> @@ -181,7 +181,7 @@ see https://gitee.com/yadong.zhang/DBlog/blob/master/blog-web/src/main/java/com/
      daily
      0.6
      -
      +