diff --git a/app/posts/layout.tsx b/app/posts/layout.tsx index 9b6ee10..1964c17 100644 --- a/app/posts/layout.tsx +++ b/app/posts/layout.tsx @@ -1,14 +1,17 @@ import { Metadata } from "next"; +import { Inter } from "next/font/google"; export const metadata: Metadata = { title: "Posts", description: "All Blog Posts by Sachchit Kunichetty", }; +const inter = Inter({ subsets: ["latin"] }); + interface LayoutProps { children: React.ReactNode; } export default function PostLayout({ children }: LayoutProps) { - return
{children}
; + return
{children}
; } diff --git a/app/posts/page.tsx b/app/posts/page.tsx index b9bd57c..91d9f60 100644 --- a/app/posts/page.tsx +++ b/app/posts/page.tsx @@ -1,4 +1,4 @@ -import { readFile, readdir, lstat } from "fs/promises"; +import { readFile, readdir } from "fs/promises"; import path from "path"; import Link from "next/link"; import { dateComparator } from "@/app/utils"; @@ -10,20 +10,25 @@ interface RawPostMetadata { date: string; editDate?: string; author: string; - slug: string; keywords: string[]; description: string; + slug: string; } async function getPosts() { const entries = await readdir("app/posts", { withFileTypes: true }); const folders = entries .filter((entry) => entry.isDirectory()) - .map((entry) => path.join(entry.parentPath, entry.name)); + .map((entry) => { + return { + fullpath: path.join(entry.parentPath, entry.name), + slug: entry.name + }; + }); const raw_metadata: RawPostMetadata[] = await Promise.all( - folders.map(async (folder) => { - const filename = `${folder}/page.mdx`; + folders.map(async ({fullpath, slug}) => { + const filename = `${fullpath}/page.mdx`; const main = await readFile(filename); const content = main.toString().split("\n"); @@ -34,7 +39,10 @@ async function getPosts() { while (index < content.length && content[index] != "---") { ++index; } - return parse(content.slice(1, index).join("\n")); + return { + slug, + ...parse(content.slice(1, index).join("\n")) + }; } }) ); diff --git a/components/post.tsx b/components/post.tsx index 70c9f7e..4ff85b1 100644 --- a/components/post.tsx +++ b/components/post.tsx @@ -1,6 +1,7 @@ "use client"; import katex from "katex"; -import { MutableRefObject, useEffect, useRef } from "react"; +import { useEffect, useRef } from "react"; +import Image, {StaticImageData} from "next/image"; export interface PostMetadata { title: string; @@ -31,10 +32,16 @@ interface BlockEquationProps { latex: string; } +interface ImageWithCaptionProps { + src: string | StaticImageData; + alt: string; + caption: string; +} + export function PostHeader({ title, date }: PostHeaderProps) { return (
-

{title}

+

{title}

{date.toLocaleDateString()}

@@ -44,8 +51,8 @@ export function PostHeader({ title, date }: PostHeaderProps) { export function Callout({ emoji, children }: CalloutProps) { return ( -
-

{emoji}

+
+

{emoji}

{children}
); @@ -53,13 +60,22 @@ export function Callout({ emoji, children }: CalloutProps) { export function Example({ children }: ExampleProps) { return ( -
+

Example:

{children}
); } +export function Definition({ children }: ExampleProps) { + return ( +
+

Definition:

+ {children} +
+ ); +} + export function BlockEquation({ latex }: BlockEquationProps) { const body = useRef(null); @@ -72,3 +88,14 @@ export function BlockEquation({ latex }: BlockEquationProps) { }); return
; } + +export function ImageWithCaption({ src, alt, caption }: ImageWithCaptionProps){ + return ( +
+
+ {alt} +

{caption}

+
+
+ ); +} diff --git a/mdx-components.tsx b/mdx-components.tsx index 1e27a5b..d81c88f 100644 --- a/mdx-components.tsx +++ b/mdx-components.tsx @@ -13,8 +13,9 @@ export function useMDXComponents(components: MDXComponents): MDXComponents { h4: ({ children }) => (

{children}

), - ul: ({ children }) =>
    {children}
, - ol: ({ children }) =>
    {children}
, + ul: ({ children }) =>
    {children}
, + ol: ({ children }) =>
    {children}
, + li: ({ children }) =>
  • {children}
  • , em: ({ children }) => {children}, p: ({ children }) => (

    {children}