From c302a62f95aea3b76f32ffeb34fae9972bb3e8cc Mon Sep 17 00:00:00 2001 From: Phillip Jensen Date: Thu, 26 Oct 2023 14:27:26 +0200 Subject: [PATCH] Fix sidebar bug --- src/components/DefaultValue.jsx | 4 ++-- src/pages/_app.jsx | 16 ++++------------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/components/DefaultValue.jsx b/src/components/DefaultValue.jsx index 4ca35fa7f..cc682a3e3 100644 --- a/src/components/DefaultValue.jsx +++ b/src/components/DefaultValue.jsx @@ -1,11 +1,11 @@ import { slugifyWithCounter } from '@sindresorhus/slugify' const slugify = slugifyWithCounter() -function DefaultValue({ title, description, defaultValue }) { +function DefaultValue({ title, description, defaultValue, id }) { return (

{title}

{description}

diff --git a/src/pages/_app.jsx b/src/pages/_app.jsx index feee72cd6..d2f76740a 100644 --- a/src/pages/_app.jsx +++ b/src/pages/_app.jsx @@ -29,18 +29,12 @@ function collectHeadings( let sections = [] for (let node of nodes) { - if ( - node.name === 'Heading' || - (node.name === 'Defaultvalue' && node.attributes && node.attributes.title) - ) { + if (node.name === 'Heading' || (node.name === 'Defaultvalue' && node.attributes && node.attributes.title)) { let level = node.name === 'Defaultvalue' ? 3 : node.attributes.level - let title = - node.name === 'Defaultvalue' ? node.attributes.title : getNodeText(node) + let title = node.name === 'Defaultvalue' ? node.attributes.title : getNodeText(node) if (title) { - if (node.name === 'Defaultvalue') { - console.log(node) - } + let id = node.attributes?.id ?? slugify(title) let newNode = { ...node.attributes, id, title, children: [], level } if (lastNodes[level - 2]) { @@ -53,9 +47,7 @@ function collectHeadings( } } - sections.push( - ...collectHeadings(node.children ?? [], slugify, lastNodes, idMap) - ) + sections.push(...collectHeadings(node.children ?? [], slugify, lastNodes, idMap)) } return sections }