1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2026-01-14 10:42:56 -05:00

add getStaticProps types

This commit is contained in:
2022-06-30 20:56:34 -04:00
parent 5f22b7989d
commit 887c24d317
17 changed files with 67 additions and 50 deletions

View File

@@ -6,4 +6,4 @@ import path from "path";
export const NOTES_DIR = path.join(process.cwd(), "notes");
// normalize the timestamp saved when building/deploying (see next.config.js) and fall back to right now:
export const RELEASE_DATE = new Date(process.env.NEXT_PUBLIC_RELEASE_DATE || Date.now()).toISOString();
export const RELEASE_DATE = new Date(process.env.RELEASE_DATE || Date.now()).toISOString();

View File

@@ -16,6 +16,10 @@ module.exports = {
shortDescription: "Front-End Web Developer in Boston, MA",
longDescription:
"Hi there! I'm a frontend web developer based in Boston, Massachusetts specializing in the JAMstack, modern JavaScript frameworks, and progressive web apps.",
license: "Creative Commons Attribution 4.0 International",
licenseAbbr: "CC-BY-4.0",
licenseUrl: "https://creativecommons.org/licenses/by/4.0/",
copyrightYearStart: 2001,
githubRepo: "jakejarvis/jarv.is",
verifyGoogle: "qQhmLTwjNWYgQ7W42nSTq63xIrTch13X_11mmxBE9zk",
verifyBing: "164551986DA47F7F6FC0D21A93FFFCA6",

View File

@@ -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: {

View File

@@ -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));