2023-10-23 23:11:59 +02:00
|
|
|
import { faLink } from "@fortawesome/free-solid-svg-icons"
|
2024-05-23 22:30:13 +02:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
|
2023-10-23 23:11:59 +02:00
|
|
|
import { nodeTypes } from "@mdx-js/mdx"
|
2024-05-23 22:30:13 +02:00
|
|
|
import rehypeShikiFromHighlighter from "@shikijs/rehype/core"
|
|
|
|
import { MDXRemote } from "next-mdx-remote/rsc"
|
|
|
|
import { cookies } from "next/headers"
|
|
|
|
import Image from "next/image"
|
|
|
|
import Link from "next/link"
|
|
|
|
import rehypeKatex from "rehype-katex"
|
2023-10-23 23:11:59 +02:00
|
|
|
import rehypeRaw from "rehype-raw"
|
|
|
|
import rehypeSlug from "rehype-slug"
|
2024-05-23 22:30:13 +02:00
|
|
|
import remarkGfm from "remark-gfm"
|
2023-10-23 23:11:59 +02:00
|
|
|
import remarkMath from "remark-math"
|
2024-05-23 22:30:13 +02:00
|
|
|
import { getHighlighterCore } from "shiki/core"
|
2023-08-01 18:59:45 +02:00
|
|
|
|
2023-10-23 23:11:59 +02:00
|
|
|
import "katex/dist/katex.min.css"
|
2023-08-01 18:59:45 +02:00
|
|
|
|
2023-10-23 23:11:59 +02:00
|
|
|
import { BlogPostComments } from "@/blog/BlogPostComments"
|
2024-05-23 22:30:13 +02:00
|
|
|
import { getTheme } from "@/theme/theme.server"
|
2023-08-01 18:59:45 +02:00
|
|
|
|
|
|
|
const Heading = (
|
|
|
|
props: React.DetailedHTMLProps<
|
|
|
|
React.HTMLAttributes<HTMLHeadingElement>,
|
|
|
|
HTMLHeadingElement
|
2023-10-23 23:11:59 +02:00
|
|
|
>,
|
2023-08-01 18:59:45 +02:00
|
|
|
): JSX.Element => {
|
2023-10-23 23:11:59 +02:00
|
|
|
const { children, id = "" } = props
|
2023-08-01 18:59:45 +02:00
|
|
|
return (
|
2024-05-21 19:06:12 +02:00
|
|
|
<h2 {...props}>
|
|
|
|
<Link href={`#${id}`} className="group relative hover:no-underline">
|
|
|
|
<FontAwesomeIcon
|
|
|
|
className="absolute bottom-2 left-[-26px] mr-2 hidden size-4 !text-black group-hover:inline dark:!text-white"
|
|
|
|
icon={faLink}
|
|
|
|
/>
|
|
|
|
{children}
|
2023-08-01 18:59:45 +02:00
|
|
|
</Link>
|
|
|
|
</h2>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface BlogPostContentProps {
|
|
|
|
content: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export const BlogPostContent = async (
|
2023-10-23 23:11:59 +02:00
|
|
|
props: BlogPostContentProps,
|
2023-08-01 18:59:45 +02:00
|
|
|
): Promise<JSX.Element> => {
|
|
|
|
const { content } = props
|
|
|
|
|
|
|
|
const cookiesStore = cookies()
|
|
|
|
const theme = getTheme()
|
|
|
|
|
2024-05-23 22:30:13 +02:00
|
|
|
const highlighter = await getHighlighterCore({
|
|
|
|
themes: [
|
|
|
|
import("shiki/themes/light-plus.mjs"),
|
|
|
|
import("shiki/themes/dark-plus.mjs"),
|
|
|
|
],
|
|
|
|
langs: [
|
|
|
|
import("shiki/langs/markdown.mjs"),
|
|
|
|
import("shiki/langs/shell.mjs"),
|
|
|
|
import("shiki/langs/javascript.mjs"),
|
|
|
|
import("shiki/langs/typescript.mjs"),
|
|
|
|
import("shiki/langs/python.mjs"),
|
|
|
|
],
|
|
|
|
loadWasm: import("shiki/wasm"),
|
2023-08-01 18:59:45 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
2023-10-23 23:11:59 +02:00
|
|
|
<div className="prose mb-10">
|
|
|
|
<div className="px-8">
|
2023-08-01 18:59:45 +02:00
|
|
|
<MDXRemote
|
|
|
|
source={content}
|
|
|
|
options={{
|
|
|
|
mdxOptions: {
|
2024-05-23 22:30:13 +02:00
|
|
|
remarkPlugins: [remarkGfm, remarkMath],
|
2023-08-01 18:59:45 +02:00
|
|
|
rehypePlugins: [
|
|
|
|
rehypeSlug,
|
|
|
|
[rehypeRaw, { passThrough: nodeTypes }],
|
2023-10-23 23:11:59 +02:00
|
|
|
rehypeKatex,
|
2024-05-23 22:30:13 +02:00
|
|
|
[
|
|
|
|
rehypeShikiFromHighlighter,
|
|
|
|
highlighter,
|
|
|
|
{
|
|
|
|
theme: `${theme}-plus`,
|
|
|
|
},
|
|
|
|
],
|
2023-10-23 23:11:59 +02:00
|
|
|
],
|
|
|
|
},
|
2023-08-01 18:59:45 +02:00
|
|
|
}}
|
|
|
|
components={{
|
|
|
|
h1: Heading,
|
|
|
|
h2: Heading,
|
|
|
|
h3: Heading,
|
|
|
|
h4: Heading,
|
|
|
|
h5: Heading,
|
|
|
|
h6: Heading,
|
|
|
|
img: (properties) => {
|
2023-10-23 23:11:59 +02:00
|
|
|
const { src = "", alt = "Blog Image" } = properties
|
|
|
|
const source = src.replace("../../public/", "/")
|
2023-08-01 18:59:45 +02:00
|
|
|
return (
|
2023-10-23 23:11:59 +02:00
|
|
|
<span className="flex flex-col items-center justify-center">
|
2023-08-01 18:59:45 +02:00
|
|
|
<Image
|
|
|
|
src={source}
|
|
|
|
alt={alt}
|
|
|
|
width={1000}
|
|
|
|
height={1000}
|
2024-01-28 03:21:11 +01:00
|
|
|
className="size-auto"
|
2023-08-01 18:59:45 +02:00
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
a: (props) => {
|
2024-01-23 22:29:21 +01:00
|
|
|
const { href = "", ...rest } = props
|
2023-10-23 23:11:59 +02:00
|
|
|
if (href.startsWith("#")) {
|
2023-08-01 18:59:45 +02:00
|
|
|
return <a {...props} />
|
|
|
|
}
|
2024-01-23 22:29:21 +01:00
|
|
|
if (href.startsWith("../posts/")) {
|
|
|
|
return (
|
|
|
|
<a
|
|
|
|
href={href
|
|
|
|
.replace("../posts/", "/blog/")
|
|
|
|
.replace(".md", "")}
|
|
|
|
{...rest}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2023-10-23 23:11:59 +02:00
|
|
|
return <a target="_blank" rel="noopener noreferrer" {...props} />
|
|
|
|
},
|
2023-08-01 18:59:45 +02:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<BlogPostComments cookiesStore={cookiesStore.toString()} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|