mirror of https://github.com/halo-dev/halo
Merge branch 'v1' of C:\Users\RYAN0UP\Desktop\halo with conflicts.
parent
2184102c68
commit
1c0b225dee
|
@ -94,10 +94,12 @@ public class HaloUtils {
|
|||
*
|
||||
* @return default page size
|
||||
*/
|
||||
public static int getDefaultPageSize() {
|
||||
return Integer.valueOf(OPTIONS.getOrDefault(
|
||||
BlogProperties.INDEX_POSTS.getValue(),
|
||||
String.valueOf(DEFAULT_PAGE_SIZE)));
|
||||
public static int getDefaultPageSize(int pageSize) {
|
||||
if (StrUtil.isNotBlank(OPTIONS.get(BlogProperties.INDEX_POSTS))) {
|
||||
return Integer.parseInt(OPTIONS.get(BlogProperties.INDEX_POSTS));
|
||||
}
|
||||
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -5,9 +5,11 @@ import cc.ryanc.halo.model.enums.BlogProperties;
|
|||
import cc.ryanc.halo.model.enums.PostStatus;
|
||||
import cc.ryanc.halo.model.enums.PostType;
|
||||
import cc.ryanc.halo.service.PostService;
|
||||
import cc.ryanc.halo.utils.HaloUtils;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
import javafx.geometry.Pos;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
@ -57,15 +59,7 @@ public class ContentFeedController {
|
|||
}
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
final Pageable pageable = PageRequest.of(0, Integer.parseInt(rssPosts), sort);
|
||||
final Page<Post> postsPage = postService.pageBy(PostStatus.PUBLISHED, PostType.POST, pageable).map(post -> {
|
||||
if (StrUtil.isNotEmpty(post.getPassword())) {
|
||||
post.setFormatContent("该文章为加密文章");
|
||||
post.setSummary("该文章为加密文章");
|
||||
}
|
||||
return post;
|
||||
});
|
||||
final List<Post> posts = postsPage.getContent();
|
||||
model.addAttribute("posts", posts);
|
||||
model.addAttribute("posts", buildPosts(pageable));
|
||||
final Template template = freeMarker.getConfiguration().getTemplate("common/web/rss.ftl");
|
||||
return FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
|
||||
}
|
||||
|
@ -81,21 +75,10 @@ public class ContentFeedController {
|
|||
@GetMapping(value = {"atom", "atom.xml"}, produces = "application/xml;charset=UTF-8")
|
||||
@ResponseBody
|
||||
public String atom(Model model) throws IOException, TemplateException {
|
||||
String rssPosts = OPTIONS.get(BlogProperties.RSS_POSTS.getValue());
|
||||
if (StrUtil.isBlank(rssPosts)) {
|
||||
rssPosts = "20";
|
||||
}
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "postDate");
|
||||
final Pageable pageable = PageRequest.of(0, Integer.parseInt(rssPosts), sort);
|
||||
final Page<Post> postsPage = postService.pageBy(PostStatus.PUBLISHED, PostType.POST, pageable).map(post -> {
|
||||
if (StrUtil.isNotEmpty(post.getPassword())) {
|
||||
post.setFormatContent("该文章为加密文章");
|
||||
post.setSummary("该文章为加密文章");
|
||||
}
|
||||
return post;
|
||||
});
|
||||
final List<Post> posts = postsPage.getContent();
|
||||
model.addAttribute("posts", posts);
|
||||
int pageSize = HaloUtils.getDefaultPageSize(20);
|
||||
final Sort sort = new Sort(Sort.Direction.DESC, "createTime");
|
||||
final Pageable pageable = PageRequest.of(0, pageSize, sort);
|
||||
model.addAttribute("posts", buildPosts(pageable));
|
||||
final Template template = freeMarker.getConfiguration().getTemplate("common/web/atom.ftl");
|
||||
return FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
|
||||
}
|
||||
|
@ -111,15 +94,7 @@ public class ContentFeedController {
|
|||
@GetMapping(value = {"sitemap", "sitemap.xml"}, produces = "application/xml;charset=UTF-8")
|
||||
@ResponseBody
|
||||
public String sitemapXml(Model model) throws IOException, TemplateException {
|
||||
final Page<Post> postsPage = postService.pageBy(PostStatus.PUBLISHED, PostType.POST, null).map(post -> {
|
||||
if (StrUtil.isNotEmpty(post.getPassword())) {
|
||||
post.setFormatContent("该文章为加密文章");
|
||||
post.setSummary("该文章为加密文章");
|
||||
}
|
||||
return post;
|
||||
});
|
||||
final List<Post> posts = postsPage.getContent();
|
||||
model.addAttribute("posts", posts);
|
||||
model.addAttribute("posts", buildPosts(null));
|
||||
final Template template = freeMarker.getConfiguration().getTemplate("common/web/sitemap_xml.ftl");
|
||||
return FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
|
||||
}
|
||||
|
@ -132,15 +107,7 @@ public class ContentFeedController {
|
|||
*/
|
||||
@GetMapping(value = "sitemap.html", produces = {"text/html"})
|
||||
public String sitemapHtml(Model model) {
|
||||
final Page<Post> postsPage = postService.pageBy(PostStatus.PUBLISHED, PostType.POST, null).map(post -> {
|
||||
if (StrUtil.isNotEmpty(post.getPassword())) {
|
||||
post.setFormatContent("该文章为加密文章");
|
||||
post.setSummary("该文章为加密文章");
|
||||
}
|
||||
return post;
|
||||
});
|
||||
final List<Post> posts = postsPage.getContent();
|
||||
model.addAttribute("posts", posts);
|
||||
model.addAttribute("posts", buildPosts(null));
|
||||
return "common/web/sitemap_html";
|
||||
}
|
||||
|
||||
|
@ -158,4 +125,20 @@ public class ContentFeedController {
|
|||
final Template template = freeMarker.getConfiguration().getTemplate("common/web/robots.ftl");
|
||||
return FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build posts for feed
|
||||
* @param pageable pageable
|
||||
* @return List<Post>
|
||||
*/
|
||||
private List<Post> buildPosts(Pageable pageable){
|
||||
final Page<Post> postsPage = postService.pageBy(PostStatus.PUBLISHED, PostType.POST, pageable).map(post -> {
|
||||
if (StrUtil.isNotEmpty(post.getPassword())) {
|
||||
post.setFormatContent("该文章为加密文章");
|
||||
post.setSummary("该文章为加密文章");
|
||||
}
|
||||
return post;
|
||||
});
|
||||
return postsPage.getContent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,14 +65,9 @@ public class ContentIndexController extends BaseContentController {
|
|||
@SortDefault(sort = "createTime", direction = DESC)
|
||||
}) Sort sort) {
|
||||
log.debug("Requested index page, sort info: [{}]", sort);
|
||||
|
||||
int size = HaloUtils.getDefaultPageSize();
|
||||
Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
int pageSize = HaloUtils.getDefaultPageSize(10);
|
||||
Pageable pageable = PageRequest.of(page - 1, pageSize, sort);
|
||||
Page<PostListVO> posts = postService.pageListVoBy(PostStatus.PUBLISHED, PostType.POST, pageable);
|
||||
if (null == posts) {
|
||||
// TODO There will never be null
|
||||
return this.renderNotFound();
|
||||
}
|
||||
int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
||||
model.addAttribute("is_index", true);
|
||||
model.addAttribute("posts", posts);
|
||||
|
|
|
@ -81,7 +81,7 @@ public class ContentTagController extends BaseContentController {
|
|||
if (null == tag) {
|
||||
return this.renderNotFound();
|
||||
}
|
||||
int size = HaloUtils.getDefaultPageSize();
|
||||
int size = HaloUtils.getDefaultPageSize(10);
|
||||
final Pageable pageable = PageRequest.of(page - 1, size, sort);
|
||||
|
||||
// TODO get posts by tag
|
||||
|
|
Loading…
Reference in New Issue