feat: add canonical URLs #3

Merged
Minion3665 merged 3 commits from private/skyler/canonical-urls into main 2024-05-25 15:13:20 +00:00
3 changed files with 70 additions and 84 deletions

View file

@ -149,11 +149,11 @@
"wiki": { "wiki": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1716056148, "lastModified": 1716579217,
"narHash": "sha256-jWgjCkiExjBrRYcBzziNGPkorzJBLyWIa/ZUyUqqcr0=", "narHash": "sha256-Zu/DzCkjgic5qAFGgrRtpuPD8I9/kYqNxhCmixYL0GY=",
"owner": "auxolotl", "owner": "auxolotl",
"repo": "wiki", "repo": "wiki",
"rev": "644da0cf69dd962394c75cf4c924b19d56ba60c4", "rev": "c2f9bdfeba0b44aae46569da6207867706e7f6ee",
"type": "github" "type": "github"
}, },
"original": { "original": {

@ -1 +1 @@
Subproject commit 644da0cf69dd962394c75cf4c924b19d56ba60c4 Subproject commit c2f9bdfeba0b44aae46569da6207867706e7f6ee

View file

@ -1,26 +1,32 @@
--- ---
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",
name: "Home",
post: await getEntry("wiki", "home"),
},
}, },
...Array.from(paths.entries()).flatMap(([key, post]) => { ...Array.from(paths.entries()).flatMap(([key, post]) => {
if (!post) { if (!post) {
return [{ return [
{
params: { slug: key }, params: { slug: key },
props: { path: key, name: parse(key).name } props: { path: key, name: parse(key).name },
}] },
];
} else { } else {
return [ return [
{ {
@ -30,34 +36,15 @@ export async function getStaticPaths() {
{ {
params: { slug: post.slug + ".md" }, params: { slug: post.slug + ".md" },
props: { path: post.id, name: post.data.title, post }, props: { path: post.id, name: post.data.title, post },
},
];
} }
] }),
}
})
// ...pages.flatMap((post: CollectionEntry<'wiki'> | undefined) => {
// 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;
}; };
@ -66,8 +53,13 @@ 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 ? (
<link rel="canonical" href={`https://wiki.auxolotl.org/${path}`} />
) : null
}
</head> </head>
<style> <style>
.box { .box {
@ -87,11 +79,5 @@ const { post, path, name } = Astro.props;
<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>