From 7f8f33ed844bbe2e6c83b77997e1554ee1a17038 Mon Sep 17 00:00:00 2001 From: Antoine BERNIER Date: Fri, 9 Aug 2024 11:16:38 +0200 Subject: [PATCH] MDX + LIBNAME --- .env | 1 + .gitignore | 3 +- package.json | 4 +- readme.md | 16 +++-- src/app/[[...slug]]/DocsContext.tsx | 2 +- src/app/[[...slug]]/layout.tsx | 28 ++++---- src/app/[[...slug]]/page.tsx | 50 ++++++------- src/components/LibSwitcher.tsx | 44 ------------ src/components/Seo.tsx | 29 -------- src/data/libraries.ts | 108 ---------------------------- src/utils/docs.ts | 65 ++++------------- yarn.lock | 80 +-------------------- 12 files changed, 68 insertions(+), 362 deletions(-) create mode 100644 .env delete mode 100644 src/components/LibSwitcher.tsx delete mode 100644 src/components/Seo.tsx delete mode 100644 src/data/libraries.ts diff --git a/.env b/.env new file mode 100644 index 00000000..e9dfd7ad --- /dev/null +++ b/.env @@ -0,0 +1 @@ +MDX=docs \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8cdaf83e..cd8caaae 100644 --- a/.gitignore +++ b/.gitignore @@ -20,5 +20,4 @@ dist/ logs/ out/ tmp/ -temp/ -docs/ \ No newline at end of file +temp/ \ No newline at end of file diff --git a/package.json b/package.json index d66c80f0..3dd68ca9 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "pmndrs-docs", + "name": "@pmndrs/docs", "version": "0.1.0", "private": true, "type": "module", @@ -22,9 +22,7 @@ "@tailwindcss/typography": "^0.5.4", "clsx": "^1.2.1", "gray-matter": "^4.0.2", - "isomorphic-git": "^1.19.1", "match-sorter": "^6.3.1", - "memfs": "^3.4.7", "next": "^14.2.5", "next-mdx-remote": "^4.4.1", "p-memoize": "^7.1.1", diff --git a/readme.md b/readme.md index 3c84782b..aaf6b27b 100644 --- a/readme.md +++ b/readme.md @@ -1,8 +1,14 @@ -# Poimandres Docs +```sh +$ MDX=~/code/pmndrs/react-three-fiber/docs LIBNAME="React Three Fiber" yarn dev +``` -```bash -yarn -yarn dev +```sh +$ MDX=docs LIBNAME="React Three Fiber" yarn build ``` -[![Powered by Vercel](public/vercel.svg)](https://vercel.com/?utm_source=pmndrs&utm_campaign=oss) +| var | description | default | +| ----------- | --------------------------------------------------------- | ------- | +| `MDX` | Path to `*.mxd` folder
NB: can be relative or absolute | `docs` | +| `LIBNAME`\* | Library name | none | + +\* Required diff --git a/src/app/[[...slug]]/DocsContext.tsx b/src/app/[[...slug]]/DocsContext.tsx index 2ec1f25c..9632ebf3 100644 --- a/src/app/[[...slug]]/DocsContext.tsx +++ b/src/app/[[...slug]]/DocsContext.tsx @@ -18,7 +18,7 @@ export type DocToC = { export type Doc = { slug: string[] url: string - editURL: string + // editURL: string nav: number title: string description: string diff --git a/src/app/[[...slug]]/layout.tsx b/src/app/[[...slug]]/layout.tsx index 1ba9ac11..4ef35677 100644 --- a/src/app/[[...slug]]/layout.tsx +++ b/src/app/[[...slug]]/layout.tsx @@ -1,6 +1,5 @@ import clsx from 'clsx' import * as React from 'react' -import LibSwitcher from '@/components/LibSwitcher' import Nav from '@/components/Nav' import Icon from '@/components/Icon' import Toc from '@/components/Toc' @@ -11,10 +10,8 @@ import { useLockBodyScroll } from '@/hooks/useLockBodyScroll' import ToggleTheme from '@/components/ToggleTheme' -import { Doc, DocsContext } from './DocsContext' -import libraries from '@/data/libraries' -import { notFound } from 'next/navigation' -import { getData, getDocs } from '@/utils/docs' +import { DocsContext } from './DocsContext' +import { getData } from '@/utils/docs' export type Props = { params: { slug: string[] } @@ -24,15 +21,8 @@ export type Props = { export default async function Layout({ params, children }: Props) { const slug = params.slug - // 404 - if (!(slug[0] in libraries)) { - return notFound() - } - const asPath = `/${slug.join('/')}` - const lib = slug[0] - const { docs, doc } = await getData(...slug) // console.log('docs', docs) @@ -47,6 +37,8 @@ export default async function Layout({ params, children }: Props) { // React.useEffect(() => setMenuOpen(false), [asPath]) + const { LIBNAME } = process.env + return ( <> @@ -54,7 +46,7 @@ export default async function Layout({ params, children }: Props) {
- Pmndrs + pmndrs .docs
@@ -89,7 +81,11 @@ export default async function Layout({ params, children }: Props) { className="overflow-y-auto px-4 font-medium text-base lg:text-sm pb-10 lg:pb-14 sticky?lg:h-(screen-16) z-10 relative" >
- + {LIBNAME?.length && ( + + {LIBNAME} + + )}
@@ -114,7 +110,7 @@ export default async function Layout({ params, children }: Props) {
{children}