Skip to content
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

Merged
merged 7 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion frontend/apps/service-site/.eslintrc.json
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\"`"
}
]
}
]
}
}
3 changes: 2 additions & 1 deletion frontend/apps/service-site/contentlayer.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { defineDocumentType, makeSource } from 'contentlayer/source-files'

export const Post = defineDocumentType(() => ({
name: 'Post',
filePathPattern: 'posts/*/*.md',
filePathPattern: 'posts/*/*.mdx',
contentType: 'mdx',
fields: {
title: { type: 'string', required: true },
date: { type: 'date', required: true },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: '5 Best Practices for Successful No-Code App Development'
title: "5 Best Practices for Successful No-Code App Development"
date: 2024-09-26
tags:
- Vision
Expand Down Expand Up @@ -32,3 +32,15 @@ A no-code platform provides a user-friendly interface where developers, or even
As the capabilities of no-code platforms continue to expand, more complex applications can be built without needing to write a single line of code. AI integration and automation are the next frontiers in no-code development, offering even more opportunities for innovation.

The no-code movement is democratizing the app development process, empowering more people to participate in creating the future of software. As these platforms evolve, they will continue to blur the line between developer and non-developer, making app development accessible to everyone.

<Callout>
No-code platforms are breaking down the barriers to innovation, allowing
anyone with an idea to bring it to life without needing to write a single line
of code.
</Callout>

<Callout type="danger">
No-code platforms are breaking down the barriers to innovation, allowing
anyone with an idea to bring it to life without needing to write a single line
of code.
</Callout>
Copy link
Member

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 😄

Copy link
Member

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.

1 change: 1 addition & 0 deletions frontend/apps/service-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"devDependencies": {
"@biomejs/biome": "1.9.3",
"@packages/configs": "workspace:*",
"@packages/mdx-components": "workspace:*",
"@storybook/nextjs": "^8.3.4",
"@storybook/react": "^8.3.4",
"@types/node": "^20",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { PageProps } from '@/app/types'
import { langSchema, langs } 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'
Expand Down Expand Up @@ -40,8 +41,7 @@ export default function Page({ params }: PageProps) {
</time>
<h1>{post.title}</h1>
</div>
{/* biome-ignore lint/security/noDangerouslySetInnerHtml: <explanation> */}
<div dangerouslySetInnerHTML={{ __html: post.body.html }} />
<MDXContent code={post.body.code} />
</article>
)
}
4 changes: 2 additions & 2 deletions frontend/apps/service-site/src/app/[lang]/posts/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { PageProps } from '@/app/types'
import { getTranslation, langSchema, langs } from '@/features/i18n'
import { filterPostsByLang } from '@/features/posts'
import { MDXContent } from '@packages/mdx-components'
import type { Post } from 'contentlayer/generated'
import { compareDesc, format, parseISO } from 'date-fns'
import Link from 'next/link'
Expand All @@ -15,8 +16,7 @@ function PostCard(post: Post) {
<time dateTime={post.date}>
{format(parseISO(post.date), 'LLLL d, yyyy')}
</time>
{/* biome-ignore lint/security/noDangerouslySetInnerHtml: No problem, as it is only via Markdown written by in-house members. */}
<div dangerouslySetInnerHTML={{ __html: post.body.html }} />
<MDXContent code={post.body.code} />
</div>
)
}
Expand Down
5 changes: 3 additions & 2 deletions frontend/apps/service-site/src/app/posts/[slug]/page.tsx
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'
Expand Down Expand Up @@ -30,14 +31,14 @@ export default function Page({ params }: PageProps) {

return (
<article>
{/* <Callout /> */}
Copy link
Member

Choose a reason for hiding this comment

The 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>
)
}
4 changes: 2 additions & 2 deletions frontend/apps/service-site/src/app/posts/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { fallbackLang, getTranslation } from '@/features/i18n'
import { filterPostsByLang } from '@/features/posts'
import { MDXContent } from '@packages/mdx-components'
import type { Post } from 'contentlayer/generated'
import { compareDesc, format, parseISO } from 'date-fns'
import Link from 'next/link'
Expand All @@ -13,8 +14,7 @@ function PostCard(post: Post) {
<time dateTime={post.date}>
{format(parseISO(post.date), 'LLLL d, yyyy')}
</time>
{/* biome-ignore lint/security/noDangerouslySetInnerHtml: No problem, as it is only via Markdown written by in-house members. */}
<div dangerouslySetInnerHTML={{ __html: post.body.html }} />
<MDXContent code={post.body.code} />
</div>
)
}
Expand Down
7 changes: 5 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
5 changes: 5 additions & 0 deletions frontend/packages/mdx-components/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# build
dist

# typed-css-modules
*.css.d.ts
35 changes: 35 additions & 0 deletions frontend/packages/mdx-components/package.json
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"
}
}
11 changes: 11 additions & 0 deletions frontend/packages/mdx-components/src/Callout/Callout.module.css
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));
}
22 changes: 22 additions & 0 deletions frontend/packages/mdx-components/src/Callout/Callout.tsx
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>
)
}
1 change: 1 addition & 0 deletions frontend/packages/mdx-components/src/Callout/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Callout'
18 changes: 18 additions & 0 deletions frontend/packages/mdx-components/src/MDXContent.tsx
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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm...
If it depends on the logic of next, this @packages/mdx-components is not a pure React component, and the benefit of splitting the package.
service-site/features/mdx looks good to me, but what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MH4GF
I struggled with how to handle this part. The reason I wanted to split it into a package was to clearly define which components article writers can use within MDX files.

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? 👀

/
└─ src
   └─ contents
      ├─ posts
      │  └─ 1/en.mdx
      └─ components
         └─ Callout

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@junkisai I see. Thanks for your consideration!

What if we manage these components in the same directory where we manage the articles? 👀

Looks good if it works!👍🏻

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MH4GF
I've implemented the change to manage the components in the same directory as the articles!

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} />
}
1 change: 1 addition & 0 deletions frontend/packages/mdx-components/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './MDXContent'
22 changes: 22 additions & 0 deletions frontend/packages/mdx-components/tsconfig.json
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"]
}
Loading