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

pass mdx images through next/image for full optimization benefits

This commit is contained in:
2022-01-09 22:53:10 -05:00
parent 32d1683e51
commit 6436a34c59
34 changed files with 256 additions and 180 deletions

View File

@@ -6,7 +6,8 @@ import { escape } from "html-escaper";
import { getMDXComponent } from "mdx-bundler/client";
import Content from "../../components/Content";
import Meta from "../../components/notes/Meta";
import mdxComponents from "../../components/mdxComponents";
import CustomLink from "../../components/embeds/Link";
import CustomCode from "../../components/embeds/Code";
import { getNote, getNoteSlugs } from "../../lib/parse-notes";
import * as config from "../../lib/config";
import type { GetStaticProps, GetStaticPaths } from "next";
@@ -14,6 +15,11 @@ import type { GetStaticProps, GetStaticPaths } from "next";
const Comments = dynamic(() => import("../../components/notes/Comments"), { ssr: false });
const Note = ({ frontMatter, mdxSource }) => {
const customComponents = {
a: CustomLink,
code: CustomCode,
};
const MDXComponent = useMemo(() => getMDXComponent(mdxSource, { process }), [mdxSource]);
return (
@@ -67,7 +73,7 @@ const Note = ({ frontMatter, mdxSource }) => {
<Meta {...frontMatter} />
<Content>
{/* @ts-ignore */}
<MDXComponent components={mdxComponents} />
<MDXComponent components={customComponents} />
</Content>
{frontMatter.noComments !== true && <Comments slug={frontMatter.slug} />}
</>