mirror of https://github.com/halo-dev/halo
Refactor PostTagDirective.
parent
53eee6cb82
commit
34e13f35c0
|
@ -43,7 +43,11 @@ public class PostTagDirective implements TemplateDirectiveModel {
|
|||
String method = params.get(HaloConst.METHOD_KEY).toString();
|
||||
Integer categoryId = Integer.parseInt(params.get("categoryId").toString());
|
||||
Integer tagId = Integer.parseInt(params.get("tagId").toString());
|
||||
int top = Integer.parseInt(params.get("top").toString());
|
||||
switch (method) {
|
||||
case "latest":
|
||||
env.setVariable("posts", builder.build().wrap(postService.listLatest(top)));
|
||||
break;
|
||||
case "count":
|
||||
env.setVariable("count", builder.build().wrap(postService.count()));
|
||||
break;
|
||||
|
|
|
@ -112,7 +112,7 @@ public interface BasePostService<POST extends BasePost> extends CrudService<POST
|
|||
Optional<POST> getNextPost(@NonNull Date date);
|
||||
|
||||
/**
|
||||
* Lists latest posts.
|
||||
* Pages latest posts.
|
||||
*
|
||||
* @param top top number must not be less than 0
|
||||
* @return latest posts
|
||||
|
@ -120,6 +120,14 @@ public interface BasePostService<POST extends BasePost> extends CrudService<POST
|
|||
@NonNull
|
||||
Page<POST> pageLatest(int top);
|
||||
|
||||
/**
|
||||
* Lists latest posts.
|
||||
* @param top top number must not be less than 0
|
||||
* @return latest posts
|
||||
*/
|
||||
@NonNull
|
||||
List<POST> listLatest(int top);
|
||||
|
||||
/**
|
||||
* Gets a page of sheet.
|
||||
*
|
||||
|
|
|
@ -134,6 +134,20 @@ public abstract class BasePostServiceImpl<POST extends BasePost> extends Abstrac
|
|||
return listAll(latestPageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists latest posts.
|
||||
*
|
||||
* @param top top number must not be less than 0
|
||||
* @return latest posts
|
||||
*/
|
||||
@Override
|
||||
public List<POST> listLatest(int top) {
|
||||
Assert.isTrue(top > 0, "Top number must not be less than 0");
|
||||
|
||||
PageRequest latestPageable = PageRequest.of(0, top, Sort.by(DESC, "editTime"));
|
||||
return basePostRepository.findAllByStatus(PostStatus.PUBLISHED, latestPageable).getContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<POST> pageBy(Pageable pageable) {
|
||||
Assert.notNull(pageable, "Page info must not be null");
|
||||
|
|
|
@ -158,11 +158,11 @@ see https://gitee.com/yadong.zhang/DBlog/blob/master/blog-web/src/main/java/com/
|
|||
<div id="content">
|
||||
<h3>分类目录</h3>
|
||||
<ul id="myTable">
|
||||
<@commonTag method="categories">
|
||||
<@categoryTag method="list">
|
||||
<#if categories?? && categories?size gt 0>
|
||||
<#list categories as cate>
|
||||
<li>
|
||||
<div class="T1 pull-left"><a href="${options.blog_url}/categories/${cate.url!}" title="前端编程">${cate.name} | ${options.blog_title!}</a></div>
|
||||
<div class="T1 pull-left"><a href="${options.blog_url}/categories/${cate.slugName!}" title="前端编程">${cate.name} | ${options.blog_title!}</a></div>
|
||||
<div class="T2 pull-right">${cate.createTime?string('yyyy-MM-dd')}</div>
|
||||
<div class="T3 pull-right">daily</div>
|
||||
<div class="T4 pull-right">0.6</div>
|
||||
|
@ -170,17 +170,17 @@ see https://gitee.com/yadong.zhang/DBlog/blob/master/blog-web/src/main/java/com/
|
|||
<div class="myClear"></div>
|
||||
</#list>
|
||||
</#if>
|
||||
</@commonTag>
|
||||
</@categoryTag>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="content">
|
||||
<h3>标签目录</h3>
|
||||
<ul id="myTable">
|
||||
<@commonTag method="tags">
|
||||
<@tagTag method="list">
|
||||
<#if tags?? && tags?size gt 0>
|
||||
<#list tags as tag>
|
||||
<li>
|
||||
<div class="T1 pull-left"><a href="${options.blog_url}/tags/${tag.url!}" title="前端编程">${tag.name} | ${options.blog_title!}</a></div>
|
||||
<div class="T1 pull-left"><a href="${options.blog_url}/tags/${tag.slugName!}" title="前端编程">${tag.name} | ${options.blog_title!}</a></div>
|
||||
<div class="T2 pull-right">${tag.createTime?string('yyyy-MM-dd')}</div>
|
||||
<div class="T3 pull-right">daily</div>
|
||||
<div class="T4 pull-right">0.6</div>
|
||||
|
@ -188,7 +188,7 @@ see https://gitee.com/yadong.zhang/DBlog/blob/master/blog-web/src/main/java/com/
|
|||
<div class="myClear"></div>
|
||||
</#list>
|
||||
</#if>
|
||||
</@commonTag>
|
||||
</@tagTag>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="footer">
|
||||
|
|
Loading…
Reference in New Issue