gallery.badmanners.xyz/src/pages/stories/[...slug].astro
Bad Manners cd67f6a5c5 Add qualifyLocalURLsInMarkdown()
This will handle special links in the description and similar fields
2024-08-12 21:57:09 -03:00

36 lines
1 KiB
Text

---
import type { GetStaticPaths } from "astro";
import { type CollectionEntry, getCollection } from "astro:content";
import getReadingTime from "reading-time";
import StoryLayout from "../../layouts/StoryLayout.astro";
type Props = CollectionEntry<"stories">;
type Params = {
slug: CollectionEntry<"stories">["slug"];
};
export const getStaticPaths: GetStaticPaths = async () => {
const stories = await getCollection("stories");
return stories.map((story) => ({
params: { slug: story.slug } satisfies Params,
props: story satisfies Props,
}));
};
const story = Astro.props;
const readingTime = getReadingTime(story.body);
if (story.data.wordCount && Math.abs(story.data.wordCount - readingTime.words) >= 150) {
console.warn(
`WARNING: "wordCount" differs greatly from actual word count for published story ` +
`${story.data.title} ("${story.slug}") ` +
`(expected ~${story.data.wordCount}, found ${readingTime.words})`,
);
}
const { Content } = await story.render();
---
<StoryLayout {...story.data}>
<Content />
</StoryLayout>