refactor: change url scheme

This commit is contained in:
iCrawl
2022-08-22 16:50:43 +02:00
parent 1aec243b1d
commit 1e001601c8
4 changed files with 9 additions and 9 deletions

View File

@@ -2,9 +2,9 @@ import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export default function middleware(request: NextRequest) {
return NextResponse.redirect(new URL('/docs/main/packages/builders', request.url));
return NextResponse.redirect(new URL('/docs/packages/builders/main', request.url));
}
export const config = {
matcher: ['/docs', '/docs/:branch'],
matcher: ['/docs'],
};

View File

@@ -49,7 +49,7 @@ export const getStaticPaths: GetStaticPaths = async () => {
const pkg = findPackage(model, packageName);
return [
{ params: { slug: ['main', 'packages', packageName] } },
{ params: { slug: ['packages', packageName, 'main'] } },
...getMembers(pkg!)
// Filtering out enum `RESTEvents` because of interface with similar name `RestEvents`
// causing next.js export to error
@@ -58,12 +58,12 @@ export const getStaticPaths: GetStaticPaths = async () => {
if (member.kind === 'Function' && member.overloadIndex && member.overloadIndex > 1) {
return {
params: {
slug: ['main', 'packages', packageName, `${member.name}:${member.overloadIndex}`],
slug: ['packages', packageName, 'main', `${member.name}:${member.overloadIndex}`],
},
};
}
return { params: { slug: ['main', 'packages', packageName, member.name] } };
return { params: { slug: ['packages', packageName, 'main', member.name] } };
}),
];
} catch {
@@ -80,7 +80,7 @@ export const getStaticPaths: GetStaticPaths = async () => {
};
export const getStaticProps: GetStaticProps = async ({ params }) => {
const [branchName = 'main', , packageName = 'builders', member = 'ActionRowBuilder'] = params!.slug as string[];
const [, packageName = 'builders', branchName = 'main', member = 'ActionRowBuilder'] = params!.slug as string[];
const [memberName, overloadIndex] = member.split(':') as [string, string | undefined];

View File

@@ -22,7 +22,7 @@ export default function PackagesRoute() {
<Container pt={96} size="xs">
<Stack sx={{ flexGrow: 1 }}>
{packages.map((pkg) => (
<Link key={pkg} href={`/docs/main/packages/${pkg}`} passHref>
<Link key={pkg} href={`/docs/packages/${pkg}/main`} passHref>
<UnstyledButton className={classes.control} component="a">
<Group position="apart">
<Group>

View File

@@ -24,7 +24,7 @@ export function findPackage(model: ApiModel, name: string): ApiPackage | undefin
}
export function generatePath(items: readonly ApiItem[]) {
let path = '/docs/main/packages';
let path = '/docs/packages';
for (const item of items) {
switch (item.kind) {
case ApiItemKind.Model:
@@ -53,7 +53,7 @@ export function generatePath(items: readonly ApiItem[]) {
}
}
return path.replace(/@discordjs\//, '');
return path.replace(/@discordjs\/(.*)\/(.*)?/, '$1/main/$2');
}
export function resolveDocComment(item: ApiDocumentedItem) {