Skip to content

Commit 1ed7e96

Browse files
committed
refactor: enhance DocPageHeading to conditionally include documentation description and update page redirection logic
1 parent b3dbda4 commit 1ed7e96

File tree

3 files changed

+66
-51
lines changed

3 files changed

+66
-51
lines changed

app/docs/[plugin]/[version]/[...slug]/page.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export default async function Page(props: Props) {
3838
notFound();
3939
}
4040

41+
const lastSlug = slugs[slugs.length - 1];
42+
4143
let content = await page.data.load();
4244

4345
if (content.source) {
@@ -53,8 +55,15 @@ export default async function Page(props: Props) {
5355
const MdxContent = content.body;
5456

5557
return (
56-
<DocsPage toc={content.toc} full={content.full}>
57-
<DocPageHeading repository={repository} />
58+
<DocsPage
59+
toc={content.toc}
60+
tableOfContent={{
61+
style: 'clerk',
62+
}}
63+
full={content.full}
64+
breadcrumb={{ enabled: true, full: true, includeRoot: false, includePage: true }}
65+
>
66+
<DocPageHeading repository={repository} includeDocsDescription={lastSlug !== "index" && lastSlug !== "overview"} />
5867
<DocsBody>
5968
<MdxContent
6069
components={createMdxComponents({

app/docs/[plugin]/[version]/page.tsx

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
repositories,
77
getVersionBySlug,
88
} from "@/lib/repo-config";
9-
import { notFound } from "next/navigation";
9+
import { notFound, redirect } from "next/navigation";
1010
import { DocPageHeading } from "../../components";
1111
import { source } from "@/lib/source";
1212
import { createMdxComponents, createRelativeLink } from "@/components/mdx";
@@ -38,54 +38,56 @@ export default async function Page(props: Props) {
3838
<DocsPage>
3939
<DocPageHeading repository={repository} />
4040
<DocsBody>
41-
<Cards>
42-
{version.limited_files?.map((file) => (
43-
<Card
44-
key={file.slug}
45-
href={`/docs/${repoSlug}/${versionSlug}/${file.slug}`}
46-
title={file.title}
47-
className="flex items-center gap-2"
48-
/>
49-
))}
50-
</Cards>
41+
<Cards>
42+
{version.limited_files?.map((file) => (
43+
<Card
44+
key={file.slug}
45+
href={`/docs/${repoSlug}/${versionSlug}/${file.slug}`}
46+
title={file.title}
47+
className="flex items-center gap-2"
48+
/>
49+
))}
50+
</Cards>
5151
</DocsBody>
5252
</DocsPage>
5353
);
5454
}
55-
56-
let content = await page.data.load();
57-
58-
if (content.source) {
59-
const sourcePage = source.getPage(content.source.split("/"));
60-
61-
if (!sourcePage)
62-
throw new Error(
63-
`unresolved source in frontmatter of ${page.file.path}: ${content.source}`,
64-
);
65-
content = await sourcePage.data.load();
66-
}
67-
68-
const MdxContent = content.body;
69-
70-
return (
71-
<DocsPage toc={content.toc} full={content.full}>
72-
<DocPageHeading repository={repository} />
73-
<DocsBody>
74-
<MdxContent
75-
components={createMdxComponents({
76-
a: ({ href, ...props }: { href: string }) => {
77-
return (
78-
<a
79-
href={createRelativeLink(repository, version, href)}
80-
{...props}
81-
/>
82-
);
83-
},
84-
})}
85-
/>
86-
</DocsBody>
87-
</DocsPage>
88-
);
55+
56+
redirect(`/docs/${repoSlug}/${versionSlug}/overview`);
57+
58+
// let content = await page.data.load();
59+
60+
// if (content.source) {
61+
// const sourcePage = source.getPage(content.source.split("/"));
62+
63+
// if (!sourcePage)
64+
// throw new Error(
65+
// `unresolved source in frontmatter of ${page.file.path}: ${content.source}`,
66+
// );
67+
// content = await sourcePage.data.load();
68+
// }
69+
70+
// const MdxContent = content.body;
71+
72+
// return (
73+
// <DocsPage toc={content.toc} full={content.full}>
74+
// <DocPageHeading repository={repository} includeDocsDescription={false} />
75+
// <DocsBody>
76+
// <MdxContent
77+
// components={createMdxComponents({
78+
// a: ({ href, ...props }: { href: string }) => {
79+
// return (
80+
// <a
81+
// href={createRelativeLink(repository, version, href)}
82+
// {...props}
83+
// />
84+
// );
85+
// },
86+
// })}
87+
// />
88+
// </DocsBody>
89+
// </DocsPage>
90+
// );
8991
}
9092

9193
export async function generateMetadata({ params }: Props) {

app/docs/components.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@ import { Github } from "lucide-react";
88

99
export function DocPageHeading({
1010
repository,
11+
includeDocsDescription = true,
1112
}: {
1213
repository: RepositoryConfig;
14+
includeDocsDescription?: boolean;
1315
}) {
1416
return (
1517
<>
1618
<DocsTitle>
1719
<div className="flex items-center gap-4">
18-
<span>{getRepositoryDisplayName(repository)}</span>
19-
<div className="flex gap-2">
20+
{includeDocsDescription && (
21+
<span>{getRepositoryDisplayName(repository)}</span>
22+
)}
23+
<div className="ml-auto flex gap-2">
2024
{!repository.is_private && repository.repository_url && (
2125
<Link
2226
href={repository.repository_url}
@@ -30,9 +34,9 @@ export function DocPageHeading({
3034
</div>
3135
</div>
3236
</DocsTitle>
33-
{repository.description && (
37+
{repository.description && includeDocsDescription && (
3438
<DocsDescription>{repository.description}</DocsDescription>
3539
)}
3640
</>
3741
);
38-
}
42+
}

0 commit comments

Comments
 (0)