diff --git a/components/mdxComponents.tsx b/components/mdxComponents.tsx index 1fd2aaaa..08376fd9 100644 --- a/components/mdxComponents.tsx +++ b/components/mdxComponents.tsx @@ -6,29 +6,17 @@ import { OctocatOcticon } from "./icons/octicons"; import type { LinkProps } from "next/link"; import type { ImageProps } from "next/image"; -import type { GistProps } from "react-gist"; -import type { ReactPlayerProps } from "react-player"; - -const TweetEmbed = dynamic(() => import("react-tweet-embed")); -const Gist = dynamic(() => import("react-gist")); -const Video = dynamic(() => import("./video/FullPageVideo")); -const CopyButton = dynamic(() => import("./clipboard/CopyButton")); // The following components are all passed into as replacement HTML tags or drop-in React components // available in .mdx files containing post content, since they're not directly aware of the components in this folder. -const CustomLink = ({ - href, - target, - rel, - className, - children, -}: LinkProps & { +type CustomLinkProps = LinkProps & { target?: string; rel?: string; className?: string; children?: unknown; -}) => ( +}; +const CustomLink = ({ href, target, rel, className, children }: CustomLinkProps) => ( {children} @@ -36,18 +24,19 @@ const CustomLink = ({ ); -const CustomImg = (props: ImageProps) => { - return ( - // height and width are part of the props, so they get automatically passed here with {...props} -
- {/* eslint-disable-next-line jsx-a11y/alt-text */} - -
- ); -}; +const CustomImg = (props: ImageProps) => ( + // the required height and width are part of the props, so they get automatically passed here with {...props} +
+ {/* eslint-disable-next-line jsx-a11y/alt-text */} + +
+); const CustomCode = (props: any) => { if (props.className?.split(" ").includes("hljs")) { + const CopyButton = dynamic(() => import("./clipboard/CopyButton")); + + // full multi-line code blocks with highlight.js and copy-to-clipboard button return (
@@ -63,23 +52,28 @@ const CustomCode = (props: any) => {
); } else { + // inline code in paragraphs, headings, etc. (not highlighted) return {props.children}; } }; -const CustomVideo = (props: ReactPlayerProps) =>
@@ -97,6 +91,7 @@ const CustomGitHubLink = (props: { repo: string }) => ( ); +// These are the actual tags referenced in mdx files: const mdxComponents = { a: CustomLink, img: CustomImg, diff --git a/components/video/FullPageVideo.module.scss b/components/video/Video.module.scss similarity index 100% rename from components/video/FullPageVideo.module.scss rename to components/video/Video.module.scss diff --git a/components/video/FullPageVideo.tsx b/components/video/Video.tsx similarity index 68% rename from components/video/FullPageVideo.tsx rename to components/video/Video.tsx index eb7bb718..a4a8aaeb 100644 --- a/components/video/FullPageVideo.tsx +++ b/components/video/Video.tsx @@ -1,14 +1,14 @@ import dynamic from "next/dynamic"; import type { ReactPlayerProps } from "react-player"; -import styles from "./FullPageVideo.module.scss"; +import styles from "./Video.module.scss"; const ReactPlayer = dynamic(() => import("react-player")); -const FullPageVideo = (props: ReactPlayerProps) => ( +const Video = (props: ReactPlayerProps) => (
); -export default FullPageVideo; +export default Video; diff --git a/lib/config.js b/lib/config.js index 1d860bde..50c923d6 100644 --- a/lib/config.js +++ b/lib/config.js @@ -1,3 +1,4 @@ +// do not convert to ESM -- this needs to be imported in CJS files like next.config.js too module.exports = { // Site info siteName: "Jake Jarvis", diff --git a/lib/parse-notes.ts b/lib/parse-notes.ts index b7ffcb36..7fd63063 100644 --- a/lib/parse-notes.ts +++ b/lib/parse-notes.ts @@ -3,6 +3,7 @@ import path from "path"; import matter from "gray-matter"; import { NOTES_DIR, baseUrl } from "./config"; +// returns front matter and/or *raw* markdown contents of a given slug export const getNoteData = (slug: string) => { const fullPath = path.join(process.cwd(), NOTES_DIR, `${slug}.mdx`); const rawContent = fs.readFileSync(fullPath, "utf8"); @@ -19,15 +20,15 @@ export const getNoteData = (slug: string) => { }; }; -// all .mdx files in NOTES_DIR +// returns all .mdx files in NOTES_DIR (without .mdx extension) export const getNoteSlugs = () => fs .readdirSync(path.join(process.cwd(), NOTES_DIR)) .filter((file) => /\.mdx$/.test(file)) .map((noteFile) => noteFile.replace(/\.mdx$/, "")); +// returns the front matter of ALL notes, sorted reverse chronologically export const getAllNotes = () => getNoteSlugs() .map((slug) => getNoteData(slug).frontMatter) - // sort notes by date in descending order .sort((note1: any, note2: any) => (note1.date > note2.date ? -1 : 1)); diff --git a/pages/_app.tsx b/pages/_app.tsx index 16ad2d27..01690ad6 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -30,7 +30,9 @@ const App = ({ Component, pageProps }: AppProps) => { // https://usefathom.com/docs/integrations/next // https://vercel.com/guides/deploying-nextjs-using-fathom-analytics-with-vercel Fathom.load(config.fathomSiteId, { + // optional custom domain: https://usefathom.com/docs/script/custom-domains url: `${config.fathomCustomDomain || "https://cdn.usefathom.com"}/script.js`, + // don't track branch/deploy previews and localhost includedDomains: [config.siteDomain], }); @@ -38,7 +40,7 @@ const App = ({ Component, pageProps }: AppProps) => { Fathom.trackPageview(); }; - // send ping when route changes + // needs to be triggered manually on link clicks (the page doesn't actually change) router.events.on("routeChangeComplete", onRouteChangeComplete); return () => { diff --git a/pages/birthday.tsx b/pages/birthday.tsx index c5f42b25..a9e9e906 100644 --- a/pages/birthday.tsx +++ b/pages/birthday.tsx @@ -2,7 +2,7 @@ import Layout from "../components/Layout"; import Container from "../components/Container"; import Content from "../components/Content"; import PageTitle from "../components/page/PageTitle"; -import Video from "../components/video/FullPageVideo"; +import Video from "../components/video/Video"; import { TapeIcon } from "../components/icons"; import thumbnail from "../public/static/images/birthday/thumb.png"; diff --git a/pages/hillary.tsx b/pages/hillary.tsx index e947e8be..418eb3e1 100644 --- a/pages/hillary.tsx +++ b/pages/hillary.tsx @@ -2,7 +2,7 @@ import Layout from "../components/Layout"; import Container from "../components/Container"; import Content from "../components/Content"; import PageTitle from "../components/page/PageTitle"; -import Video from "../components/video/FullPageVideo"; +import Video from "../components/video/Video"; import thumbnail from "../public/static/images/hillary/thumb.png"; diff --git a/pages/leo.tsx b/pages/leo.tsx index 941a207d..94fd56e6 100644 --- a/pages/leo.tsx +++ b/pages/leo.tsx @@ -2,7 +2,7 @@ import Layout from "../components/Layout"; import Container from "../components/Container"; import Content from "../components/Content"; import PageTitle from "../components/page/PageTitle"; -import Video from "../components/video/FullPageVideo"; +import Video from "../components/video/Video"; import thumbnail from "../public/static/images/leo/thumb.png";