diff --git a/src/components/utils.ts b/src/components/utils.ts
index f715072..6943db8 100644
--- a/src/components/utils.ts
+++ b/src/components/utils.ts
@@ -17,7 +17,7 @@ export function leftTrimDedent(input: string): Array {
// Get indentation level of the first line
let indentationLevel = 0;
for (const char of lines[0]!) {
- if (char === " ") {
+ if (char === " " || char === "\n") {
indentationLevel += 1;
} else {
break;
@@ -33,7 +33,7 @@ export function leftTrimDedent(input: string): Array {
output.push(trimWhitespace(line, indentationLevel));
}
- if (output.length > 1 && output[output.length - 1] === "") {
+ if (output.length > 1 && output[output.length - 1] === "") {
output = output.slice(0, -1);
}
diff --git a/src/layouts/DocsLayout.astro b/src/layouts/DocsLayout.astro
deleted file mode 100644
index 47096c0..0000000
--- a/src/layouts/DocsLayout.astro
+++ /dev/null
@@ -1,19 +0,0 @@
----
-import PagesLayout from "./PagesLayout.astro";
-
-const { frontmatter, headings } = Astro.props;
-
-const posts = await Astro.glob("@/pages/learn/**/*.{md,mdx}");
-const indexSubpath = `/learn/index.mdx`;
----
-
-
-
-
diff --git a/src/layouts/NewDocsLayout.astro b/src/layouts/NewDocsLayout.astro
index 07e7193..cb2942b 100644
--- a/src/layouts/NewDocsLayout.astro
+++ b/src/layouts/NewDocsLayout.astro
@@ -42,16 +42,14 @@ const {
const base_len = base_url.length;
const posts_2 = posts
- .map(post => {
- return {
+ .map(post => ({
...post,
title: post.frontmatter.title,
// this should be a path relative to the base url.
// e.g if base_url is `/spec`, then this instead of
// being `/spec/ast/tokens` would be `/ast/tokens`
path: post.url.substring(base_len),
- }
- })
+ }))
.sort((p1, p2) => p1.frontmatter.order > p2.frontmatter.order? 1 : -1);
// build a hierarchy of the files
@@ -75,39 +73,42 @@ for (const post of posts_2) {
}
}
-// transform to the layout that the sidebar expects
+// build a folder hierarchy (only 2 levels)
const entries: Array = [];
-for (const levels_key in second_level) {
+const levels_keys = Object.keys(second_level).toSorted();
+
+// The key `_` contains the top level links. Always insert those
+const top_level_posts = second_level["_"]!;
+// sort
+const sorted_posts = top_level_posts.toSorted(sort_posts);
+entries.push(...sorted_posts);
+
+for (const levels_key of levels_keys) {
if (levels_key === "_") {
- // top level
- const posts = second_level[levels_key]!;
- entries.push(...posts)
+ // top level, already inserted
+ continue;
}
else {
const posts = second_level[levels_key]!;
+ const sorted_posts = posts.toSorted(sort_posts);
const parentEntry = {
path: "",
title: levels_key,
- children: posts,
+ children: sorted_posts,
url: "",
};
entries.push(parentEntry);
}
}
-/*
-const index_page = posts_2.find(post => post.relative_file === "/index.md" || post.relative_file === "/index.mdx");
-if (index_page === undefined) {
- console.error("\n\nBuilding without an index page");
- console.error(import.meta.dirname);
- console.error("base_path", base_dir);
- console.error("entries len", entries.length);
- entries.forEach(e => console.log("\t"+e.url));
- throw new Error("No entries");
+function sort_posts(p1, p2) {
+ if (!!p1.frontmatter.order && !!p2.frontmatter.order) {
+ return p1.frontmatter.order > p2.frontmatter.order ? 1 : -1;
+ } else {
+ return p1.title > p2.title? 1 : -1;
+ }
}
-const basePath = index_page?.url ?? "/";
-*/
---
diff --git a/src/layouts/PagesLayout.astro b/src/layouts/PagesLayout.astro
deleted file mode 100644
index 8768ffc..0000000
--- a/src/layouts/PagesLayout.astro
+++ /dev/null
@@ -1,126 +0,0 @@
----
-import Navbar from "../components/Navbar.astro";
-import BaseLayout from "./BaseLayout.astro";
-import TOC from "../components/TOC.astro";
-import Sidebar from "../components/Sidebar.astro";
-
-const {
- frontmatter,
- headings,
- posts: _posts,
- indexSubpath,
- basePath,
- disable_container,
-} = Astro.props;
-const posts: Record[] = _posts;
-
-const indexPage = posts.find((post) => post.file.endsWith(indexSubpath));
-
-if (indexPage === undefined) {
- throw new Error(`No index page found at ${indexSubpath}`);
-}
-
-export type PageEntry = {
- path: string;
- title?: string;
- children?: Array;
-};
-
-const pagesIndex: Array | undefined =
- indexPage.frontmatter.pagesLayout;
-
-if (pagesIndex === undefined) {
- console.error(indexPage.frontmatter);
- throw new Error(`No pagesLayout frontmatter found in ${indexSubpath}`);
-}
-
-function validateEntry(entry: PageEntry, basePath: string) {
- if (!entry.children) {
- // Attempt to get the page title from frontmatter
- const pageData = posts.find(
- (post) =>
- post.file.endsWith(entry.path + ".md") ||
- post.file.endsWith(entry.path + ".mdx"),
- );
-
- if (pageData === undefined) {
- console.error(entry);
- console.error(entry.path + ".md");
- throw new Error(`No page found at ${entry.path}`);
- }
-
- // set the title
- entry.title = pageData.frontmatter.title ?? "Title not set";
-
- return;
- }
-
- // Recursively search for children
- if (!entry.title) {
- console.log(entry);
- throw new Error(
- `No title found in ${basePath + entry.path}, which is a folder and requires it.`,
- );
- }
-
- const folderName = entry.title;
-
- entry.children.forEach((child) =>
- validateEntry(child, basePath + "/" + folderName),
- );
-}
-
-for (const entry of pagesIndex) {
- validateEntry(entry, basePath);
-}
----
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/layouts/SpecLayout.astro b/src/layouts/SpecLayout.astro
deleted file mode 100644
index d23e49f..0000000
--- a/src/layouts/SpecLayout.astro
+++ /dev/null
@@ -1,18 +0,0 @@
----
-import PagesLayout from "./PagesLayout.astro";
-
-const { frontmatter, headings } = Astro.props;
-
-const posts = await Astro.glob("../pages/spec/**/*.{md,mdx}");
-const indexSubpath = `/spec/index.mdx`;
----
-
-
-
-
diff --git a/src/pages/en/latest/learn/basics/comments.mdx b/src/pages/en/latest/learn/01_basics/comments.mdx
similarity index 100%
rename from src/pages/en/latest/learn/basics/comments.mdx
rename to src/pages/en/latest/learn/01_basics/comments.mdx
diff --git a/src/pages/en/latest/learn/basics/datatypes.mdx b/src/pages/en/latest/learn/01_basics/datatypes.mdx
similarity index 100%
rename from src/pages/en/latest/learn/basics/datatypes.mdx
rename to src/pages/en/latest/learn/01_basics/datatypes.mdx
diff --git a/src/pages/en/latest/learn/basics/hello-world.mdx b/src/pages/en/latest/learn/01_basics/hello-world.mdx
similarity index 100%
rename from src/pages/en/latest/learn/basics/hello-world.mdx
rename to src/pages/en/latest/learn/01_basics/hello-world.mdx
diff --git a/src/pages/en/latest/learn/basics/operators.mdx b/src/pages/en/latest/learn/01_basics/operators.mdx
similarity index 100%
rename from src/pages/en/latest/learn/basics/operators.mdx
rename to src/pages/en/latest/learn/01_basics/operators.mdx
diff --git a/src/pages/en/latest/learn/basics/variables.mdx b/src/pages/en/latest/learn/01_basics/variables.mdx
similarity index 100%
rename from src/pages/en/latest/learn/basics/variables.mdx
rename to src/pages/en/latest/learn/01_basics/variables.mdx
diff --git a/src/pages/en/latest/learn/data-structures/arrays.mdx b/src/pages/en/latest/learn/02_data-structures/arrays.mdx
similarity index 100%
rename from src/pages/en/latest/learn/data-structures/arrays.mdx
rename to src/pages/en/latest/learn/02_data-structures/arrays.mdx
diff --git a/src/pages/en/latest/learn/data-structures/enums.mdx b/src/pages/en/latest/learn/02_data-structures/enums.mdx
similarity index 100%
rename from src/pages/en/latest/learn/data-structures/enums.mdx
rename to src/pages/en/latest/learn/02_data-structures/enums.mdx
diff --git a/src/pages/en/latest/learn/data-structures/maps.mdx b/src/pages/en/latest/learn/02_data-structures/maps.mdx
similarity index 100%
rename from src/pages/en/latest/learn/data-structures/maps.mdx
rename to src/pages/en/latest/learn/02_data-structures/maps.mdx
diff --git a/src/pages/en/latest/learn/data-structures/tuples.mdx b/src/pages/en/latest/learn/02_data-structures/tuples.mdx
similarity index 100%
rename from src/pages/en/latest/learn/data-structures/tuples.mdx
rename to src/pages/en/latest/learn/02_data-structures/tuples.mdx
diff --git a/src/pages/en/latest/learn/data-structures/unions.mdx b/src/pages/en/latest/learn/02_data-structures/unions.mdx
similarity index 100%
rename from src/pages/en/latest/learn/data-structures/unions.mdx
rename to src/pages/en/latest/learn/02_data-structures/unions.mdx
diff --git a/src/pages/en/latest/learn/flow-control/blocks.mdx b/src/pages/en/latest/learn/03_flow-control/blocks.mdx
similarity index 100%
rename from src/pages/en/latest/learn/flow-control/blocks.mdx
rename to src/pages/en/latest/learn/03_flow-control/blocks.mdx
diff --git a/src/pages/en/latest/learn/flow-control/conditionals.mdx b/src/pages/en/latest/learn/03_flow-control/conditionals.mdx
similarity index 100%
rename from src/pages/en/latest/learn/flow-control/conditionals.mdx
rename to src/pages/en/latest/learn/03_flow-control/conditionals.mdx
diff --git a/src/pages/en/latest/learn/flow-control/loops.mdx b/src/pages/en/latest/learn/03_flow-control/loops.mdx
similarity index 100%
rename from src/pages/en/latest/learn/flow-control/loops.mdx
rename to src/pages/en/latest/learn/03_flow-control/loops.mdx
diff --git a/src/pages/en/latest/learn/flow-control/match.mdx b/src/pages/en/latest/learn/03_flow-control/match.mdx
similarity index 100%
rename from src/pages/en/latest/learn/flow-control/match.mdx
rename to src/pages/en/latest/learn/03_flow-control/match.mdx
diff --git a/src/pages/en/latest/learn/functions/declaration.mdx b/src/pages/en/latest/learn/04_functions/declaration.mdx
similarity index 100%
rename from src/pages/en/latest/learn/functions/declaration.mdx
rename to src/pages/en/latest/learn/04_functions/declaration.mdx
diff --git a/src/pages/en/latest/learn/functions/higher-order.mdx b/src/pages/en/latest/learn/04_functions/higher-order.mdx
similarity index 100%
rename from src/pages/en/latest/learn/functions/higher-order.mdx
rename to src/pages/en/latest/learn/04_functions/higher-order.mdx
diff --git a/src/pages/en/latest/learn/functions/lambdas.mdx b/src/pages/en/latest/learn/04_functions/lambdas.mdx
similarity index 100%
rename from src/pages/en/latest/learn/functions/lambdas.mdx
rename to src/pages/en/latest/learn/04_functions/lambdas.mdx
diff --git a/src/pages/en/latest/learn/functions/parameters.mdx b/src/pages/en/latest/learn/04_functions/parameters.mdx
similarity index 100%
rename from src/pages/en/latest/learn/functions/parameters.mdx
rename to src/pages/en/latest/learn/04_functions/parameters.mdx
diff --git a/src/pages/en/latest/learn/error-handling/null.mdx b/src/pages/en/latest/learn/05_error-handling/null.mdx
similarity index 100%
rename from src/pages/en/latest/learn/error-handling/null.mdx
rename to src/pages/en/latest/learn/05_error-handling/null.mdx
diff --git a/src/pages/en/latest/learn/error-handling/try.mdx b/src/pages/en/latest/learn/05_error-handling/try.mdx
similarity index 100%
rename from src/pages/en/latest/learn/error-handling/try.mdx
rename to src/pages/en/latest/learn/05_error-handling/try.mdx
diff --git a/src/pages/en/latest/learn/classes/abstract.mdx b/src/pages/en/latest/learn/06_classes/abstract.mdx
similarity index 100%
rename from src/pages/en/latest/learn/classes/abstract.mdx
rename to src/pages/en/latest/learn/06_classes/abstract.mdx
diff --git a/src/pages/en/latest/learn/classes/anonymous.mdx b/src/pages/en/latest/learn/06_classes/anonymous.mdx
similarity index 100%
rename from src/pages/en/latest/learn/classes/anonymous.mdx
rename to src/pages/en/latest/learn/06_classes/anonymous.mdx
diff --git a/src/pages/en/latest/learn/classes/constructor.mdx b/src/pages/en/latest/learn/06_classes/constructor.mdx
similarity index 100%
rename from src/pages/en/latest/learn/classes/constructor.mdx
rename to src/pages/en/latest/learn/06_classes/constructor.mdx
diff --git a/src/pages/en/latest/learn/classes/definition.mdx b/src/pages/en/latest/learn/06_classes/definition.mdx
similarity index 100%
rename from src/pages/en/latest/learn/classes/definition.mdx
rename to src/pages/en/latest/learn/06_classes/definition.mdx
diff --git a/src/pages/en/latest/learn/classes/inheritance.mdx b/src/pages/en/latest/learn/06_classes/inheritance.mdx
similarity index 100%
rename from src/pages/en/latest/learn/classes/inheritance.mdx
rename to src/pages/en/latest/learn/06_classes/inheritance.mdx
diff --git a/src/pages/en/latest/learn/classes/interfaces.mdx b/src/pages/en/latest/learn/06_classes/interfaces.mdx
similarity index 100%
rename from src/pages/en/latest/learn/classes/interfaces.mdx
rename to src/pages/en/latest/learn/06_classes/interfaces.mdx
diff --git a/src/pages/en/latest/learn/classes/magic.mdx b/src/pages/en/latest/learn/06_classes/magic.mdx
similarity index 100%
rename from src/pages/en/latest/learn/classes/magic.mdx
rename to src/pages/en/latest/learn/06_classes/magic.mdx
diff --git a/src/pages/en/latest/learn/classes/readonly.mdx b/src/pages/en/latest/learn/06_classes/readonly.mdx
similarity index 100%
rename from src/pages/en/latest/learn/classes/readonly.mdx
rename to src/pages/en/latest/learn/06_classes/readonly.mdx
diff --git a/src/pages/en/latest/learn/classes/static.mdx b/src/pages/en/latest/learn/06_classes/static.mdx
similarity index 100%
rename from src/pages/en/latest/learn/classes/static.mdx
rename to src/pages/en/latest/learn/06_classes/static.mdx
diff --git a/src/pages/en/latest/learn/classes/visibility.mdx b/src/pages/en/latest/learn/06_classes/visibility.mdx
similarity index 100%
rename from src/pages/en/latest/learn/classes/visibility.mdx
rename to src/pages/en/latest/learn/06_classes/visibility.mdx
diff --git a/src/pages/en/latest/learn/templating/components.mdx b/src/pages/en/latest/learn/07_templating/components.mdx
similarity index 100%
rename from src/pages/en/latest/learn/templating/components.mdx
rename to src/pages/en/latest/learn/07_templating/components.mdx
diff --git a/src/pages/en/latest/learn/templating/control-flow.mdx b/src/pages/en/latest/learn/07_templating/control-flow.mdx
similarity index 100%
rename from src/pages/en/latest/learn/templating/control-flow.mdx
rename to src/pages/en/latest/learn/07_templating/control-flow.mdx
diff --git a/src/pages/en/latest/learn/templating/intro.mdx b/src/pages/en/latest/learn/07_templating/intro.mdx
similarity index 100%
rename from src/pages/en/latest/learn/templating/intro.mdx
rename to src/pages/en/latest/learn/07_templating/intro.mdx
diff --git a/src/pages/en/latest/learn/templating/props.mdx b/src/pages/en/latest/learn/07_templating/props.mdx
similarity index 100%
rename from src/pages/en/latest/learn/templating/props.mdx
rename to src/pages/en/latest/learn/07_templating/props.mdx