fix route

This commit is contained in:
Barrett Ruth 2025-10-09 15:29:04 -04:00
parent 100ba75689
commit b024a8bbff

View file

@ -1,26 +1,27 @@
--- ---
import BaseLayout from "../../layouts/BaseLayout.astro"; import BaseLayout from "../../layouts/BaseLayout.astro";
import { getCollection } from "astro:content"; import { getCollection } from "astro:content";
import * as collections from "../../content/config";
export async function getStaticPaths() {
return Object.keys(collections.collections)
.filter((category) => category !== "git" && category !== "gists")
.map((category) => ({
params: { category },
}));
}
const category = Astro.params.category; const category = Astro.params.category;
const title = "Barrett Ruth"; const title = "Barrett Ruth";
const allPosts = await getCollection("posts"); const posts = await getCollection(category);
const postsByCategory = allPosts.reduce((acc, post) => { posts.sort((a, b) => {
const c = post.id.split("/")[0]; const parseEuroDate = (dateStr) => {
(acc[c] ||= []).push(post); if (!dateStr) return new Date(0);
return acc; const [day, month, year] = (dateStr || "").split("/");
}, {}); return new Date(year, month - 1, day);
};
Object.keys(postsByCategory).forEach((c) => { return parseEuroDate(b.data.date) - parseEuroDate(a.data.date);
postsByCategory[c].sort((a, b) => {
const parseEuroDate = (dateStr) => {
if (!dateStr) return new Date(0);
const [day, month, year] = (dateStr || "").split("/");
return new Date(year, month - 1, day);
};
return parseEuroDate(b.data.date) - parseEuroDate(a.data.date);
});
}); });
--- ---
@ -40,16 +41,19 @@ Object.keys(postsByCategory).forEach((c) => {
<li class="topic meditations"> <li class="topic meditations">
<a href="/meditations" data-topic="meditations">meditations</a> <a href="/meditations" data-topic="meditations">meditations</a>
</li> </li>
<li class="topic autonomous-racing">
<a href="/autonomous-racing" data-topic="autonomous-racing"
>autonomous-racing</a
>
</li>
</ul> </ul>
<div class="posts" id="posts"></div>
</div>
<script <div class="posts" id="posts">
slot="scripts" {
define:vars={{ postsByCategory, SELECTED_CATEGORY: category }} posts.map((p) => (
> <a href={`/${category}/${p.slug}.html`}>{p.data.title}</a>
window.postsByCategory = postsByCategory; ))
window.SELECTED_CATEGORY = SELECTED_CATEGORY; }
</script> </div>
<script slot="scripts" type="module" src="/scripts/index.js"></script> </div>
</BaseLayout> </BaseLayout>