Skip to content

Commit

Permalink
fix: generate correct paths after moving catch-all
Browse files Browse the repository at this point in the history
  • Loading branch information
iCrawl committed Nov 30, 2022
1 parent 4ae029d commit 8a39c14
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
27 changes: 9 additions & 18 deletions apps/website/src/app/docs/packages/[package]/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ import { DESCRIPTION, PACKAGES } from '~/util/constants';
import { findMember, findMemberByKey } from '~/util/model.server';
import { tryResolveDescription } from '~/util/summary';

export async function generateStaticParams({ params }: { params: { package: string } }) {
const packageName = params.package;

if (!packageName) {
return [{ slug: [] }];
}
export async function generateStaticParams({ params }: { params?: { package: string } }) {
const packageName = params?.package ?? 'builders';

try {
let data: any[] = [];
Expand All @@ -73,22 +69,17 @@ export async function generateStaticParams({ params }: { params: { package: stri
const pkgs = models.map((model) => findPackage(model, packageName)) as ApiPackage[];

return [
...versions.map((version) => ({ slug: ['packages', packageName, version] })),
...versions.map((version) => ({ slug: [version] })),
...pkgs.flatMap((pkg, idx) =>
getMembers(pkg, versions[idx] ?? 'main').map((member) => {
if (member.kind === ApiItemKind.Function && member.overloadIndex && member.overloadIndex > 1) {
return {
slug: [
'packages',
packageName,
versions[idx] ?? 'main',
`${member.name}:${member.overloadIndex}:${member.kind}`,
],
slug: [versions[idx] ?? 'main', `${member.name}:${member.overloadIndex}:${member.kind}`],
};
}

return {
slug: ['packages', packageName, versions[idx] ?? 'main', `${member.name}:${member.kind}`],
slug: [versions[idx] ?? 'main', `${member.name}:${member.kind}`],
};
}),
),
Expand All @@ -99,19 +90,19 @@ export async function generateStaticParams({ params }: { params: { package: stri
const pkg = findPackage(model, packageName)!;

return [
{ slug: ['packages', packageName, 'main'] },
{ slug: ['main'] },
...getMembers(pkg, 'main').map((member) => {
if (member.kind === ApiItemKind.Function && member.overloadIndex && member.overloadIndex > 1) {
return {
slug: ['packages', packageName, 'main', `${member.name}:${member.overloadIndex}:${member.kind}`],
slug: ['main', `${member.name}:${member.overloadIndex}:${member.kind}`],
};
}

return { slug: ['packages', packageName, 'main', `${member.name}:${member.kind}`] };
return { slug: ['main', `${member.name}:${member.kind}`] };
}),
];
} catch {
return [{ slug: [] }];
return [{ slug: ['main'] }];
}
}

Expand Down
1 change: 1 addition & 0 deletions apps/website/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function Page() {
<Link
className="bg-blurple focus:ring-width-2 flex h-11 transform-gpu cursor-pointer select-none appearance-none flex-row place-items-center rounded border-0 px-6 text-base font-semibold leading-none text-white no-underline outline-0 focus:ring focus:ring-white active:translate-y-px"
href="/docs"
prefetch={false}
>
Docs
</Link>
Expand Down

1 comment on commit 8a39c14

@vercel
Copy link

@vercel vercel bot commented on 8a39c14 Nov 30, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.