Number manual sidebar navigation
This commit is contained in:
@@ -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>`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user