Merge pull request #21 from PR0M3TH3AN/codex/fix-sidebar-open-close-functionality

Improve sidebar behavior and navigation titles
This commit is contained in:
thePR0M3TH3AN
2025-07-10 13:17:19 -04:00
committed by GitHub
2 changed files with 28 additions and 7 deletions

View File

@@ -59,9 +59,10 @@ body {
background: var(--sidebar-bg);
padding: 1rem;
}
.sidebar ul { list-style: none; padding: 0; }
.sidebar ul ul { padding-left: 1rem; }
.sidebar a { text-decoration: none; color: var(--text-color); }
.sidebar ul { list-style: none; padding: 0; margin: 0; }
.sidebar li { margin: 0.25rem 0; }
.sidebar a { text-decoration: none; color: var(--text-color); display: block; padding: 0.25rem 0; }
.sidebar ul ul { padding-left: 1rem; margin-left: 0.5rem; border-left: 2px solid #ccc; }
main {
flex: 1;
padding: 1rem;
@@ -74,7 +75,7 @@ main {
top: 0;
height: 100%;
overflow-y: auto;
transition: left 0.3s ease;
transition: none;
z-index: 1000;
}
body.sidebar-open .sidebar { left: 0; }

View File

@@ -26,10 +26,29 @@ function buildNav(pages) {
const tree = {};
for (const page of pages) {
const rel = page.file.replace(/\\/g, '/');
if (rel === 'index.md') {
if (!tree.children) tree.children = [];
tree.children.push({
name: 'index.md',
children: [],
page: page.data,
path: `/${rel.replace(/\.md$/, '.html')}`,
order: page.data.order || 0
});
continue;
}
const parts = rel.split('/');
let node = tree;
for (let i = 0; i < parts.length; i++) {
const part = parts[i];
const isLast = i === parts.length - 1;
const isIndex = isLast && part === 'index.md';
if (isIndex) {
node.page = page.data;
node.path = `/${rel.replace(/\.md$/, '.html')}`;
node.order = page.data.order || 0;
break;
}
if (!node.children) node.children = [];
let child = node.children.find(c => c.name === part);
if (!child) {
@@ -37,12 +56,12 @@ function buildNav(pages) {
node.children.push(child);
}
node = child;
if (i === parts.length - 1) {
if (isLast) {
node.page = page.data;
node.path = `/${rel.replace(/\.md$/, '.html')}`;
node.order = page.data.order || 0;
}
}
node.order = page.data.order || 0;
}
function sort(node) {
@@ -92,8 +111,9 @@ async function generate({ contentDir = 'content', outputDir = '_site', configPat
const mdObj = await runHook('onParseMarkdown', { file: rel, content: raw });
if (mdObj && mdObj.content) raw = mdObj.content;
const parsed = matter(raw);
const title = parsed.data.title || path.basename(rel, '.md');
const tokens = lexer(parsed.content || '');
const firstHeading = tokens.find(t => t.type === 'heading');
const title = parsed.data.title || (firstHeading ? firstHeading.text : path.basename(rel, '.md'));
const headings = tokens.filter(t => t.type === 'heading').map(t => t.text).join(' ');
pages.push({ file: rel, data: { ...parsed.data, title } });
searchDocs.push({ id: rel.replace(/\.md$/, '.html'), url: '/' + rel.replace(/\.md$/, '.html'), title, headings });