1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-07-19 13:55:31 -04:00

server all the actions!

This commit is contained in:
2025-02-08 12:37:41 -05:00
parent fa5edc003f
commit 37375b766f
27 changed files with 689 additions and 707 deletions

View File

@@ -1,9 +0,0 @@
// very simple fetch wrapper that's passed into SWR hooks:
// https://swr.vercel.app/docs/data-fetching#fetch
// note: fetch does *not* need to be poly/ponyfilled in Next.js:
// https://nextjs.org/blog/next-9-1-7#new-built-in-polyfills-fetch-url-and-objectassign
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const fetcher = <T = any>(...args: Parameters<typeof fetch>): Promise<T> => fetch(...args).then((res) => res.json());
export default fetcher;

View File

@@ -5,17 +5,28 @@ import pMap from "p-map";
import pMemoize from "p-memoize";
import matter from "gray-matter";
import { formatDate } from "./format-date";
import type { PostFrontMatter } from "../../types";
import { metadata as defaultMetadata } from "../../app/layout";
// path to directory with .mdx files, relative to project root
export const POSTS_DIR = "notes";
const POSTS_DIR = "notes";
export type FrontMatter = {
slug: string;
permalink: string;
date: string;
title: string;
htmlTitle?: string;
description?: string;
image?: string;
tags?: string[];
noComments?: boolean;
};
// returns front matter and the **raw & uncompiled** markdown of a given slug
export const getPostData = async (
slug: string
): Promise<{
frontMatter: PostFrontMatter;
frontMatter: FrontMatter;
markdown: string;
}> => {
const { unified } = await import("unified");
@@ -54,7 +65,7 @@ export const getPostData = async (
// return both the parsed YAML front matter (with a few amendments) and the raw, unparsed markdown content
return {
frontMatter: {
...(data as Partial<PostFrontMatter>),
...(data as Partial<FrontMatter>),
// zero markdown title:
title,
htmlTitle,
@@ -81,7 +92,7 @@ export const getPostSlugs = pMemoize(async (): Promise<string[]> => {
});
// returns the parsed front matter of ALL posts, sorted reverse chronologically
export const getAllPosts = pMemoize(async (): Promise<PostFrontMatter[]> => {
export const getAllPosts = pMemoize(async (): Promise<FrontMatter[]> => {
// for each post, query its front matter
const data = await pMap(await getPostSlugs(), async (slug) => (await getPostData(slug)).frontMatter);