From 4f957e7e92355696b7b5d2841dc66932b181a40d Mon Sep 17 00:00:00 2001 From: kazoottt Date: Sun, 4 Feb 2024 16:56:45 +0800 Subject: [PATCH] feat: highlight the selected tag --- themes/heo/components/TagGroups.js | 46 ++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/themes/heo/components/TagGroups.js b/themes/heo/components/TagGroups.js index 7c8ae0e6..a74a43b3 100644 --- a/themes/heo/components/TagGroups.js +++ b/themes/heo/components/TagGroups.js @@ -1,4 +1,5 @@ import Link from 'next/link' +import { useRouter } from 'next/router' /** * 标签组 @@ -9,22 +10,37 @@ import Link from 'next/link' */ const TagGroups = ({ tags, className }) => { if (!tags) return <> - return ( -
- { - tags.map((tag, index) => { - return -
-
{tag.name}
{tag.count ? {tag.count} : <>} -
- - }) - } -
+ const router = useRouter() + const { tag: currentTag } = router.query + + return ( +
+ {tags.map((tag, index) => { + const selected = currentTag === tag.name + return ( + +
+
{tag.name}
+ {tag.count ? ( + {tag.count} + ) : ( + <> + )} +
+ + ) + })} +
) }