mirror of https://github.com/halo-dev/halo
feat: support set archives page size. (#610)
parent
b70806960b
commit
a9fedef8b2
|
@ -53,7 +53,7 @@ public class CategoryModel {
|
|||
final Category category = categoryService.getBySlugOfNonNull(slug);
|
||||
CategoryDTO categoryDTO = categoryService.convertTo(category);
|
||||
|
||||
final Pageable pageable = PageRequest.of(page - 1, optionService.getPostPageSize(), Sort.by(DESC, "createTime"));
|
||||
final Pageable pageable = PageRequest.of(page - 1, optionService.getArchivesPageSize(), Sort.by(DESC, "createTime"));
|
||||
Page<Post> postPage = postCategoryService.pagePostBy(category.getId(), PostStatus.PUBLISHED, pageable);
|
||||
Page<PostListVO> posts = postService.convertToListVo(postPage);
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@ public class PostModel {
|
|||
}
|
||||
|
||||
public String archives(Integer page, Model model) {
|
||||
int pageSize = optionService.getPostPageSize();
|
||||
int pageSize = optionService.getArchivesPageSize();
|
||||
Pageable pageable = PageRequest
|
||||
.of(page >= 1 ? page - 1 : page, pageSize, Sort.by(Sort.Direction.DESC, "createTime"));
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ public class TagModel {
|
|||
final Tag tag = tagService.getBySlugOfNonNull(slug);
|
||||
TagDTO tagDTO = tagService.convertTo(tag);
|
||||
|
||||
final Pageable pageable = PageRequest.of(page - 1, optionService.getPostPageSize(), Sort.by(DESC, "createTime"));
|
||||
final Pageable pageable = PageRequest.of(page - 1, optionService.getArchivesPageSize(), Sort.by(DESC, "createTime"));
|
||||
Page<Post> postPage = postTagService.pagePostsBy(tag.getId(), PostStatus.PUBLISHED, pageable);
|
||||
Page<PostListVO> posts = postService.convertToListVo(postPage);
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@ package run.halo.app.model.properties;
|
|||
* Post properties.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 4/1/19
|
||||
* @author ryanwang
|
||||
* @date 2019-04-01
|
||||
*/
|
||||
public enum PostProperties implements PropertyEnum {
|
||||
|
||||
|
@ -28,6 +29,11 @@ public enum PostProperties implements PropertyEnum {
|
|||
*/
|
||||
INDEX_PAGE_SIZE("post_index_page_size", Integer.class, "10"),
|
||||
|
||||
/**
|
||||
* Archives page size.
|
||||
*/
|
||||
ARCHIVES_PAGE_SIZE("post_archives_page_size", Integer.class, "10"),
|
||||
|
||||
/**
|
||||
* Post index sort.
|
||||
*/
|
||||
|
|
|
@ -33,6 +33,8 @@ public interface OptionService extends CrudService<Option, Integer> {
|
|||
|
||||
int DEFAULT_POST_PAGE_SIZE = 10;
|
||||
|
||||
int DEFAULT_ARCHIVES_PAGE_SIZE = 10;
|
||||
|
||||
int DEFAULT_COMMENT_PAGE_SIZE = 10;
|
||||
|
||||
int DEFAULT_RSS_PAGE_SIZE = 20;
|
||||
|
@ -299,6 +301,13 @@ public interface OptionService extends CrudService<Option, Integer> {
|
|||
*/
|
||||
int getPostPageSize();
|
||||
|
||||
/**
|
||||
* Gets archives page size.
|
||||
*
|
||||
* @return page size
|
||||
*/
|
||||
int getArchivesPageSize();
|
||||
|
||||
/**
|
||||
* Gets comment page size.
|
||||
*
|
||||
|
|
|
@ -43,6 +43,7 @@ import java.util.stream.Collectors;
|
|||
* OptionService implementation class
|
||||
*
|
||||
* @author ryanwang
|
||||
* @author johnniang
|
||||
* @date 2019-03-14
|
||||
*/
|
||||
@Slf4j
|
||||
|
@ -365,13 +366,23 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
@Override
|
||||
public int getPostPageSize() {
|
||||
try {
|
||||
return getByPropertyOrDefault(PostProperties.INDEX_PAGE_SIZE, Integer.class, DEFAULT_COMMENT_PAGE_SIZE);
|
||||
return getByPropertyOrDefault(PostProperties.INDEX_PAGE_SIZE, Integer.class, DEFAULT_POST_PAGE_SIZE);
|
||||
} catch (NumberFormatException e) {
|
||||
log.error(PostProperties.INDEX_PAGE_SIZE.getValue() + " option is not a number format", e);
|
||||
return DEFAULT_POST_PAGE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getArchivesPageSize() {
|
||||
try {
|
||||
return getByPropertyOrDefault(PostProperties.ARCHIVES_PAGE_SIZE, Integer.class, DEFAULT_ARCHIVES_PAGE_SIZE);
|
||||
} catch (NumberFormatException e) {
|
||||
log.error(PostProperties.ARCHIVES_PAGE_SIZE.getValue() + " option is not a number format", e);
|
||||
return DEFAULT_POST_PAGE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCommentPageSize() {
|
||||
try {
|
||||
|
@ -385,7 +396,7 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
@Override
|
||||
public int getRssPageSize() {
|
||||
try {
|
||||
return getByPropertyOrDefault(PostProperties.RSS_PAGE_SIZE, Integer.class, DEFAULT_COMMENT_PAGE_SIZE);
|
||||
return getByPropertyOrDefault(PostProperties.RSS_PAGE_SIZE, Integer.class, DEFAULT_RSS_PAGE_SIZE);
|
||||
} catch (NumberFormatException e) {
|
||||
log.error(PostProperties.RSS_PAGE_SIZE.getValue() + " setting is not a number format", e);
|
||||
return DEFAULT_RSS_PAGE_SIZE;
|
||||
|
|
Loading…
Reference in New Issue