From d4cfc3ae7f09ffd252b9fda30ea5e3c74bda027d Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Tue, 17 Mar 2020 23:56:01 +0800 Subject: [PATCH] feat: #598 (#689) --- .../core/freemarker/tag/CategoryTagDirective.java | 3 +++ .../app/service/impl/CategoryServiceImpl.java | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/run/halo/app/core/freemarker/tag/CategoryTagDirective.java b/src/main/java/run/halo/app/core/freemarker/tag/CategoryTagDirective.java index 21d924e6b..08cfdec66 100644 --- a/src/main/java/run/halo/app/core/freemarker/tag/CategoryTagDirective.java +++ b/src/main/java/run/halo/app/core/freemarker/tag/CategoryTagDirective.java @@ -46,6 +46,9 @@ public class CategoryTagDirective implements TemplateDirectiveModel { case "list": env.setVariable("categories", builder.build().wrap(postCategoryService.listCategoryWithPostCountDto(Sort.by(DESC, "createTime")))); break; + case "tree": + env.setVariable("categories", builder.build().wrap(categoryService.listAsTree(Sort.by(DESC, "createTime")))); + break; case "listByPostId": Integer postId = Integer.parseInt(params.get("postId").toString()); List categories = postCategoryService.listCategoriesBy(postId); diff --git a/src/main/java/run/halo/app/service/impl/CategoryServiceImpl.java b/src/main/java/run/halo/app/service/impl/CategoryServiceImpl.java index 9438747c1..089e4f1fc 100644 --- a/src/main/java/run/halo/app/service/impl/CategoryServiceImpl.java +++ b/src/main/java/run/halo/app/service/impl/CategoryServiceImpl.java @@ -123,6 +123,21 @@ public class CategoryServiceImpl extends AbstractCrudService if (parentCategory.getChildren() == null) { parentCategory.setChildren(new LinkedList<>()); } + + StringBuilder fullPath = new StringBuilder(); + + if (optionService.isEnabledAbsolutePath()) { + fullPath.append(optionService.getBlogBaseUrl()); + } + + fullPath.append("/") + .append(optionService.getCategoriesPrefix()) + .append("/") + .append(child.getSlug()) + .append(optionService.getPathSuffix()); + + child.setFullPath(fullPath.toString()); + // Add child parentCategory.getChildren().add(child); });