mirror of https://github.com/halo-dev/halo
Complete archives page controller.
parent
25ca8b96be
commit
d41c32da43
|
@ -33,6 +33,12 @@ public class PostTagDirective implements TemplateDirectiveModel {
|
|||
case "count":
|
||||
env.setVariable("count", builder.build().wrap(postService.count()));
|
||||
break;
|
||||
case "archiveYear":
|
||||
env.setVariable("archives",builder.build().wrap(postService.listYearArchives()));
|
||||
break;
|
||||
case "archiveMonth":
|
||||
env.setVariable("archives",builder.build().wrap(postService.listMonthArchives()));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.util.PageUtil;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.web.SortDefault;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -17,6 +18,7 @@ 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.model.vo.CommentVO;
|
||||
import run.halo.app.model.vo.PostListVO;
|
||||
import run.halo.app.service.*;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -60,6 +62,38 @@ public class ContentArchiveController {
|
|||
this.optionService = optionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render post archives page.
|
||||
*
|
||||
* @param model model
|
||||
* @return template path : theme/{theme}/archives.ftl
|
||||
*/
|
||||
@GetMapping
|
||||
public String archives(Model model) {
|
||||
return this.archives(model, 1, Sort.by(DESC, "createTime"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Render post archives page.
|
||||
*
|
||||
* @param model model
|
||||
* @return template path : theme/{theme}/archives.ftl
|
||||
*/
|
||||
@GetMapping(value = "page/{page}")
|
||||
public String archives(Model model,
|
||||
@PathVariable(value = "page") Integer page,
|
||||
@SortDefault(sort = "createTime", direction = DESC) Sort sort) {
|
||||
Pageable pageable = PageRequest.of(page - 1, optionService.getPostPageSize(), sort);
|
||||
|
||||
Page<PostListVO> posts = postService.pageListVoBy(PostStatus.PUBLISHED, pageable);
|
||||
int[] pageRainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
||||
|
||||
model.addAttribute("is_archives", true);
|
||||
model.addAttribute("pageRainbow", pageRainbow);
|
||||
model.addAttribute("posts", posts);
|
||||
return themeService.render("archives");
|
||||
}
|
||||
|
||||
/**
|
||||
* Render post page.
|
||||
*
|
||||
|
|
|
@ -74,8 +74,10 @@ public class ContentIndexController {
|
|||
log.debug("Requested index page, sort info: [{}]", sort);
|
||||
int pageSize = optionService.getPostPageSize();
|
||||
Pageable pageable = PageRequest.of(page - 1, pageSize, sort);
|
||||
|
||||
Page<PostListVO> posts = postService.pageListVoBy(PostStatus.PUBLISHED, pageable);
|
||||
int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
||||
|
||||
model.addAttribute("is_index", true);
|
||||
model.addAttribute("posts", posts);
|
||||
model.addAttribute("rainbow", rainbow);
|
||||
|
|
|
@ -7,23 +7,23 @@
|
|||
<div class="content">
|
||||
<div class="archive animated fadeInDown">
|
||||
<ul class="list-with-title">
|
||||
<@articleTag method="archivesLess">
|
||||
<#list archivesLess as archive>
|
||||
<div class="listing-title">${archive.year}</div>
|
||||
<@postTag method="archiveYear">
|
||||
<#list archives as archive>
|
||||
<div class="listing-title">${archive.year?c}</div>
|
||||
<ul class="listing">
|
||||
<#list archive.posts?sort_by("createTime")?reverse as post>
|
||||
<div class="listing-item">
|
||||
<div class="listing-post">
|
||||
<a href="${options.blog_url!}/archives/${post.url!}" title="${post.title!}">${post.title!}</a>
|
||||
<div class="post-time">
|
||||
<span class="date">${post.postDate?string("yyyy-MM-dd")}</span>
|
||||
<span class="date">${post.createTime?string("yyyy-MM-dd")}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</#list>
|
||||
</ul>
|
||||
</#list>
|
||||
</@articleTag>
|
||||
</@postTag>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -80,14 +80,14 @@
|
|||
<div class="pagination">
|
||||
<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>
|
||||
</li>
|
||||
<li class="next pagbuttons">
|
||||
<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>
|
||||
</li>
|
||||
<li class="pre pagbuttons">
|
||||
<a class="btn" role="navigation" href="${options.blog_url!}/archives/${prePost.url}" title="${prePost.title}">上一篇</a>
|
||||
</li>
|
||||
</#if>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue