diff --git a/src/components/Sidebar.astro b/src/components/Sidebar.astro
index c9ac403..830150c 100644
--- a/src/components/Sidebar.astro
+++ b/src/components/Sidebar.astro
@@ -2,17 +2,7 @@
import type { PageEntry } from "../layouts/PagesLayout.astro";
const entry: PageEntry = Astro.props.entry;
-const basePath: string = Astro.props.basePath;
-
-const entryPath = is_index_file(entry.path)? "": entry.path;
-
-const entryUrl = basePath + entryPath + (entryPath.endsWith("/")? "" : "/");
-
-function is_index_file(p) {
- return p.endsWith("index")
- || p.endsWith("index.md")
- || p.endsWith("index.mdx")
-}
+const post_url = entry.url + (entry.url.endsWith("/") ? "" : "/");
---
{
@@ -20,7 +10,7 @@ function is_index_file(p) {
{entry.title}
@@ -38,7 +28,6 @@ function is_index_file(p) {
{entry.children!.map((nextEntry) => (
))}
diff --git a/src/layouts/NewDocsLayout.astro b/src/layouts/NewDocsLayout.astro
index c3cc8ff..07e7193 100644
--- a/src/layouts/NewDocsLayout.astro
+++ b/src/layouts/NewDocsLayout.astro
@@ -25,29 +25,33 @@ export interface Frontmatter {
}
type Props = {
- /** The directory where all the md/mdx files start from */
- base_dir: string
+ /** Base url. It is used to later build a tree file system */
+ base_url: string,
frontmatter: Frontmatter;
headings: any;
posts: Array;
};
const {
- base_dir,
+ base_url,
frontmatter,
headings,
posts
}: Props = Astro.props;
-const base_dir_end = base_dir.length;
+const base_len = base_url.length;
const posts_2 = posts
- .map(post => ({
+ .map(post => {
+ return {
...post,
- relative_file: post.file.substring(base_dir_end),
- path: post.file.substring(base_dir_end).replace(/\.mdx?$/, ""),
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
@@ -65,7 +69,7 @@ for (const post of posts_2) {
}
second_level[folder_name].push(post);
}
- else if (fragments.length === 2) {
+ else {
// add to root folder
second_level["_"]!.push(post);
}
@@ -86,17 +90,24 @@ for (const levels_key in second_level) {
path: "",
title: levels_key,
children: posts,
+ url: "",
};
entries.push(parentEntry);
}
}
-const index_page = entries.find(post => post.relative_file === "/index.md" || post.relative_file === "/index.mdx");
-if (index_page === undefined && process.env.NODE_ENV !== "production") {
+/*
+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("Props base_dir:", base_dir);
+ 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");
}
const basePath = index_page?.url ?? "/";
+*/
---
@@ -113,7 +124,7 @@ const basePath = index_page?.url ?? "/";
diff --git a/src/pages/en/latest/learn/_wrapper.astro b/src/pages/en/latest/learn/_wrapper.astro
index 79329dd..ad4c022 100644
--- a/src/pages/en/latest/learn/_wrapper.astro
+++ b/src/pages/en/latest/learn/_wrapper.astro
@@ -6,12 +6,12 @@ const { frontmatter, headings } = Astro.props;
const posts = await Astro.glob("./**/*.{md,mdx}") as unknown as Array;
-// Current dir
-const current_dir = import.meta.dirname;
+// The base of every URL under this glob
+const base_url = "/en/latest/learn"
---
;
-// Current dir
-const current_dir = import.meta.dirname;
+// The base of every URL under this glob
+const base_url = "/spec"
---