fix route
This commit is contained in:
parent
100ba75689
commit
b024a8bbff
1 changed files with 30 additions and 26 deletions
|
|
@ -1,26 +1,27 @@
|
|||
---
|
||||
import BaseLayout from "../../layouts/BaseLayout.astro";
|
||||
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 title = "Barrett Ruth";
|
||||
|
||||
const allPosts = await getCollection("posts");
|
||||
const postsByCategory = allPosts.reduce((acc, post) => {
|
||||
const c = post.id.split("/")[0];
|
||||
(acc[c] ||= []).push(post);
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
Object.keys(postsByCategory).forEach((c) => {
|
||||
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);
|
||||
});
|
||||
const posts = await getCollection(category);
|
||||
posts.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">
|
||||
<a href="/meditations" data-topic="meditations">meditations</a>
|
||||
</li>
|
||||
<li class="topic autonomous-racing">
|
||||
<a href="/autonomous-racing" data-topic="autonomous-racing"
|
||||
>autonomous-racing</a
|
||||
>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="posts" id="posts"></div>
|
||||
</div>
|
||||
|
||||
<script
|
||||
slot="scripts"
|
||||
define:vars={{ postsByCategory, SELECTED_CATEGORY: category }}
|
||||
>
|
||||
window.postsByCategory = postsByCategory;
|
||||
window.SELECTED_CATEGORY = SELECTED_CATEGORY;
|
||||
</script>
|
||||
<script slot="scripts" type="module" src="/scripts/index.js"></script>
|
||||
<div class="posts" id="posts">
|
||||
{
|
||||
posts.map((p) => (
|
||||
<a href={`/${category}/${p.slug}.html`}>{p.data.title}</a>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</BaseLayout>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue