From f1caf83103ace0d13320dc90b71dcc93a5faddaa Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Sat, 6 Aug 2022 13:37:49 -0700 Subject: [PATCH] docs: correctly render table of contents [ci skip] --- docs/svelte.config.js | 88 +++++++++++-------------------------------- 1 file changed, 23 insertions(+), 65 deletions(-) diff --git a/docs/svelte.config.js b/docs/svelte.config.js index ac82385b..277d8ced 100644 --- a/docs/svelte.config.js +++ b/docs/svelte.config.js @@ -163,71 +163,30 @@ module.exports = { { markup({ content, filename }) { if (/node_modules/.test(filename)) return null; - if (filename.endsWith(".svx")) { - const toc = []; + if (!filename.match(/pages\/(components)/)) return null; - walk(parse(content), { - enter(node) { - if (node.type === "Element") { - if (node.name === "h2") { - const id = node.attributes.find( - (attribute) => attribute.name === "id" - ); - toc.push({ - id: id.value[0].raw, - text: node.children[0].raw, - }); - } + const toc = []; + + walk(parse(content), { + enter(node) { + if (node.type === "Element") { + if (node.name === "h3") { + const id = node.attributes.find( + (attribute) => attribute.name === "id" + ); + toc.push({ + id: id.value[0].raw, + text: node.children[0].raw, + }); } - }, - }); + } + }, + }); - return { - code: content.replace( - "", - `
- -
- ` - ), - }; - } - - if ( - filename.endsWith(".svx") && - filename.match(/pages\/(components)/) - ) { - const toc = []; - - walk(parse(content), { - enter(node) { - if (node.type === "Element") { - if (node.name === "h3") { - const id = node.attributes.find( - (attribute) => attribute.name === "id" - ); - toc.push({ - id: id.value[0].raw, - text: node.children[0].raw, - }); - } - } - }, - }); - - return { - code: content.replace( - "", - `
+ return { + code: content.replace( + "", + `
  • Usage @@ -268,9 +227,8 @@ module.exports = {
` - ), - }; - } + ), + }; }, }, ],