1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-19 05:35:30 -04:00

bump next

This commit is contained in:
2022-06-14 07:55:13 -04:00
parent 4e0ca9ff4d
commit e735ea9a99
7 changed files with 120 additions and 123 deletions

View File

@@ -7,7 +7,6 @@ import type { GetServerSidePropsContext, PreviewData } from "next";
import type { ParsedUrlQuery } from "querystring";
export type BuildFeedOptions = {
type: "rss" | "atom" | "json";
edgeCacheAge?: number; // in seconds, defaults to 43200 (12 hours)
};
@@ -15,7 +14,8 @@ export type BuildFeedOptions = {
// all the page needs to do is `return buildFeed(context, { format: "rss" })` from getServerSideProps.
export const buildFeed = async (
context: GetServerSidePropsContext<ParsedUrlQuery, PreviewData>,
options: BuildFeedOptions
type: "rss" | "atom" | "json",
options?: BuildFeedOptions
): Promise<{ props: Record<string, unknown> }> => {
const { res } = context;
@@ -61,23 +61,23 @@ export const buildFeed = async (
// cache on edge for 12 hours by default
res.setHeader(
"cache-control",
`public, max-age=0, s-maxage=${options.edgeCacheAge ?? 86400}, stale-while-revalidate`
`public, max-age=0, s-maxage=${options?.edgeCacheAge ?? 86400}, stale-while-revalidate`
);
// generates RSS by default
if (options.type === "rss") {
if (type === "rss") {
res.setHeader("content-type", "application/rss+xml; charset=utf-8");
res.write(feed.rss2());
} else if (options.type === "atom") {
} else if (type === "atom") {
res.setHeader("content-type", "application/atom+xml; charset=utf-8");
res.write(feed.atom1());
} else if (options.type === "json") {
} else if (type === "json") {
// rare but including as an option because why not...
// https://www.jsonfeed.org/
res.setHeader("content-type", "application/feed+json; charset=utf-8");
res.write(feed.json1());
} else {
throw new TypeError(`Invalid feed type "${options.type}", must be "rss", "atom", or "json".`);
throw new TypeError(`Invalid feed type "${type}", must be "rss", "atom", or "json".`);
}
res.end();