feat: use nested folders

This commit is contained in:
Araozu 2024-11-21 20:43:57 -05:00
parent 86ef6f8c09
commit 67ff5203a6
2 changed files with 17 additions and 6 deletions

View File

@ -7,6 +7,10 @@ const basePath: string = Astro.props.basePath;
const entryPath = is_index_file(entry.path)? "": entry.path; const entryPath = is_index_file(entry.path)? "": entry.path;
const entryUrl = basePath + entryPath + (entryPath.endsWith("/")? "" : "/"); const entryUrl = basePath + entryPath + (entryPath.endsWith("/")? "" : "/");
console.table({
basePath,
entryPath,
})
function is_index_file(p) { function is_index_file(p) {
return p.endsWith("index") return p.endsWith("index")
@ -38,7 +42,7 @@ function is_index_file(p) {
{entry.children!.map((nextEntry) => ( {entry.children!.map((nextEntry) => (
<Astro.self <Astro.self
entry={nextEntry} entry={nextEntry}
basePath={`${basePath}${entry.path}/`} basePath={`${basePath}${entry.path}`}
/> />
))} ))}
</ul> </ul>

View File

@ -69,8 +69,6 @@ for (const post of posts_2) {
} }
} }
console.log(JSON.stringify(second_level, null, 4));
// transform to the layout that the sidebar expects // transform to the layout that the sidebar expects
const entries = []; const entries = [];
@ -80,13 +78,22 @@ for (const levels_key in second_level) {
const posts = second_level[levels_key]; const posts = second_level[levels_key];
entries.push(...posts) entries.push(...posts)
} }
else {
const posts = second_level[levels_key];
const parentEntry = {
path: "",
title: levels_key,
children: posts,
};
entries.push(parentEntry);
}
} }
const index_page = entries.find(post => post.relative_file === "/index.md" || post.relative_file === "/index.mdx");
const index_page = posts_2.find(post => post.relative_file === "/index.md" || post.relative_file === "/index.mdx");
const basePath = index_page.url; const basePath = index_page.url;
const pagesIndex = posts_2; console.log(JSON.stringify(index_page, null, 4));
console.log(basePath);
--- ---
<BaseLayout title={frontmatter.title}> <BaseLayout title={frontmatter.title}>