Add Mastodon comments and remove date-fns dependency
This commit is contained in:
parent
00fa1fb164
commit
3e8bcbcf43
19 changed files with 393 additions and 142 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import rss, { type RSSFeedItem } from "@astrojs/rss";
|
||||
import type { APIRoute } from "astro";
|
||||
import { getCollection } from "astro:content";
|
||||
import { getUnixTime, addMinutes } from "date-fns";
|
||||
|
||||
type FeedItem = RSSFeedItem & {
|
||||
pubDate: Date;
|
||||
|
|
@ -9,9 +8,19 @@ type FeedItem = RSSFeedItem & {
|
|||
|
||||
const MAX_ITEMS = 10;
|
||||
|
||||
function toNoonUTCDate(date: Date) {
|
||||
const adjustedDate = new Date(date);
|
||||
adjustedDate.setUTCHours(12);
|
||||
return adjustedDate;
|
||||
}
|
||||
|
||||
export const GET: APIRoute = async ({ site }) => {
|
||||
const stories = (await getCollection("stories", (story) => !story.data.isDraft)).sort((a, b) => getUnixTime(b.data.pubDate) - getUnixTime(a.data.pubDate)).slice(0, MAX_ITEMS);
|
||||
const games = (await getCollection("games", (game) => !game.data.isDraft)).sort((a, b) => getUnixTime(b.data.pubDate) - getUnixTime(a.data.pubDate)).slice(0, MAX_ITEMS);
|
||||
const stories = (await getCollection("stories", (story) => !story.data.isDraft))
|
||||
.sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime())
|
||||
.slice(0, MAX_ITEMS);
|
||||
const games = (await getCollection("games", (game) => !game.data.isDraft))
|
||||
.sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime())
|
||||
.slice(0, MAX_ITEMS);
|
||||
return rss({
|
||||
title: "Gallery | Bad Manners",
|
||||
description: "Stories, games, and (possibly) more by Bad Manners",
|
||||
|
|
@ -19,7 +28,7 @@ export const GET: APIRoute = async ({ site }) => {
|
|||
items: [
|
||||
stories.map<FeedItem>((story) => ({
|
||||
title: `New story! "${story.data.title}"`,
|
||||
pubDate: addMinutes(story.data.pubDate, 12 * 60 - story.data.pubDate.getTimezoneOffset()),
|
||||
pubDate: toNoonUTCDate(story.data.pubDate),
|
||||
link: `/stories/${story.slug}`,
|
||||
description:
|
||||
`Word count: ${story.data.wordCount}. ${story.data.contentWarning} ${story.data.descriptionPlaintext || story.data.description}`
|
||||
|
|
@ -29,7 +38,7 @@ export const GET: APIRoute = async ({ site }) => {
|
|||
})),
|
||||
games.map<FeedItem>((game) => ({
|
||||
title: `New game! "${game.data.title}"`,
|
||||
pubDate: addMinutes(game.data.pubDate, 12 * 60 - game.data.pubDate.getTimezoneOffset()),
|
||||
pubDate: toNoonUTCDate(game.data.pubDate),
|
||||
link: `/games/${game.slug}`,
|
||||
description: `${game.data.contentWarning} ${game.data.descriptionPlaintext || game.data.description}`
|
||||
.replaceAll(/[\n ]+/g, " ")
|
||||
|
|
@ -38,7 +47,7 @@ export const GET: APIRoute = async ({ site }) => {
|
|||
})),
|
||||
]
|
||||
.flat()
|
||||
.sort((a, b) => getUnixTime(b.pubDate) - getUnixTime(a.pubDate))
|
||||
.sort((a, b) => b.pubDate.getTime() - a.pubDate.getTime())
|
||||
.slice(0, MAX_ITEMS),
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue