chore: format [...slug].astro

This commit is contained in:
Skyler Grey 2024-05-25 15:11:07 +00:00 committed by Samuel Shuert
parent dd452009fe
commit c403a8151b

View file

@ -1,102 +1,83 @@
--- ---
import { type CollectionEntry, getCollection, getEntry } from 'astro:content'; import { type CollectionEntry, getCollection, getEntry } from "astro:content";
import NavBar from '../components/NavBar.astro'; import NavBar from "../components/NavBar.astro";
import Renderer from '../components/Renderer.astro'; import Renderer from "../components/Renderer.astro";
import NavPage from '../components/NavPage.astro'; import NavPage from "../components/NavPage.astro";
import "../style/globals.css" import "../style/globals.css";
import { allPageAndDirectoryPaths } from "../lib/pagePaths"; import { allPageAndDirectoryPaths } from "../lib/pagePaths";
import { parse } from "node:path" import { parse } from "node:path";
export async function getStaticPaths() { export async function getStaticPaths() {
const wikiPages = await getCollection('wiki'); const wikiPages = await getCollection("wiki");
const paths = allPageAndDirectoryPaths(wikiPages); const paths = allPageAndDirectoryPaths(wikiPages);
return [ return [
{ {
params: { slug: undefined }, params: { slug: undefined },
props: { path: "home", name: "Home", post: await getEntry("wiki", "home") } props: {
}, path: "home",
...Array.from(paths.entries()).flatMap(([key, post]) => { name: "Home",
if (!post) { post: await getEntry("wiki", "home"),
return [{ },
params: { slug: key }, },
props: { path: key, name: parse(key).name } ...Array.from(paths.entries()).flatMap(([key, post]) => {
}] if (!post) {
} else { return [
return [ {
{ params: { slug: key },
params: { slug: post.slug }, props: { path: key, name: parse(key).name },
props: { path: post.id, name: post.data.title, post }, },
}, ];
{ } else {
params: { slug: post.slug + ".md" }, return [
props: { path: post.id, name: post.data.title, post }, {
} params: { slug: post.slug },
] props: { path: post.id, name: post.data.title, post },
} },
}) {
params: { slug: post.slug + ".md" },
// ...pages.flatMap((post: CollectionEntry<'wiki'> | undefined) => { props: { path: post.id, name: post.data.title, post },
// if (!post) { },
// return [{ ];
// params: { slug: } }
// }] }),
// } else { ];
// return [
// {
// params: { slug: post.slug },
// props: { path: post.id, name: post.data.title, post },
// },
// {
// params: { slug: post.slug + ".md" },
// props: { path: post.id, name: post.data.title, post },
// }
// ]
// }
// })
];
} }
type Props = { type Props = {
post?: CollectionEntry<'wiki'> post?: CollectionEntry<"wiki">;
path: string; path: string;
name: string; name: string;
}; };
const { post, path, name } = Astro.props; const { post, path, name } = Astro.props;
--- ---
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8" />
<title>Aux Docs - {name}</title> <title>Aux Docs - {name}</title>
{ {
post ? ( post ? (
<link rel="canonical" href={`https://wiki.auxolotl.org/${path}`} /> <link rel="canonical" href={`https://wiki.auxolotl.org/${path}`} />
) : null ) : null
} }
</head> </head>
<style> <style>
.box { .box {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
margin: 0; margin: 0;
height: 100vh; height: 100vh;
} }
.nav-pane { .nav-pane {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
min-width: 16em; min-width: 16em;
width: fit-content; width: fit-content;
} }
</style> </style>
<body class="box"> <body class="box">
<div class="nav-pane"> <div class="nav-pane">
<NavBar currentPage={path} /> <NavBar currentPage={path} />
</div> </div>
{ {post ? <Renderer post={post} /> : <NavPage path={path} />}
post ? (
<Renderer post={post} />
) : (
<NavPage path={path} />
)
}
</body> </body>