Refactor CategoryTagDirective.java.

pull/146/head
ruibaby 2019-04-30 23:11:26 +08:00
parent c06df35be9
commit 43e362a58d
3 changed files with 10 additions and 2 deletions

View File

@ -63,7 +63,9 @@ public class ContentSheetController {
Model model) {
Sheet sheet = sheetService.getBy(PostStatus.PUBLISHED, url);
// sheet and post all can use
model.addAttribute("sheet", sheetService.convertToDetail(sheet));
model.addAttribute("post",sheetService.convertToDetail(sheet));
if (StrUtil.isNotEmpty(sheet.getTemplate())) {
if (themeService.templateExists(sheet.getTemplate() + HaloConst.SUFFIX_FTL)) {

View File

@ -2,6 +2,7 @@ package run.halo.app.model.freemarker.tag;
import freemarker.core.Environment;
import freemarker.template.*;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;
import run.halo.app.model.support.HaloConst;
import run.halo.app.service.CategoryService;
@ -10,6 +11,8 @@ import run.halo.app.service.PostCategoryService;
import java.io.IOException;
import java.util.Map;
import static org.springframework.data.domain.Sort.Direction.DESC;
/**
* Freemarker custom tag of category.
*
@ -37,7 +40,7 @@ public class CategoryTagDirective implements TemplateDirectiveModel {
String method = params.get(HaloConst.METHOD_KEY).toString();
switch (method) {
case "list":
env.setVariable("categories", builder.build().wrap(categoryService.listAll()));
env.setVariable("categories", builder.build().wrap(postCategoryService.listCategoryWithPostCountDto(Sort.by(DESC, "createTime"))));
break;
case "listByPostId":
Integer postId = Integer.parseInt(params.get("postId").toString());

View File

@ -2,6 +2,7 @@ package run.halo.app.model.freemarker.tag;
import freemarker.core.Environment;
import freemarker.template.*;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;
import run.halo.app.model.support.HaloConst;
import run.halo.app.service.PostTagService;
@ -10,6 +11,8 @@ import run.halo.app.service.TagService;
import java.io.IOException;
import java.util.Map;
import static org.springframework.data.domain.Sort.Direction.DESC;
/**
* Freemarker custom tag of tag.
*
@ -37,7 +40,7 @@ public class TagTagDirective implements TemplateDirectiveModel {
String method = params.get(HaloConst.METHOD_KEY).toString();
switch (method) {
case "list":
env.setVariable("tags", builder.build().wrap(tagService.listAll()));
env.setVariable("tags", builder.build().wrap(postTagService.listTagWithCountDtos(Sort.by(DESC, "createTime"))));
break;
case "listByPostId":
Integer postId = Integer.parseInt(params.get("postId").toString());