mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-10-26 01:05:49 -04:00
refactor "notes" into "posts" (only on the backend)
This commit is contained in:
@@ -2,16 +2,15 @@ import { InView } from "react-intersection-observer";
|
||||
import { NextSeo, ArticleJsonLd } from "next-seo";
|
||||
import { MDXRemote, MDXRemoteProps } from "next-mdx-remote";
|
||||
import Content from "../../components/Content";
|
||||
import NoteMeta from "../../components/NoteMeta";
|
||||
import PostMeta from "../../components/PostMeta";
|
||||
import Comments from "../../components/Comments";
|
||||
import * as mdxComponents from "../../lib/helpers/mdx-components";
|
||||
import { getNoteSlugs } from "../../lib/helpers/parse-notes";
|
||||
import { compileNote } from "../../lib/helpers/compile-note";
|
||||
import { getPostSlugs, compilePost } from "../../lib/helpers/posts";
|
||||
import * as config from "../../lib/config";
|
||||
import { articleJsonLd } from "../../lib/config/seo";
|
||||
import { meJpg } from "../../lib/config/favicons";
|
||||
import type { GetStaticProps, GetStaticPaths, InferGetStaticPropsType } from "next";
|
||||
import type { NoteWithSource, NoteFrontMatter } from "../../types";
|
||||
import type { PostWithSource, PostFrontMatter } from "../../types";
|
||||
|
||||
const Note = ({ frontMatter, source }: InferGetStaticPropsType<typeof getStaticProps>) => {
|
||||
return (
|
||||
@@ -51,7 +50,7 @@ const Note = ({ frontMatter, source }: InferGetStaticPropsType<typeof getStaticP
|
||||
{...articleJsonLd}
|
||||
/>
|
||||
|
||||
<NoteMeta {...frontMatter} />
|
||||
<PostMeta {...frontMatter} />
|
||||
|
||||
<Content>
|
||||
<MDXRemote {...source} components={{ ...(mdxComponents as MDXRemoteProps["components"]) }} />
|
||||
@@ -70,14 +69,14 @@ const Note = ({ frontMatter, source }: InferGetStaticPropsType<typeof getStaticP
|
||||
);
|
||||
};
|
||||
|
||||
export const getStaticProps: GetStaticProps<NoteWithSource, Pick<NoteFrontMatter, "slug">> = async ({ params }) => {
|
||||
export const getStaticProps: GetStaticProps<PostWithSource, Pick<PostFrontMatter, "slug">> = async ({ params }) => {
|
||||
if (!params?.slug) {
|
||||
return {
|
||||
notFound: true,
|
||||
};
|
||||
}
|
||||
|
||||
const { frontMatter, source } = await compileNote(params.slug);
|
||||
const { frontMatter, source } = await compilePost(params.slug);
|
||||
|
||||
return {
|
||||
props: {
|
||||
@@ -88,7 +87,10 @@ export const getStaticProps: GetStaticProps<NoteWithSource, Pick<NoteFrontMatter
|
||||
};
|
||||
|
||||
export const getStaticPaths: GetStaticPaths = async () => {
|
||||
const slugs = await getNoteSlugs();
|
||||
// get the slug of each .mdx file in /notes
|
||||
const slugs = await getPostSlugs();
|
||||
|
||||
// map slugs into a static paths object required by next.js
|
||||
const paths = slugs.map((slug) => ({ params: { slug } }));
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { NextSeo } from "next-seo";
|
||||
import Content from "../../components/Content";
|
||||
import NotesList from "../../components/NotesList";
|
||||
import { getAllNotes } from "../../lib/helpers/parse-notes";
|
||||
import PostsList from "../../components/PostsList";
|
||||
import { getAllPosts } from "../../lib/helpers/posts";
|
||||
import { authorName } from "../../lib/config";
|
||||
import type { GetStaticProps, InferGetStaticPropsType } from "next";
|
||||
import type { NotesByYear } from "../../types";
|
||||
import type { PostsByYear } from "../../types";
|
||||
|
||||
const Notes = ({ notesByYear }: InferGetStaticPropsType<typeof getStaticProps>) => {
|
||||
return (
|
||||
@@ -18,18 +18,18 @@ const Notes = ({ notesByYear }: InferGetStaticPropsType<typeof getStaticProps>)
|
||||
/>
|
||||
|
||||
<Content>
|
||||
<NotesList notesByYear={notesByYear} />
|
||||
<PostsList postsByYear={notesByYear} />
|
||||
</Content>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const getStaticProps: GetStaticProps<{
|
||||
notesByYear: NotesByYear;
|
||||
notesByYear: PostsByYear;
|
||||
}> = async () => {
|
||||
// parse the year of each note and group them together
|
||||
const notes = await getAllNotes();
|
||||
const notesByYear: NotesByYear = {};
|
||||
const notes = await getAllPosts();
|
||||
const notesByYear: PostsByYear = {};
|
||||
|
||||
notes.forEach((note) => {
|
||||
const year = new Date(note.date).getUTCFullYear();
|
||||
|
||||
Reference in New Issue
Block a user