Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions starlight/src/components/ReadingTimeRoutes.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
import Page from "../../node_modules/starlight-blog/components/Page.astro";
import PostCount from "../../node_modules/starlight-blog/components/PostCount.astro";
import Posts from "../../node_modules/starlight-blog/components/Posts.astro";
import {
getBlogEntries,
type StarlightBlogEntry,
} from "../../node_modules/starlight-blog/libs/content";

const { posts } = Astro.locals.starlightBlog;

export async function getStaticPaths() {
return [
{ params: { length: "short" } },
{ params: { length: "medium" } },
{ params: { length: "long" } },
];
}
const { length } = Astro.params;

const pageProps = {
frontmatter: {
pagefind: false,
title: length + " posts",
prev: false,
next: false,
},
};

const starlightBlogEntries = (await getBlogEntries(
"en"
)) as StarlightBlogEntry[];
const entries = starlightBlogEntries.filter((entry) => {
const representativeEntry = posts.find((post) => post.href === entry.id);
if (!representativeEntry) return false;
if (length === "short")
return representativeEntry.metrics.readingTime.minutes < 2;
if (length === "medium")
return (
representativeEntry.metrics.readingTime.minutes >= 2 &&
representativeEntry.metrics.readingTime.minutes < 5
);
if (length === "long")
return representativeEntry.metrics.readingTime.minutes >= 5;
return false;
});
---

<Page {...pageProps}>
<PostCount>{entries.length} {length} posts.</PostCount>
<Posts {entries} locale="en" />
</Page>