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:
@@ -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;
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user