mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-04-18 20:38:45 -04:00
add getStaticProps types
This commit is contained in:
@@ -3,7 +3,7 @@ import { getAllNotes } from "./parse-notes";
|
||||
import * as config from "../config";
|
||||
import { RELEASE_DATE } from "../config/constants";
|
||||
import { favicons } from "../config/seo";
|
||||
import type { GetServerSidePropsContext, PreviewData } from "next";
|
||||
import type { GetServerSidePropsContext, GetServerSidePropsResult, PreviewData } from "next";
|
||||
import type { ParsedUrlQuery } from "querystring";
|
||||
|
||||
export type BuildFeedOptions = {
|
||||
@@ -11,12 +11,12 @@ export type BuildFeedOptions = {
|
||||
};
|
||||
|
||||
// handles literally *everything* about building the server-side rss/atom feeds and writing the response.
|
||||
// all the page needs to do is `return buildFeed(context, { format: "rss" })` from getServerSideProps.
|
||||
// all the page needs to do is `return buildFeed(context, "rss")` from getServerSideProps.
|
||||
export const buildFeed = async (
|
||||
context: GetServerSidePropsContext<ParsedUrlQuery, PreviewData>,
|
||||
type: "rss" | "atom" | "json",
|
||||
options?: BuildFeedOptions
|
||||
): Promise<{ props: Record<string, unknown> }> => {
|
||||
): Promise<GetServerSidePropsResult<Record<string, never>>> => {
|
||||
const { res } = context;
|
||||
|
||||
// https://github.com/jpmonette/feed#example
|
||||
@@ -25,7 +25,7 @@ export const buildFeed = async (
|
||||
link: `${config.baseUrl}/`,
|
||||
title: config.siteName,
|
||||
description: config.longDescription,
|
||||
copyright: "https://creativecommons.org/licenses/by/4.0/",
|
||||
copyright: config.licenseUrl,
|
||||
updated: new Date(RELEASE_DATE),
|
||||
image: `${config.baseUrl}${favicons.meJpg.src}`,
|
||||
feedLinks: {
|
||||
|
||||
@@ -13,7 +13,10 @@ import type { NoteFrontMatter } from "../../types";
|
||||
|
||||
export const getNoteSlugs = async (): Promise<string[]> => {
|
||||
// list all .mdx files in NOTES_DIR
|
||||
const mdxFiles = await glob("*.mdx", { cwd: NOTES_DIR });
|
||||
const mdxFiles = await glob("*.mdx", {
|
||||
cwd: NOTES_DIR,
|
||||
dot: false,
|
||||
});
|
||||
|
||||
// strip the .mdx extensions from filenames
|
||||
const slugs = mdxFiles.map((fileName) => fileName.replace(/\.mdx$/, ""));
|
||||
@@ -51,14 +54,12 @@ export const getNoteData = async (
|
||||
};
|
||||
};
|
||||
|
||||
// returns the front matter of ALL notes, sorted reverse chronologically
|
||||
// returns the parsed front matter of ALL notes, sorted reverse chronologically
|
||||
export const getAllNotes = async (): Promise<NoteFrontMatter[]> => {
|
||||
const slugs = await getNoteSlugs();
|
||||
|
||||
// for each slug, query its front matter
|
||||
const data = await pMap(slugs, async (slug) => (await getNoteData(slug)).frontMatter, {
|
||||
stopOnError: true,
|
||||
});
|
||||
const data = await pMap(slugs, async (slug) => (await getNoteData(slug)).frontMatter);
|
||||
|
||||
// sort the results by date
|
||||
data.sort((note1, note2) => (note1.date > note2.date ? -1 : 1));
|
||||
|
||||
Reference in New Issue
Block a user