nextui icon indicating copy to clipboard operation
nextui copied to clipboard

refactor: improve dx for writing a docs component

Open Innei opened this issue 1 year ago • 6 comments

Closes #

📝 Description

Add a brief description

The component DX that writes docs now is very unfriendly and difficult to maintain.

Like this. What stringfiy code??

CleanShot 2024-03-18 at 9  39 42@2x

For now, I just refactor this and improve DX. And now we can write code in single tsx file, and import it. CleanShot 2024-03-18 at 9  40 39@2x

And import it assert to raw.

import App from "./bordered-variant.raw.tsx?raw";

const react = {
  "/App.jsx": App,
};

export default {
  ...react,
};

💣 Is this a breaking change (Yes/No):

No

📝 Additional Information

Summary by CodeRabbit

  • New Features
    • Introduced a new way to import and use components in the documentation app, enhancing code readability and maintainability.
  • Documentation
    • Updated the documentation app configuration to support new content types and improve the authoring experience.
  • Refactor
    • Refactored accordion components to use a more efficient import method.
  • Chores
    • Updated dependencies to ensure compatibility and security.
  • Tests
    • Ensured all new changes are compatible with existing configurations and types.

Innei avatar Mar 18 '24 13:03 Innei

⚠️ No Changeset found

Latest commit: 2a57dc5c2c780aeb03f5d47da887a793387c02c0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

changeset-bot[bot] avatar Mar 18 '24 13:03 changeset-bot[bot]

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nextui-docs-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 6, 2024 2:44pm
nextui-storybook-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 6, 2024 2:44pm

vercel[bot] avatar Mar 18 '24 13:03 vercel[bot]

@Innei is attempting to deploy a commit to the NextUI Inc Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar Mar 18 '24 13:03 vercel[bot]

Walkthrough

The update modifies import statements across various components in the documentation app, transitioning from internal definitions to importing from raw files. It introduces the esbuild-plugin-raw for handling raw file imports, updates the contentlayer.config.js with new computed fields and options, and refines document type definitions. A new TypeScript declaration file is included for importing files as raw strings, and dependencies are updated accordingly.

Changes

Files Change Summary
.../accordion/bordered-variant.ts
.../accordion/compact.ts
Changed to import App from respective .raw.tsx files instead of defining it internally.
.../contentlayer.config.js Added RawPlugin import, new computed fields, updated AuthorProperties and BlogPost types, added esbuildOptions.
.../package.json Added esbuild-plugin-raw dependency.
.../tsconfig.json Added "types.d.ts" to included files.
.../types.d.ts Introduced declaration for importing files as raw strings.
pnpm-lock.yaml Added esbuild-plugin-raw and its dependencies, updated eslint-config-next, added esbuild dependency.
.../blog/[slug]/page.tsx Modified import for allBlogPosts, changing source to contentlayer2/generated.
.../blog/page.tsx Modified import for allBlogPosts, changing source to contentlayer2/generated.
.../docs/[[...slug]]/page.tsx Modified import for allDocs, changing source to contentlayer2/generated.
.../feed.xml/route.ts Modified import for allBlogPosts, changing source to contentlayer2/generated.
.../components/blog-post.tsx Modified import for BlogPost type, changing source to contentlayer2/generated.
.../components/code-window/code-block.tsx Updated import of hastToHtml to named import toHtml from hast-util-to-html.
.../components/mdx-content.tsx Modified import for useMDXComponent, changing path to "next-contentlayer2/hooks".

Possibly related PRs

  • #3751: This PR addresses documentation issues related to missing Tailwind CSS nested groups, which may be relevant to the changes in import statements and component structures in the main PR.
  • #3796: This PR fixes broken links in the documentation, which could relate to the overall documentation updates and changes in import paths in the main PR.

Suggested labels

📋 Scope : Docs

Suggested reviewers

  • winchesHe

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar Mar 18 '24 13:03 coderabbitai[bot]

That's great, it's very easy to write docs component!

winchesHe avatar Mar 18 '24 13:03 winchesHe

@Innei Thanks for your PR! Could you please resolve the conflicts so that we can proceed with the review?

ryo-manba avatar Apr 22 '24 13:04 ryo-manba

after syncing latest canary branch, this PR no longer works. Therefore I made the following changes.

  • switch from contentlayer to contentlayer2 since contentlayer doesn't support node 20 and out of maintenance. (by the time this PR was made, we were still using node 16 / 18)
  • bump docs related dependencies because of contentlayer2, e.g. rehype, remark, unified, unist-util-visit etc.
  • bump ts version to v5 (ts-pattern requires that)
  • fix module "*.tsx?raw" type and rename to avoid conflict with @types

After this PR is merged, I'll change the rest of the components.

wingkwong avatar Oct 06 '24 15:10 wingkwong

Sorry, I haven't paid attention to this project for a long time and ignored these updates.

Innei avatar Oct 07 '24 12:10 Innei