diff --git a/apps/techlabblog/app/[slug]/page.tsx b/apps/techlabblog/app/[slug]/page.tsx index d4ded021f..178263844 100644 --- a/apps/techlabblog/app/[slug]/page.tsx +++ b/apps/techlabblog/app/[slug]/page.tsx @@ -1,11 +1,12 @@ import { Section } from "@commons-ui/core"; -import { getPost } from "@/techlabblog/lib/data"; import PostHeader from "@/techlabblog/components/PostHeader"; +import { getPost } from "@/techlabblog/lib/data"; export default async function Page({ params }: { params: { slug: string } }) { const postModule = await getPost(params.slug); - if (!postModule) { + + if (!(postModule && postModule.frontmatter)) { // TODO(kilemensi): 404 return null; } @@ -17,7 +18,7 @@ export default async function Page({ params }: { params: { slug: string } }) { py: { xs: 2.5, sm: 5 }, }} > - {frontmatter ? : null} + ); diff --git a/apps/techlabblog/app/layout.tsx b/apps/techlabblog/app/layout.tsx index 3af4b51ad..50e410031 100644 --- a/apps/techlabblog/app/layout.tsx +++ b/apps/techlabblog/app/layout.tsx @@ -20,9 +20,14 @@ export default async function RootLayout({ }: Readonly<{ children: React.ReactNode; }>) { + const settings = await getSettings(); + if (!settings) { + // TODO(kilemensi): log to sentry + return null; + } const { analytics, connect, primaryNavigation, secondaryNavigation } = - await getSettings(); - // TODO: blurWidth/blurHeight https://github.com/vercel/next.js/issues/56511 + settings; + // TODO(kilemensi): blurWidth/blurHeight https://github.com/vercel/next.js/issues/56511 const { blurWidth, blurHeight, ...logoProps } = logoLight; const logo = { ...logoProps, diff --git a/apps/techlabblog/components/PostHeader/PostSxProps.tsx b/apps/techlabblog/components/Post/PostProps.tsx similarity index 67% rename from apps/techlabblog/components/PostHeader/PostSxProps.tsx rename to apps/techlabblog/components/Post/PostProps.tsx index 0750143fb..a5fb04220 100644 --- a/apps/techlabblog/components/PostHeader/PostSxProps.tsx +++ b/apps/techlabblog/components/Post/PostProps.tsx @@ -2,8 +2,8 @@ import type { SxProps, Theme } from "@mui/material/styles"; import { Post } from "@/techlabblog/lib/data"; -interface PostSxProps extends Post { +interface PostProps extends Post { sx?: SxProps; } -export type { PostSxProps }; +export type { PostProps }; diff --git a/apps/techlabblog/components/Post/index.ts b/apps/techlabblog/components/Post/index.ts new file mode 100644 index 000000000..dc1111e33 --- /dev/null +++ b/apps/techlabblog/components/Post/index.ts @@ -0,0 +1,3 @@ +import type { PostProps } from "./PostProps"; + +export type { PostProps }; diff --git a/apps/techlabblog/components/PostHeader/PostHeader.tsx b/apps/techlabblog/components/PostHeader/PostHeader.tsx index 61378d2c8..08786e3ec 100644 --- a/apps/techlabblog/components/PostHeader/PostHeader.tsx +++ b/apps/techlabblog/components/PostHeader/PostHeader.tsx @@ -1,10 +1,10 @@ import { Box, Typography } from "@mui/material"; import React from "react"; -import type { PostSxProps } from "./PostSxProps"; +import type { PostProps } from "@/techlabblog/components/Post"; const PostHeader = React.forwardRef(function ArticleHeader( - props: PostSxProps, + props: PostProps, ref: React.Ref, ) { const { publishedDate, excerpt, sx, title } = props; diff --git a/apps/techlabblog/components/PostHeader/index.ts b/apps/techlabblog/components/PostHeader/index.ts index c2dbd1f5d..27339ff89 100644 --- a/apps/techlabblog/components/PostHeader/index.ts +++ b/apps/techlabblog/components/PostHeader/index.ts @@ -1,5 +1,3 @@ import PostHeader from "./PostHeader"; -import type { PostSxProps } from "./PostSxProps"; -export type { PostSxProps as PostProps }; export default PostHeader; diff --git a/apps/techlabblog/components/PostList/PostCard.tsx b/apps/techlabblog/components/PostList/PostCard.tsx index 7a8a47d2b..916aa4f96 100644 --- a/apps/techlabblog/components/PostList/PostCard.tsx +++ b/apps/techlabblog/components/PostList/PostCard.tsx @@ -8,17 +8,12 @@ import { CardMedia, Typography, } from "@mui/material"; -import type { SxProps, Theme } from "@mui/material/styles"; import React from "react"; -import { PostFrontMatterProps } from "@/techlabblog/lib/data"; - -interface PostCardProps extends PostFrontMatterProps { - sx?: SxProps; -} +import type { PostProps } from "@/techlabblog/components/Post"; const PostCard = React.forwardRef(function ArticleCard( - props: PostCardProps, + props: PostProps, ref: React.Ref, ) { const { title, publishedDate, featuredImage, slug, sx } = props; @@ -65,5 +60,4 @@ const PostCard = React.forwardRef(function ArticleCard( ); }); -export type { PostCardProps }; export default PostCard; diff --git a/apps/techlabblog/components/PostList/PostList.tsx b/apps/techlabblog/components/PostList/PostList.tsx index 2bede715a..d5f6c9493 100644 --- a/apps/techlabblog/components/PostList/PostList.tsx +++ b/apps/techlabblog/components/PostList/PostList.tsx @@ -2,11 +2,12 @@ import { Grid } from "@mui/material"; import type { SxProps, Theme } from "@mui/material/styles"; import React from "react"; -import type { PostCardProps } from "./PostCard"; +import type { PostProps } from "@/techlabblog/components/Post"; + import PostCard from "./PostCard"; interface PostListProps { - posts?: PostCardProps[]; + posts?: PostProps[]; sx?: SxProps; } @@ -36,4 +37,5 @@ const PostList = React.forwardRef(function PostList( ); }); +export type { PostListProps }; export default PostList; diff --git a/apps/techlabblog/components/PostList/index.ts b/apps/techlabblog/components/PostList/index.ts index 33aff0f29..e219434ab 100644 --- a/apps/techlabblog/components/PostList/index.ts +++ b/apps/techlabblog/components/PostList/index.ts @@ -1,5 +1,5 @@ -import type { PostCardProps } from "./PostCard"; +import type { PostListProps } from "./PostList"; import PostList from "./PostList"; -export type { PostCardProps }; +export type { PostListProps }; export default PostList; diff --git a/apps/techlabblog/lib/data/index.ts b/apps/techlabblog/lib/data/index.ts index e2862341e..cd1ae4c39 100644 --- a/apps/techlabblog/lib/data/index.ts +++ b/apps/techlabblog/lib/data/index.ts @@ -1,6 +1,6 @@ import { compile, run } from "@mdx-js/mdx"; -import { promises as fs } from "fs"; import type { PathLike } from "fs"; +import { promises as fs } from "fs"; import type { MDXModule } from "mdx/types"; import path from "path"; import * as runtime from "react/jsx-runtime"; @@ -42,9 +42,11 @@ async function readMdFile( const vfile = await compile(fileContent, { outputFormat: "function-body", providerImportSource: "../../mdx-components.tsx", + // @ts-ignore https://mdxjs.com/packages/mdx/#processoroptions rehypePlugins, remarkPlugins, }); + // @ts-ignore https://mdxjs.com/packages/mdx/#examples-1 return run(vfile, { ...runtime, useMDXComponents }); } diff --git a/apps/techlabblog/mdx-components.tsx b/apps/techlabblog/mdx-components.tsx index e338c9a96..303dce565 100644 --- a/apps/techlabblog/mdx-components.tsx +++ b/apps/techlabblog/mdx-components.tsx @@ -1,12 +1,15 @@ +import type { LinkProps, TypographyProps } from "@mui/material"; +// TODO(kilemensi): Switch to @cui/next/Link import { Link, Typography } from "@mui/material"; -import type { Variant } from "@mui/material/styles/createTypography"; import type { MDXComponents } from "mdx/types"; -function createHeading(variant: Variant): HTMLHeadingElement { - return ({ children, ...others }) => ( +type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6; + +function createHeading(level: HeadingLevel) { + const Heading = ({ children, ...others }: TypographyProps) => ( a": { @@ -15,7 +18,6 @@ function createHeading(variant: Variant): HTMLHeadingElement { "& .icon.icon-link": { display: "none", paddingLeft: 1, - // position: "relative" }, "&:hover": { "& .icon.icon-link": { @@ -23,7 +25,6 @@ function createHeading(variant: Variant): HTMLHeadingElement { }, }, "& .icon.icon-link:before": { - // position: "absolute", content: '"#"', }, }} @@ -31,26 +32,33 @@ function createHeading(variant: Variant): HTMLHeadingElement { {children} ); + Heading.displayName = `Heading${level}`; + + return Heading; } -export function useMDXComponents(components?: MDXComponents): MDXComponents { +const customComponents = { + h1: createHeading(1), + h2: createHeading(2), + h3: createHeading(3), + h4: createHeading(4), + h5: createHeading(5), + h6: createHeading(6), + p: ({ children, ...others }: TypographyProps) => ( + + {children} + + ), + a: ({ children, ...others }: LinkProps) => ( + + {children} + + ), +}; + +export function useMDXComponents(components?: MDXComponents) { return { - h1: createHeading("h1"), - h2: createHeading("h2"), - h3: createHeading("h3"), - h4: createHeading("h4"), - h5: createHeading("h5"), - h6: createHeading("h6"), - p: ({ children, ...others }) => ( - - {children} - - ), - a: ({ children, ...others }) => ( - - {children} - - ), + ...customComponents, ...components, }; }