From 16503a389d96c925d12e1a7f8f24a67ca60d4d48 Mon Sep 17 00:00:00 2001 From: Blinko Date: Wed, 27 Nov 2024 16:14:23 +0800 Subject: [PATCH] fix: article view tag issue #186 --- src/components/BlinkoCard/blogContent.tsx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/components/BlinkoCard/blogContent.tsx b/src/components/BlinkoCard/blogContent.tsx index a6372ca..91741f2 100644 --- a/src/components/BlinkoCard/blogContent.tsx +++ b/src/components/BlinkoCard/blogContent.tsx @@ -1,5 +1,6 @@ import { Image } from '@nextui-org/react'; import { Note } from '@/server/types'; +import { helper } from '@/lib/helper'; interface BlogContentProps { blinkoItem: Note & { @@ -30,11 +31,20 @@ export const BlogContent = ({ blinkoItem, isExpanded }: BlogContentProps) => { { !!blinkoItem?.tags?.length && blinkoItem?.tags?.length > 0 && (
- {blinkoItem?.tags?.map((tag) => ( -
- #{tag.tag.name} -
- ))} + {(() => { + const tagTree = helper.buildHashTagTreeFromDb(blinkoItem.tags.map(t => t.tag)); + const tagPaths = tagTree.flatMap(node => helper.generateTagPaths(node)); + const uniquePaths = tagPaths.filter(path => { + return !tagPaths.some(otherPath => + otherPath !== path && otherPath.startsWith(path + '/') + ); + }); + return uniquePaths.map((path) => ( +
+ #{path} +
+ )); + })()}
)}