Skip to content

Commit

Permalink
Fix sidebar bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptobench committed Oct 26, 2023
1 parent c4f5ba3 commit c302a62
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/components/DefaultValue.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { slugifyWithCounter } from '@sindresorhus/slugify'
const slugify = slugifyWithCounter()

function DefaultValue({ title, description, defaultValue }) {
function DefaultValue({ title, description, defaultValue, id }) {
return (
<div className="border border-lightbluedarker dark:border-none bg-white dark:bg-darkcontent p-6 rounded-lg mb-6 shadow-sm transition-shadow duration-200">
<h3
id={slugify(title)}
id={id}
className="font-semibold text-xl mb-4 text-primary dark:text-darkprimary">{title}</h3>
<p className="text-gray-700 dark:text-white dark:text-opacity-50 mb-4">{description}</p>
<div className="mt-2">
Expand Down
16 changes: 4 additions & 12 deletions src/pages/_app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -53,9 +47,7 @@ function collectHeadings(
}
}

sections.push(
...collectHeadings(node.children ?? [], slugify, lastNodes, idMap)
)
sections.push(...collectHeadings(node.children ?? [], slugify, lastNodes, idMap))
}
return sections
}
Expand Down

0 comments on commit c302a62

Please sign in to comment.