From e948b4572b3ca3903fcc906fc166dcd50940f48e Mon Sep 17 00:00:00 2001 From: Hayden Chen Date: Thu, 13 Apr 2023 11:25:43 +0800 Subject: [PATCH] feat: :sparkles: display complete text when hovering over the TOC item. --- src/components/site/PostToc.tsx | 57 +++++++++++++++++---------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/src/components/site/PostToc.tsx b/src/components/site/PostToc.tsx index 8bcecd53..8a7d7d28 100644 --- a/src/components/site/PostToc.tsx +++ b/src/components/site/PostToc.tsx @@ -53,33 +53,36 @@ function renderItems(items: TocResult["map"], activeId: string, prefix = "") {
    {items?.children?.map((item, index) => (
  1. - {item.children.map((child: any, i) => ( - - {child.type === "paragraph" && child.children?.[0]?.url && ( - - {`${prefix}${index + 1}. ${ - child.children[0].children?.[0]?.value || - child.children[0].children?.[0]?.children?.[0]?.value - }`} - - )} - {child.type === "list" && - renderItems(child, activeId, `${index + 1}.`)} - - ))} + {item.children.map((child: any, i) => { + const content = + child.children[0].children?.[0]?.value || + child.children[0].children?.[0]?.children?.[0]?.value + return ( + + {child.type === "paragraph" && child.children?.[0]?.url && ( + + {`${prefix}${index + 1}. ${content}`} + + )} + {child.type === "list" && + renderItems(child, activeId, `${index + 1}.`)} + + ) + })}
  2. ))}