-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Implemented MDX component management for enhanced documentation capabilities. #22
Changes from 3 commits
08fac75
99638e3
ba4829a
acd6ee7
01b2b69
6fdf675
87ed714
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
{ | ||
"extends": ["next/core-web-vitals", "next/typescript"] | ||
"extends": ["next/core-web-vitals", "next/typescript"], | ||
"rules": { | ||
"no-restricted-imports": [ | ||
"error", | ||
{ | ||
"paths": [ | ||
{ | ||
"name": "next-contentlayer/hooks", | ||
"importNames": ["useMDXComponent"], | ||
"message": "Please use `import { MDXContent } from \"@packages/mdx-components\"`" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import type { PageProps } from '@/app/types' | ||
import { fallbackLang } from '@/features/i18n' | ||
import { findPostByLangAndSlug } from '@/features/posts' | ||
import { MDXContent } from '@packages/mdx-components' | ||
import { allPosts } from 'contentlayer/generated' | ||
import { format, parseISO } from 'date-fns' | ||
import { notFound } from 'next/navigation' | ||
|
@@ -30,14 +31,14 @@ export default function Page({ params }: PageProps) { | |
|
||
return ( | ||
<article> | ||
{/* <Callout /> */} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this debug code? |
||
<div> | ||
<time dateTime={post.date}> | ||
{format(parseISO(post.date), 'LLLL d, yyyy')} | ||
</time> | ||
<h1>{post.title}</h1> | ||
</div> | ||
{/* biome-ignore lint/security/noDangerouslySetInnerHtml: <explanation> */} | ||
<div dangerouslySetInnerHTML={{ __html: post.body.html }} /> | ||
<MDXContent code={post.body.code} /> | ||
</article> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,15 +3,18 @@ | |
"version": "0.0.1", | ||
"private": true, | ||
"scripts": { | ||
"dev": "pnpm -F \"service-site\" dev", | ||
"dev": "conc -c auto pnpm:dev:*", | ||
"dev:service-site": "pnpm -F 'service-site' dev", | ||
"dev:mdx-components": "pnpm -F 'mdx-components' dev", | ||
"lint:packageVersion": "syncpack list-mismatches", | ||
"service-site": "pnpm -F \"service-site\"", | ||
"gen:turbo": "turbo gen" | ||
}, | ||
"packageManager": "[email protected]+sha512.0a203ffaed5a3f63242cd064c8fb5892366c103e328079318f78062f24ea8c9d50bc6a47aa3567cabefd824d170e78fa2745ed1f16b132e16436146b7688f19b", | ||
"devDependencies": { | ||
"concurrently": "^9.0.1", | ||
"syncpack": "^13.0.0", | ||
"turbo": "^2.1.2", | ||
"@turbo/gen": "^2.1.2" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# build | ||
dist | ||
|
||
# typed-css-modules | ||
*.css.d.ts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "@packages/mdx-components", | ||
"version": "0.0.1", | ||
"private": true, | ||
"type": "module", | ||
"files": [ | ||
"src" | ||
], | ||
"main": "./src/index.ts", | ||
"scripts": { | ||
"dev": "conc -c auto pnpm:dev:*", | ||
"dev:css": "tcm src --watch", | ||
"lint": "conc -c auto pnpm:lint:*", | ||
"lint:biome": "biome check .", | ||
"lint:tsc": "tsc --noEmit", | ||
"fmt": "conc -c auto pnpm:fmt:*", | ||
"fmt:biome": "biome check --write --unsafe ." | ||
}, | ||
"dependencies": { | ||
"clsx": "^2.1.1", | ||
"next-contentlayer": "^0.3.4", | ||
"react": "^18", | ||
"react-dom": "^18" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "1.9.3", | ||
"@packages/configs": "workspace:*", | ||
"@types/mdx": "^2.0.13", | ||
"@types/react": "^18", | ||
"@types/react-dom": "^18", | ||
"concurrently": "^9.0.1", | ||
"typed-css-modules": "^0.9.1", | ||
"typescript": "^5" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.wrapper { | ||
width: 100%; | ||
padding: var(--spacing-4, 1rem); | ||
color: var(--s-callout-s-default-text, #bebfc1); | ||
background: var(--s-callout-s-default-background, rgba(255, 255, 255, 0.05)); | ||
} | ||
|
||
.danger { | ||
color: var(--s-callout-s-danger-text, #ea928e); | ||
background: var(--s-callout-s-danger-background, rgba(247, 80, 73, 0.1)); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import clsx from 'clsx' | ||
import type { FC, PropsWithChildren } from 'react' | ||
import styles from './Callout.module.css' | ||
|
||
type Props = { | ||
type?: 'default' | 'danger' | ||
} | ||
|
||
export const Callout: FC<PropsWithChildren<Props>> = ({ | ||
type = 'default', | ||
children, | ||
}) => { | ||
return ( | ||
<div | ||
className={clsx(styles.wrapper, { | ||
[styles.danger]: type === 'danger', | ||
})} | ||
> | ||
{children} | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Callout' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { MDXComponents } from 'mdx/types' | ||
import { useMDXComponent } from 'next-contentlayer/hooks' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MH4GF I was concerned that managing components within src/features/mdx/components would result in deep nesting and make the structure less clear due to the mixing of development code. 🤔 However, I agree with @MH4GF's point that the code being dependent on Next.js logic feels out of place. I've been considering a new idea: What if we manage these components in the same directory where we manage the articles? 👀
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @junkisai I see. Thanks for your consideration!
Looks good if it works!👍🏻 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @MH4GF refactor: Integrate MDX components into service-site and remove separ… |
||
import type { FC } from 'react' | ||
import { Callout } from './Callout' | ||
|
||
const mdxComponents: MDXComponents = { | ||
Callout: (props) => <Callout {...props} />, | ||
} | ||
|
||
type Props = { | ||
code: string | ||
} | ||
|
||
export const MDXContent: FC<Props> = ({ code }) => { | ||
const Content = useMDXComponent(code) | ||
|
||
return <Content components={mdxComponents} /> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './MDXContent' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "bundler", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"incremental": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"@/*": ["./src/*"] | ||
} | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules"] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is easy to understand for me 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Gyu07 This is how we plan to write it.