mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
docs: add initial recipes
This commit is contained in:
parent
964a0c9f75
commit
249f158f8a
9 changed files with 271 additions and 4 deletions
|
@ -141,13 +141,55 @@ module.exports = {
|
|||
}),
|
||||
mdsvex({
|
||||
remarkPlugins: [plugin, slug, carbonify],
|
||||
layout: path.join(__dirname, "src/layouts/ComponentLayout.svelte"),
|
||||
layout: {
|
||||
recipe: path.join(__dirname, "src/layouts/Recipe.svelte"),
|
||||
_: path.join(__dirname, "src/layouts/ComponentLayout.svelte"),
|
||||
},
|
||||
}),
|
||||
{
|
||||
markup({ content, filename }) {
|
||||
if (filename.endsWith(".svx") && filename.match(/pages\/(recipes)/)) {
|
||||
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.includes("pages/components") &&
|
||||
filename.endsWith(".svx")
|
||||
filename.endsWith(".svx") &&
|
||||
filename.match(/pages\/(components)/)
|
||||
) {
|
||||
const toc = [];
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue