mirror of https://github.com/halo-dev/halo
Refactor CategoryTagDirective.java.
parent
c06df35be9
commit
43e362a58d
|
@ -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)) {
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
|
Loading…
Reference in New Issue