mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
docs: correctly render table of contents [ci skip]
This commit is contained in:
parent
e3978e883b
commit
f1caf83103
1 changed files with 23 additions and 65 deletions
|
@ -163,49 +163,8 @@ module.exports = {
|
||||||
{
|
{
|
||||||
markup({ content, filename }) {
|
markup({ content, filename }) {
|
||||||
if (/node_modules/.test(filename)) return null;
|
if (/node_modules/.test(filename)) return null;
|
||||||
if (filename.endsWith(".svx")) {
|
if (!filename.match(/pages\/(components)/)) return null;
|
||||||
const toc = [];
|
|
||||||
|
|
||||||
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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
|
||||||
code: content.replace(
|
|
||||||
"</Layout_MDSVEX_DEFAULT>",
|
|
||||||
`<div slot="aside">
|
|
||||||
<ul class="bx--list--unordered">
|
|
||||||
${toc
|
|
||||||
.map((item) => {
|
|
||||||
return `
|
|
||||||
<li class="bx--list__item">
|
|
||||||
<a class="bx--link" href="\#${item.id}">${item.text}</a>
|
|
||||||
</li>`;
|
|
||||||
})
|
|
||||||
.join("")}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</Layout_MDSVEX_DEFAULT>`
|
|
||||||
),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
filename.endsWith(".svx") &&
|
|
||||||
filename.match(/pages\/(components)/)
|
|
||||||
) {
|
|
||||||
const toc = [];
|
const toc = [];
|
||||||
|
|
||||||
walk(parse(content), {
|
walk(parse(content), {
|
||||||
|
@ -270,7 +229,6 @@ module.exports = {
|
||||||
</Layout_MDSVEX_DEFAULT>`
|
</Layout_MDSVEX_DEFAULT>`
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue