mirror of
https://github.com/discordjs/discord.js.git
synced 2024-08-21 05:54:44 +12:00
refactor: display readme correctly
This commit is contained in:
parent
fcfe5cf142
commit
34d0224b68
7 changed files with 108 additions and 23 deletions
|
@ -7,7 +7,7 @@
|
|||
"scripts": {
|
||||
"test": "vitest run",
|
||||
"test:lighthouse": "lighthouse http://localhost:3000 --output-path=./lighthouse-results",
|
||||
"build:copy_readme": "cpy '../../packages/*/README.md' 'src/assets/readme' --rename='home-{{basename}}'",
|
||||
"build:copy_readme": "cpy '../../packages/(discord.js|brokers|builders|collection|core|formatters|next|proxy|rest|util|voice|ws)/README.md' 'src/assets/readme' --rename='home-{{basename}}'",
|
||||
"build:check": "tsc --noEmit",
|
||||
"build:local": "cross-env NEXT_PUBLIC_LOCAL_DEV=true pnpm run build:prod",
|
||||
"build:prod": "pnpm run build:copy_readme && pnpm run build:next",
|
||||
|
@ -47,10 +47,10 @@
|
|||
},
|
||||
"homepage": "https://discord.js.org",
|
||||
"dependencies": {
|
||||
"@discordjs/api-extractor-model": "workspace:^",
|
||||
"@discordjs/api-extractor-utils": "workspace:^",
|
||||
"@discordjs/scripts": "workspace:^",
|
||||
"@discordjs/ui": "workspace:^",
|
||||
"@discordjs/api-extractor-model": "workspace:^",
|
||||
"@microsoft/tsdoc": "^0.14.2",
|
||||
"@microsoft/tsdoc-config": "0.16.2",
|
||||
"@planetscale/database": "^1.11.0",
|
||||
|
|
|
@ -12,7 +12,7 @@ const sql = connect({
|
|||
},
|
||||
});
|
||||
|
||||
export const fetchVersions = cache(async (packageName: string) => {
|
||||
export const fetchVersions = cache(async (packageName: string): Promise<string[]> => {
|
||||
if (process.env.NEXT_PUBLIC_LOCAL_DEV || process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview') {
|
||||
return ['main'];
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import dynamic from 'next/dynamic';
|
|||
import { notFound } from 'next/navigation';
|
||||
import { cache, type PropsWithChildren } from 'react';
|
||||
import { fetchModelJSON, fetchVersions } from '~/app/docAPI';
|
||||
// import { Banner } from '~/components/Banner';
|
||||
import { CmdKDialog } from '~/components/CmdK';
|
||||
import { Nav } from '~/components/Nav';
|
||||
import type { SidebarSectionItemData } from '~/components/Sidebar';
|
||||
|
@ -77,7 +76,6 @@ export default async function PackageLayout({ children, params }: PropsWithChild
|
|||
|
||||
return (
|
||||
<Providers>
|
||||
{/* <Banner className="mb-6" /> */}
|
||||
<main className="mx-auto max-w-7xl px-4 lg:max-w-full">
|
||||
<Header />
|
||||
<div className="relative top-2.5 mx-auto max-w-7xl gap-6 lg:max-w-full lg:flex">
|
||||
|
|
|
@ -15,9 +15,8 @@ const loadREADME = cache(async (packageName: string) => {
|
|||
const mdxOptions = {
|
||||
mdxOptions: {
|
||||
remarkPlugins: [remarkGfm],
|
||||
remarkRehypeOptions: { allowDangerousHtml: true },
|
||||
rehypePlugins: [rehypeSlug],
|
||||
format: 'md',
|
||||
format: 'mdx',
|
||||
},
|
||||
} satisfies SerializeOptions;
|
||||
|
||||
|
@ -26,7 +25,7 @@ export default async function Page({ params }: { params: VersionRouteParams }) {
|
|||
const readmeSource = await loadREADME(packageName);
|
||||
|
||||
return (
|
||||
<div className="max-w-none prose">
|
||||
<div className="relative top-4 max-w-none prose">
|
||||
{/* @ts-expect-error SyntaxHighlighter is assignable */}
|
||||
<MDXRemote components={{ pre: SyntaxHighlighter }} options={mdxOptions} source={readmeSource} />
|
||||
</div>
|
||||
|
|
|
@ -11,7 +11,7 @@ const sql = connect({
|
|||
},
|
||||
});
|
||||
|
||||
async function fetchLatestVersion(packageName: string) {
|
||||
async function fetchLatestVersion(packageName: string): Promise<string> {
|
||||
if (process.env.NEXT_PUBLIC_LOCAL_DEV || process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview') {
|
||||
return 'main';
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ async function fetchLatestVersion(packageName: string) {
|
|||
]);
|
||||
|
||||
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
|
||||
return rows.map((row) => row.version).at(1);
|
||||
return rows.map((row) => row.version).at(1) ?? 'main';
|
||||
}
|
||||
|
||||
export default async function middleware(request: NextRequest) {
|
||||
|
@ -39,9 +39,7 @@ export default async function middleware(request: NextRequest) {
|
|||
// eslint-disable-next-line prefer-named-capture-group
|
||||
const packageName = /\/docs\/packages\/([^/]+)\/.*/.exec(request.nextUrl.pathname)?.[1] ?? 'discord.js';
|
||||
const latestVersion = await fetchLatestVersion(packageName);
|
||||
return NextResponse.redirect(
|
||||
new URL(request.nextUrl.pathname.replace('stable', latestVersion ?? 'main'), request.url),
|
||||
);
|
||||
return NextResponse.redirect(new URL(request.nextUrl.pathname.replace('stable', latestVersion), request.url));
|
||||
}
|
||||
|
||||
return NextResponse.redirect(new URL('/docs/packages', request.url));
|
||||
|
|
|
@ -147,7 +147,7 @@ export async function writeIndexToFileSystem(
|
|||
}
|
||||
|
||||
await writeFile(
|
||||
join(cwd(), 'public', dir, `${packageName}-${tag.replaceAll('.', '-')}-index.json`),
|
||||
join(cwd(), 'public', dir, `${packageName}-${tag}-index.json`),
|
||||
JSON.stringify(members, undefined, 2),
|
||||
);
|
||||
}
|
||||
|
@ -178,10 +178,14 @@ export async function generateAllIndices({
|
|||
const data = await fetchPackageVersionDocs(pkg, version);
|
||||
const model = addPackageToModel(new ApiModel(), data);
|
||||
const members = visitNodes(model.tryGetPackageByName(pkg)!.entryPoints[0]!, version);
|
||||
|
||||
const sanitizePackageName = pkg.replaceAll('.', '-');
|
||||
const sanitizeVersion = version.replaceAll('.', '-');
|
||||
|
||||
if (writeToFile) {
|
||||
await writeIndexToFileSystem(members, pkg, version);
|
||||
await writeIndexToFileSystem(members, sanitizePackageName, sanitizeVersion);
|
||||
} else {
|
||||
indices.push({ index: `${pkg.replaceAll('.', '-')}-${version.replaceAll('.', '-')}`, data: members });
|
||||
indices.push({ index: `${sanitizePackageName}-${sanitizeVersion}`, data: members });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
100
pnpm-lock.yaml
100
pnpm-lock.yaml
|
@ -319,7 +319,7 @@ importers:
|
|||
version: 14.0.0(react-dom@18.2.0)(react@18.2.0)
|
||||
'@testing-library/user-event':
|
||||
specifier: ^14.5.1
|
||||
version: 14.5.1(@testing-library/dom@9.3.3)
|
||||
version: 14.5.1
|
||||
'@types/node':
|
||||
specifier: 18.18.8
|
||||
version: 18.18.8
|
||||
|
@ -340,7 +340,7 @@ importers:
|
|||
version: 0.57.2
|
||||
'@vitejs/plugin-react':
|
||||
specifier: ^4.1.1
|
||||
version: 4.1.1(vite@4.5.0)
|
||||
version: 4.1.1
|
||||
'@vitest/coverage-v8':
|
||||
specifier: ^0.34.6
|
||||
version: 0.34.6(vitest@0.34.6)
|
||||
|
@ -7458,6 +7458,16 @@ packages:
|
|||
react-dom: 18.2.0(react@18.2.0)
|
||||
dev: true
|
||||
|
||||
/@testing-library/user-event@14.5.1:
|
||||
resolution: {integrity: sha512-UCcUKrUYGj7ClomOo2SpNVvx4/fkd/2BbIHDCle8A0ax+P3bU7yJwDBDrS6ZwdTMARWTGODX1hEsCcO+7beJjg==}
|
||||
engines: {node: '>=12', npm: '>=6'}
|
||||
peerDependencies:
|
||||
'@testing-library/dom': '>=7.21.4'
|
||||
peerDependenciesMeta:
|
||||
'@testing-library/dom':
|
||||
optional: true
|
||||
dev: true
|
||||
|
||||
/@testing-library/user-event@14.5.1(@testing-library/dom@9.3.3):
|
||||
resolution: {integrity: sha512-UCcUKrUYGj7ClomOo2SpNVvx4/fkd/2BbIHDCle8A0ax+P3bU7yJwDBDrS6ZwdTMARWTGODX1hEsCcO+7beJjg==}
|
||||
engines: {node: '>=12', npm: '>=6'}
|
||||
|
@ -8715,6 +8725,24 @@ packages:
|
|||
- supports-color
|
||||
dev: true
|
||||
|
||||
/@vitejs/plugin-react@4.1.1:
|
||||
resolution: {integrity: sha512-Jie2HERK+uh27e+ORXXwEP5h0Y2lS9T2PRGbfebiHGlwzDO0dEnd2aNtOR/qjBlPb1YgxwAONeblL1xqLikLag==}
|
||||
engines: {node: ^14.18.0 || >=16.0.0}
|
||||
peerDependencies:
|
||||
vite: ^4.2.0
|
||||
peerDependenciesMeta:
|
||||
vite:
|
||||
optional: true
|
||||
dependencies:
|
||||
'@babel/core': 7.23.2
|
||||
'@babel/plugin-transform-react-jsx-self': 7.22.5(@babel/core@7.23.2)
|
||||
'@babel/plugin-transform-react-jsx-source': 7.22.5(@babel/core@7.23.2)
|
||||
'@types/babel__core': 7.20.3
|
||||
react-refresh: 0.14.0
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: true
|
||||
|
||||
/@vitejs/plugin-react@4.1.1(vite@4.5.0):
|
||||
resolution: {integrity: sha512-Jie2HERK+uh27e+ORXXwEP5h0Y2lS9T2PRGbfebiHGlwzDO0dEnd2aNtOR/qjBlPb1YgxwAONeblL1xqLikLag==}
|
||||
engines: {node: ^14.18.0 || >=16.0.0}
|
||||
|
@ -11531,7 +11559,7 @@ packages:
|
|||
dependencies:
|
||||
semver: 7.5.4
|
||||
shelljs: 0.8.5
|
||||
typescript: 5.4.0-dev.20231107
|
||||
typescript: 5.4.0-dev.20231108
|
||||
dev: true
|
||||
|
||||
/dts-critic@3.3.11(typescript@5.2.2):
|
||||
|
@ -21530,8 +21558,8 @@ packages:
|
|||
engines: {node: '>=14.17'}
|
||||
hasBin: true
|
||||
|
||||
/typescript@5.4.0-dev.20231107:
|
||||
resolution: {integrity: sha512-4bQlfsyFjzZMo1bSLEkFJEcvuQ64pgE0S/BpdWu16lYsQOfJZtntZIyWdED3h+e96IMtVgrC6sxzfPZhj4J/dw==}
|
||||
/typescript@5.4.0-dev.20231108:
|
||||
resolution: {integrity: sha512-/DNtrqpbir9XaRxE6qwjhB94pCZzw/9R/PhB8309frJBEBGZ5qSDqstl7YYbhWbqs+zWpCCbwBjWDGlz8wn8GA==}
|
||||
engines: {node: '>=14.17'}
|
||||
hasBin: true
|
||||
dev: true
|
||||
|
@ -22154,6 +22182,28 @@ packages:
|
|||
unist-util-stringify-position: 3.0.3
|
||||
vfile-message: 3.1.4
|
||||
|
||||
/vite-node@0.34.6(@types/node@18.18.8):
|
||||
resolution: {integrity: sha512-nlBMJ9x6n7/Amaz6F3zJ97EBwR2FkzhBRxF5e+jE6LA3yi6Wtc2lyTij1OnDMIr34v5g/tVQtsVAzhT0jc5ygA==}
|
||||
engines: {node: '>=v14.18.0'}
|
||||
hasBin: true
|
||||
dependencies:
|
||||
cac: 6.7.14
|
||||
debug: 4.3.4
|
||||
mlly: 1.4.2
|
||||
pathe: 1.1.1
|
||||
picocolors: 1.0.0
|
||||
vite: 4.5.0(@types/node@18.18.8)
|
||||
transitivePeerDependencies:
|
||||
- '@types/node'
|
||||
- less
|
||||
- lightningcss
|
||||
- sass
|
||||
- stylus
|
||||
- sugarss
|
||||
- supports-color
|
||||
- terser
|
||||
dev: true
|
||||
|
||||
/vite-node@0.34.6(@types/node@18.18.8)(terser@5.24.0):
|
||||
resolution: {integrity: sha512-nlBMJ9x6n7/Amaz6F3zJ97EBwR2FkzhBRxF5e+jE6LA3yi6Wtc2lyTij1OnDMIr34v5g/tVQtsVAzhT0jc5ygA==}
|
||||
engines: {node: '>=v14.18.0'}
|
||||
|
@ -22202,6 +22252,42 @@ packages:
|
|||
- supports-color
|
||||
dev: true
|
||||
|
||||
/vite@4.5.0(@types/node@18.18.8):
|
||||
resolution: {integrity: sha512-ulr8rNLA6rkyFAlVWw2q5YJ91v098AFQ2R0PRFwPzREXOUJQPtFUG0t+/ZikhaOCDqFoDhN6/v8Sq0o4araFAw==}
|
||||
engines: {node: ^14.18.0 || >=16.0.0}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
'@types/node': '>= 14'
|
||||
less: '*'
|
||||
lightningcss: ^1.21.0
|
||||
sass: '*'
|
||||
stylus: '*'
|
||||
sugarss: '*'
|
||||
terser: ^5.4.0
|
||||
peerDependenciesMeta:
|
||||
'@types/node':
|
||||
optional: true
|
||||
less:
|
||||
optional: true
|
||||
lightningcss:
|
||||
optional: true
|
||||
sass:
|
||||
optional: true
|
||||
stylus:
|
||||
optional: true
|
||||
sugarss:
|
||||
optional: true
|
||||
terser:
|
||||
optional: true
|
||||
dependencies:
|
||||
'@types/node': 18.18.8
|
||||
esbuild: 0.18.20
|
||||
postcss: 8.4.31
|
||||
rollup: 3.29.4
|
||||
optionalDependencies:
|
||||
fsevents: 2.3.3
|
||||
dev: true
|
||||
|
||||
/vite@4.5.0(@types/node@18.18.8)(terser@5.24.0):
|
||||
resolution: {integrity: sha512-ulr8rNLA6rkyFAlVWw2q5YJ91v098AFQ2R0PRFwPzREXOUJQPtFUG0t+/ZikhaOCDqFoDhN6/v8Sq0o4araFAw==}
|
||||
engines: {node: ^14.18.0 || >=16.0.0}
|
||||
|
@ -22292,8 +22378,8 @@ packages:
|
|||
strip-literal: 1.3.0
|
||||
tinybench: 2.5.1
|
||||
tinypool: 0.7.0
|
||||
vite: 4.5.0(@types/node@18.18.8)(terser@5.24.0)
|
||||
vite-node: 0.34.6(@types/node@18.18.8)(terser@5.24.0)
|
||||
vite: 4.5.0(@types/node@18.18.8)
|
||||
vite-node: 0.34.6(@types/node@18.18.8)
|
||||
why-is-node-running: 2.2.2
|
||||
transitivePeerDependencies:
|
||||
- less
|
||||
|
|
Loading…
Reference in a new issue