mirror of https://github.com/halo-dev/halo
feat: #424
parent
30eacdb342
commit
6c677c94ef
|
@ -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<Post>
|
||||
*/
|
||||
private List<PostListVO> buildPosts(@NonNull Pageable pageable) {
|
||||
private List<PostDetailVO> buildPosts(@NonNull Pageable pageable) {
|
||||
Page<Post> postPage = postService.pageBy(PostStatus.PUBLISHED, pageable);
|
||||
Page<PostListVO> posts = postService.convertToListVo(postPage);
|
||||
Page<PostDetailVO> posts = postService.convertToDetailVo(postPage);
|
||||
posts.getContent().forEach(postListVO -> {
|
||||
try {
|
||||
// Encode post url
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<Post> {
|
|||
@NonNull
|
||||
Page<PostListVO> convertToListVo(@NonNull Page<Post> 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<BasePostDetailDTO> convertToDetailDto(@NonNull Page<Post> postPage);
|
||||
|
||||
/**
|
||||
* Converts to a page of detail vo.
|
||||
*
|
||||
* @param postPage post page must not be null
|
||||
* @return a page of post detail vo
|
||||
*/
|
||||
Page<PostDetailVO> convertToDetailVo(@NonNull Page<Post> postPage);
|
||||
}
|
||||
|
|
|
@ -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<Post> implements PostSe
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<BasePostDetailDTO> convertToDetailDto(Page<Post> 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<PostDetailVO> convertToDetailVo(Page<Post> 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<Post> 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<Integer> tagIds = ServiceUtils.fetchProperty(tags, Tag::getId);
|
||||
Set<Integer> categoryIds = ServiceUtils.fetchProperty(categories, Category::getId);
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<language>zh-CN</language>
|
||||
<sy:updatePeriod>hourly</sy:updatePeriod>
|
||||
<sy:updateFrequency>1</sy:updateFrequency>
|
||||
<generator>https://github.com/halo-dev/halo</generator>
|
||||
<generator>https://halo.run</generator>
|
||||
</channel>
|
||||
<#if posts?? && posts?size gt 0>
|
||||
<#list posts as post>
|
||||
|
@ -26,8 +26,8 @@
|
|||
<dc:creator><![CDATA[${user.nickname!}]]></dc:creator>
|
||||
|
||||
<#if post.categories?? && post.categories?size gt 0>
|
||||
<#list post.categories as cate>
|
||||
<category><![CDATA[${cate.name!}]]></category>
|
||||
<#list post.categories as category>
|
||||
<category><![CDATA[${category.name!}]]></category>
|
||||
</#list>
|
||||
</#if>
|
||||
<description>
|
||||
|
@ -37,10 +37,13 @@
|
|||
</description>
|
||||
<content:encoded>
|
||||
<![CDATA[
|
||||
${post.summary!}
|
||||
<#if (options.rss_content_type!'full') == 'full'>
|
||||
${post.formatContent!}
|
||||
<#else>
|
||||
${post.summary!}
|
||||
</#if>
|
||||
]]>
|
||||
</content:encoded>
|
||||
<slash:comments>${post.commentCount!0}</slash:comments>
|
||||
</item>
|
||||
</#list>
|
||||
</#if>
|
||||
|
|
|
@ -18,7 +18,11 @@
|
|||
<link>${options.blog_url}/archives/${post.url!}</link>
|
||||
<content:encoded>
|
||||
<![CDATA[
|
||||
${post.summary!}
|
||||
<#if (options.rss_content_type!'full') == 'full'>
|
||||
${post.formatContent!}
|
||||
<#else>
|
||||
${post.summary!}
|
||||
</#if>
|
||||
]]>
|
||||
</content:encoded>
|
||||
<pubDate>${post.createTime}</pubDate>
|
||||
|
|
|
@ -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/
|
|||
<div id="nav"><a href="${context!}"><strong>${options.blog_title!}</strong></a> » <a href="${context!}/sitemap.html">站点地图</a></div>
|
||||
<div id="content">
|
||||
<h3>最新文章</h3>
|
||||
<ul id="myTable">
|
||||
<ul id="contentTable">
|
||||
<li>
|
||||
<div class="T1-h pull-left">URL</div>
|
||||
<div class="T2-h pull-right">Last Change</div>
|
||||
<div class="T3-h pull-right">Change Frequency</div>
|
||||
<div class="T4-h pull-right">Priority</div>
|
||||
</li>
|
||||
<div class="myClear"></div>
|
||||
<div class="clear"></div>
|
||||
<li>
|
||||
<div class="T1 pull-left"><a href="${context!}" title="${options.blog_title!}">${options.blog_title!}</a></div>
|
||||
<div class="T2 pull-right">${options.blog_start!}</div>
|
||||
<div class="T3 pull-right">daily</div>
|
||||
<div class="T4 pull-right">1</div>
|
||||
</li>
|
||||
<div class="myClear"></div>
|
||||
<div class="clear"></div>
|
||||
<#if posts?? && posts?size gt 0>
|
||||
<#list posts as post>
|
||||
<li>
|
||||
|
@ -146,14 +146,14 @@ see https://gitee.com/yadong.zhang/DBlog/blob/master/blog-web/src/main/java/com/
|
|||
<div class="T3 pull-right">daily</div>
|
||||
<div class="T4 pull-right">0.6</div>
|
||||
</li>
|
||||
<div class="myClear"></div>
|
||||
<div class="clear"></div>
|
||||
</#list>
|
||||
</#if>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="content">
|
||||
<h3>分类目录</h3>
|
||||
<ul id="myTable">
|
||||
<ul id="contentTable">
|
||||
<@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/
|
|||
<div class="T3 pull-right">daily</div>
|
||||
<div class="T4 pull-right">0.6</div>
|
||||
</li>
|
||||
<div class="myClear"></div>
|
||||
<div class="clear"></div>
|
||||
</#list>
|
||||
</#if>
|
||||
</@categoryTag>
|
||||
|
@ -171,7 +171,7 @@ see https://gitee.com/yadong.zhang/DBlog/blob/master/blog-web/src/main/java/com/
|
|||
</div>
|
||||
<div id="content">
|
||||
<h3>标签目录</h3>
|
||||
<ul id="myTable">
|
||||
<ul id="contentTable">
|
||||
<@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/
|
|||
<div class="T3 pull-right">daily</div>
|
||||
<div class="T4 pull-right">0.6</div>
|
||||
</li>
|
||||
<div class="myClear"></div>
|
||||
<div class="clear"></div>
|
||||
</#list>
|
||||
</#if>
|
||||
</@tagTag>
|
||||
|
|
Loading…
Reference in New Issue