fix route
This commit is contained in:
parent
100ba75689
commit
b024a8bbff
1 changed files with 30 additions and 26 deletions
|
|
@ -1,19 +1,21 @@
|
||||||
---
|
---
|
||||||
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];
|
|
||||||
(acc[c] ||= []).push(post);
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
Object.keys(postsByCategory).forEach((c) => {
|
|
||||||
postsByCategory[c].sort((a, b) => {
|
|
||||||
const parseEuroDate = (dateStr) => {
|
const parseEuroDate = (dateStr) => {
|
||||||
if (!dateStr) return new Date(0);
|
if (!dateStr) return new Date(0);
|
||||||
const [day, month, year] = (dateStr || "").split("/");
|
const [day, month, year] = (dateStr || "").split("/");
|
||||||
|
|
@ -21,7 +23,6 @@ Object.keys(postsByCategory).forEach((c) => {
|
||||||
};
|
};
|
||||||
return parseEuroDate(b.data.date) - parseEuroDate(a.data.date);
|
return parseEuroDate(b.data.date) - parseEuroDate(a.data.date);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<BaseLayout title={title}>
|
<BaseLayout title={title}>
|
||||||
|
|
@ -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>
|
||||||
</ul>
|
<li class="topic autonomous-racing">
|
||||||
<div class="posts" id="posts"></div>
|
<a href="/autonomous-racing" data-topic="autonomous-racing"
|
||||||
</div>
|
>autonomous-racing</a
|
||||||
|
|
||||||
<script
|
|
||||||
slot="scripts"
|
|
||||||
define:vars={{ postsByCategory, SELECTED_CATEGORY: category }}
|
|
||||||
>
|
>
|
||||||
window.postsByCategory = postsByCategory;
|
</li>
|
||||||
window.SELECTED_CATEGORY = SELECTED_CATEGORY;
|
</ul>
|
||||||
</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>
|
</BaseLayout>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue