mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-03 13:46:38 -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();
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { SitemapStream, EnumChangefreq } from "sitemap";
|
||||
import { getAllNotes } from "../lib/helpers/parse-notes";
|
||||
import { getAllPosts } from "../lib/helpers/posts";
|
||||
import { siteDomain } from "../lib/config";
|
||||
import type { GetServerSideProps } from "next";
|
||||
import type { SitemapItemLoose } from "sitemap";
|
||||
@ -39,20 +39,20 @@ export const getServerSideProps: GetServerSideProps<Record<string, never>> = asy
|
||||
{ url: "/zip/" },
|
||||
];
|
||||
|
||||
// push notes separately and use their metadata
|
||||
const notes = await getAllNotes();
|
||||
notes.forEach((note) => {
|
||||
// push posts separately and use their metadata
|
||||
const posts = await getAllPosts();
|
||||
posts.forEach((post) => {
|
||||
pages.push({
|
||||
url: `/notes/${note.slug}/`,
|
||||
url: `/notes/${post.slug}/`,
|
||||
// pull lastMod from front matter date
|
||||
lastmod: note.date,
|
||||
lastmod: post.date,
|
||||
});
|
||||
});
|
||||
|
||||
// set lastmod of /notes/ page to most recent post's date
|
||||
pages.push({
|
||||
url: `/notes/`,
|
||||
lastmod: notes[0].date,
|
||||
lastmod: posts[0].date,
|
||||
});
|
||||
|
||||
// sort alphabetically by URL
|
||||
|
Reference in New Issue
Block a user