mirror of https://github.com/halo-dev/halo
Update anatole theme.
parent
b6e42e2d7e
commit
135586b4ec
|
@ -1,6 +1,5 @@
|
|||
package run.halo.app.model.entity;
|
||||
|
||||
import run.halo.app.model.enums.AttachmentType;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.lang.NonNull;
|
||||
import run.halo.app.model.entity.Post;
|
||||
import run.halo.app.model.enums.PostStatus;
|
||||
import run.halo.app.repository.base.BasePostRepository;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -26,8 +27,8 @@ public interface PostRepository extends BasePostRepository<Post>, JpaSpecificati
|
|||
Long countLike();
|
||||
|
||||
@NonNull
|
||||
Page<Post> findAllByStatusAndCreateTimeBefore(Date createTime, @NonNull Pageable pageable);
|
||||
Page<Post> findAllByStatusAndCreateTimeBefore(PostStatus status, Date createTime, @NonNull Pageable pageable);
|
||||
|
||||
@NonNull
|
||||
Page<Post> findAllByStatusAndCreateTimeAfter(Date createTime, @NonNull Pageable pageable);
|
||||
Page<Post> findAllByStatusAndCreateTimeAfter(PostStatus status, Date createTime, @NonNull Pageable pageable);
|
||||
}
|
||||
|
|
|
@ -196,6 +196,22 @@ public interface PostService extends CrudService<Post, Integer> {
|
|||
@NonNull
|
||||
Page<PostListVO> convertToListVo(@NonNull Page<Post> postPage);
|
||||
|
||||
/**
|
||||
* Get pre post by current post date.
|
||||
* @param date date
|
||||
* @return post
|
||||
*/
|
||||
@NonNull
|
||||
Post getPrePostOfNullable(@NonNull Date date);
|
||||
|
||||
/**
|
||||
* Get next post by current post date.
|
||||
* @param date date
|
||||
* @return post
|
||||
*/
|
||||
@NonNull
|
||||
Post getNextPostOfNullable(@NonNull Date date);
|
||||
|
||||
/**
|
||||
* Lists all posts by post status.
|
||||
*
|
||||
|
|
|
@ -363,6 +363,15 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
|||
return super.removeById(postId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Post getPrePostOfNullable(Date date) {
|
||||
return getPrePost(date).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Post getNextPostOfNullable(Date date) {
|
||||
return getNextPost(date).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<PostSimpleOutputDTO> convertToSimpleDto(@NonNull Page<Post> postPage) {
|
||||
|
@ -441,7 +450,7 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
|||
public Optional<Post> getPrePost(Date createTime) {
|
||||
Assert.notNull(createTime, "Create time must not be null");
|
||||
|
||||
Page<Post> prePostPage = postRepository.findAllByStatusAndCreateTimeAfter(createTime, PageRequest.of(0, 1));
|
||||
Page<Post> prePostPage = postRepository.findAllByStatusAndCreateTimeAfter(PostStatus.PUBLISHED, createTime, PageRequest.of(0, 1));
|
||||
|
||||
if (prePostPage.isEmpty()) {
|
||||
return Optional.empty();
|
||||
|
@ -454,13 +463,13 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
|
|||
public Optional<Post> getNextPost(Date createTime) {
|
||||
Assert.notNull(createTime, "Create time must not be null");
|
||||
|
||||
Page<Post> prePostPage = postRepository.findAllByStatusAndCreateTimeBefore(createTime, PageRequest.of(0, 1));
|
||||
Page<Post> nextPostPage = postRepository.findAllByStatusAndCreateTimeBefore(PostStatus.PUBLISHED, createTime, PageRequest.of(0, 1));
|
||||
|
||||
if (prePostPage.isEmpty()) {
|
||||
if (nextPostPage.isEmpty()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return Optional.of(prePostPage.getContent().get(0));
|
||||
return Optional.of(nextPostPage.getContent().get(nextPostPage.getContent().size()-1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
package run.halo.app.web.controller.content;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import run.halo.app.model.entity.Category;
|
||||
import run.halo.app.model.entity.Post;
|
||||
import run.halo.app.model.entity.Tag;
|
||||
import run.halo.app.model.enums.PostStatus;
|
||||
import run.halo.app.service.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Blog archive page controller
|
||||
*
|
||||
* @author : RYAN0UP
|
||||
* @date : 2019-03-17
|
||||
*/
|
||||
@Controller
|
||||
@RequestMapping(value = "/archives")
|
||||
public class ContentArchiveController {
|
||||
|
||||
private final PostService postService;
|
||||
|
||||
private final CommentService commentService;
|
||||
|
||||
private final ThemeService themeService;
|
||||
|
||||
private final PostCategoryService postCategoryService;
|
||||
|
||||
private final PostTagService postTagService;
|
||||
|
||||
public ContentArchiveController(PostService postService,
|
||||
CommentService commentService,
|
||||
ThemeService themeService,
|
||||
PostCategoryService postCategoryService,
|
||||
PostTagService postTagService) {
|
||||
this.postService = postService;
|
||||
this.commentService = commentService;
|
||||
this.themeService = themeService;
|
||||
this.postCategoryService = postCategoryService;
|
||||
this.postTagService = postTagService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render post page.
|
||||
*
|
||||
* @param url post slug url.
|
||||
* @param cp comment page number
|
||||
* @param request request
|
||||
* @param model model
|
||||
* @return template path: theme/{theme}/post.ftl
|
||||
*/
|
||||
@GetMapping(value = "{url}")
|
||||
public String post(@PathVariable String url,
|
||||
@RequestParam(value = "cp", defaultValue = "1") Integer cp,
|
||||
HttpServletRequest request,
|
||||
Model model) {
|
||||
final Post post = postService.getByUrl(url);
|
||||
if (null == post || !post.getStatus().equals(PostStatus.PUBLISHED)) {
|
||||
return "redirect:/404";
|
||||
}
|
||||
|
||||
final Date publishTime = post.getCreateTime();
|
||||
final Post nextPost = postService.getNextPostOfNullable(publishTime);
|
||||
final Post prePost = postService.getPrePostOfNullable(publishTime);
|
||||
|
||||
if (null != prePost) {
|
||||
model.addAttribute("prePost", prePost);
|
||||
}
|
||||
if (null != nextPost) {
|
||||
model.addAttribute("nextPost", nextPost);
|
||||
}
|
||||
|
||||
|
||||
List<Category> categories = postCategoryService.listCategoryBy(post.getId());
|
||||
List<Tag> tags = postTagService.listTagsBy(post.getId());
|
||||
|
||||
model.addAttribute("is_post", true);
|
||||
model.addAttribute("post",post);
|
||||
model.addAttribute("categories", categories);
|
||||
model.addAttribute("tags", tags);
|
||||
return themeService.render("post");
|
||||
}
|
||||
}
|
|
@ -81,12 +81,12 @@
|
|||
<ul class="clearfix">
|
||||
<#if nextPost??>
|
||||
<li class="pre pagbuttons">
|
||||
<a class="btn" role="navigation" href="${options.blog_url!}/archives/${nextPost.url}" title="${nextPost.title}">上一篇</a>
|
||||
<a class="btn" role="navigation" href="${options.blog_url!}/archives/${nextPost.url}" title="${nextPost.title}">下一篇</a>
|
||||
</li>
|
||||
</#if>
|
||||
<#if prePost??>
|
||||
<li class="next pagbuttons">
|
||||
<a class="btn" role="navigation" href="${options.blog_url!}/archives/${prePost.url}" title="${prePost.title}">下一篇</a>
|
||||
<a class="btn" role="navigation" href="${options.blog_url!}/archives/${prePost.url}" title="${prePost.title}">上一篇</a>
|
||||
</li>
|
||||
</#if>
|
||||
</ul>
|
||||
|
|
Loading…
Reference in New Issue