Number manual sidebar navigation

This commit is contained in:
2026-06-17 13:37:53 +09:00
parent 4ab47e5719
commit aa6e5c51c1
2 changed files with 17 additions and 5 deletions
@@ -4,13 +4,14 @@ import '../style.css';
const { title = 'Decodal', active = '', playground = false } = Astro.props;
function renderNav(items) {
function renderNav(items, prefix = []) {
return `<ul class="nav-tree">${items
.map((item) => {
.map((item, index) => {
const number = [...prefix, index + 1];
const href = `/docs/${item.slug}/`;
const activeClass = active === item.slug ? ' class="active"' : '';
const children = item.children ? renderNav(item.children) : '';
return `<li><a${activeClass} href="${href}">${item.title}</a>${children}</li>`;
const children = item.children ? renderNav(item.children, number) : '';
return `<li><a${activeClass} href="${href}"><span class="nav-number">${number.join('.')}.</span>${item.title}</a>${children}</li>`;
})
.join('')}</ul>`;
}