From 86ef6f8c0928a21e14829aa01d2337bf8b32631c Mon Sep 17 00:00:00 2001 From: Araozu Date: Thu, 21 Nov 2024 20:31:09 -0500 Subject: [PATCH] feat: begin to cascade folders --- src/layouts/NewDocsLayout.astro | 36 +++++- src/pages/en/latest/learn/basics.mdx | 13 -- src/pages/en/latest/learn/basics/comments.mdx | 62 +++++++++ .../en/latest/learn/basics/datatypes.mdx | 87 +++++++++++++ .../en/latest/learn/basics/hello-world.mdx | 46 +++++++ .../en/latest/learn/basics/operators.mdx | 121 ++++++++++++++++++ .../en/latest/learn/basics/variables.mdx | 98 ++++++++++++++ 7 files changed, 449 insertions(+), 14 deletions(-) delete mode 100644 src/pages/en/latest/learn/basics.mdx create mode 100644 src/pages/en/latest/learn/basics/comments.mdx create mode 100644 src/pages/en/latest/learn/basics/datatypes.mdx create mode 100644 src/pages/en/latest/learn/basics/hello-world.mdx create mode 100644 src/pages/en/latest/learn/basics/operators.mdx create mode 100644 src/pages/en/latest/learn/basics/variables.mdx diff --git a/src/layouts/NewDocsLayout.astro b/src/layouts/NewDocsLayout.astro index 27ae6b4..8fb7754 100644 --- a/src/layouts/NewDocsLayout.astro +++ b/src/layouts/NewDocsLayout.astro @@ -49,6 +49,40 @@ const posts_2 = posts })) .sort((p1, p2) => p1.frontmatter.order > p2.frontmatter.order? 1 : -1); +// build a hierarchy of the files +const second_level: Record> = { + "_": [], +}; +for (const post of posts_2) { + const fragments = post.path.split("/"); + if (fragments.length === 3) { + const folder_name = fragments[1]; + // create if not exists + if (second_level[folder_name] === undefined) { + second_level[folder_name] = []; + } + second_level[folder_name].push(post); + } + else if (fragments.length === 2) { + // add to root folder + second_level["_"].push(post); + } +} + +console.log(JSON.stringify(second_level, null, 4)); + +// transform to the layout that the sidebar expects + +const entries = []; +for (const levels_key in second_level) { + if (levels_key === "_") { + // top level + const posts = second_level[levels_key]; + entries.push(...posts) + } +} + + const index_page = posts_2.find(post => post.relative_file === "/index.md" || post.relative_file === "/index.mdx"); const basePath = index_page.url; @@ -68,7 +102,7 @@ const pagesIndex = posts_2; >