Skip to content

Commit 465f17a

Browse files
committed
feat: refactor markdown compilation with React caching and improve parsing
- Implemented React's cache for the markdown compilation process to enhance performance. - Refactored the `compile` function to utilize the new caching mechanism. - Improved the `parseSourceBeforeCompile` function to handle additional parsing cases. - Updated the `meta.ts` file to clarify the structure of the repository metadata. - Changed the slug for README files from "index" to "overview" for consistency. - Added a new utility function `removeLeadingNumber` to clean up file titles. - Enhanced GitHub source fetching with caching for directory and file retrieval. - Updated Next.js configuration to prevent externalizing the 'shiki' package. - Added scripts for Windows development and build processes. - Updated package dependencies to include 'shiki' version 3.12.0.
1 parent 03f9c8c commit 465f17a

19 files changed

Lines changed: 441 additions & 634 deletions

File tree

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { NextRequest, NextResponse } from "next/server";
55
//import { source } from '@/lib/source';
66
//import { createLocalSource } from "@/lib/sources/local";
77

8-
export async function GET() {
8+
export default async function GET() {
99
return NextResponse.json({ message: "Search not implemented" });
1010
}
1111

12-
export async function generateStaticParams() {
13-
return [];
14-
}
12+
// export async function generateStaticParams() {
13+
// return [];
14+
// }
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ export async function GET(request: NextRequest) {
3131
}
3232
}
3333

34-
export async function generateStaticParams() {
35-
return [];
36-
}
34+
// export async function generateStaticParams() {
35+
// return [];
36+
// }

app/api/cache/route.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

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

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Props = {
1616
};
1717

1818
export default async function Page(props: Props) {
19+
1920
const resolvedParams = await props.params;
2021
const repoSlug = resolvedParams.plugin;
2122
const versionSlug = resolvedParams.version;
@@ -67,9 +68,6 @@ export default async function Page(props: Props) {
6768
},
6869
})}
6970
/>
70-
{/* {page.file.name === "index" && (
71-
<DocsCategory page={page} from={source} />
72-
)} */}
7371
</DocsBody>
7472
</DocsPage>
7573
);
@@ -107,33 +105,86 @@ export async function generateMetadata({ params }: Props) {
107105
}
108106

109107
export async function generateStaticParams() {
110-
// Generate params for all repository and version combinations
108+
// Generate params for all repository and version combinations with their actual pages
111109
const params: { plugin: string; version: string; slug: string[] }[] = [];
112110

111+
// console.debug("### Repositories length:", repositories.length);
112+
113113
for (const repository of repositories) {
114114
const repoSlug = repository.repo;
115+
// console.debug("### Processing repo:", repoSlug);
115116

116117
for (const version of repository.versions) {
117118
const versionSlug = version.version;
119+
// console.debug("### Processing version:", versionSlug);
120+
121+
// Get limited files for this version
122+
const limitedFiles = version.limited_files || [];
123+
// console.debug("### Limited files:", limitedFiles);
124+
125+
for (const file of limitedFiles) {
126+
// console.debug("### Processing file:", file);
127+
128+
// Skip files with slug "index" as they are handled by [version]/page.tsx
129+
if (file.slug === "index") {
130+
// console.debug("### Skipping index file");
131+
continue;
132+
}
133+
134+
// Create the slug array for this file
135+
const slug = [file.slug];
136+
137+
// console.debug("### Adding param:", { plugin: repoSlug, version: versionSlug, slug });
138+
139+
params.push({
140+
plugin: repoSlug,
141+
version: versionSlug,
142+
slug: slug,
143+
});
144+
}
118145

119-
// Skip empty slug - that's handled by [version]/page.tsx
120-
// params.push({ plugin: repoSlug, version: versionSlug, slug: [] });
146+
if (repository.docsPath) {
147+
// Search the pages
148+
const docsPages = source.getPages()
149+
.filter(p => p.url.startsWith(`/docs/${repoSlug}/${versionSlug}/`));
121150

122-
// Add limited files for this version
123-
if (version.limited_files) {
124-
for (const file of version.limited_files) {
125-
if (file.slug === "index") {
126-
continue; // skip index as it's handled by [version]/page.tsx
151+
// console.debug("### Found doc pages:", docsPages);
152+
153+
for (const docPage of docsPages) {
154+
155+
const docPageSlug = docPage.slugs.slice(2); // Skip repo/version
156+
157+
if (docPageSlug.length === 0) {
158+
// Skip empty slugs
159+
continue;
127160
}
161+
162+
if (params.some(p => p.plugin === repoSlug && p.version === versionSlug && arraysEqual(p.slug, docPageSlug))) {
163+
// Skip existing params
164+
continue;
165+
}
166+
167+
// Create a param for each doc page
128168
params.push({
129169
plugin: repoSlug,
130170
version: versionSlug,
131-
slug: [file.slug],
171+
slug: docPageSlug,
132172
});
133173
}
134174
}
135175
}
136176
}
137177

178+
// console.debug("### Final static params:", params);
179+
138180
return params;
139181
}
182+
183+
184+
function arraysEqual(a: any[], b: any[]) {
185+
if (a.length !== b.length) return false;
186+
for (let i = 0; i < a.length; i++) {
187+
if (a[i] !== b[i]) return false;
188+
}
189+
return true;
190+
}

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { notFound } from "next/navigation";
1010
import { DocPageHeading } from "../../components";
1111
import { source } from "@/lib/source";
1212
import { createMdxComponents, createRelativeLink } from "@/components/mdx";
13+
import { Cards, Card } from "fumadocs-ui/components/card";
1314

1415
type Props = {
1516
params: Promise<{ plugin: string; version: string }>;
@@ -30,14 +31,23 @@ export default async function Page(props: Props) {
3031
notFound();
3132
}
3233

33-
const fullSlug = [repoSlug, versionSlug];
34+
const fullSlug = [repoSlug, versionSlug, 'overview'];
3435
const page = source.getPage(fullSlug);
3536
if (!page) {
3637
return (
3738
<DocsPage>
3839
<DocPageHeading repository={repository} />
3940
<DocsBody>
40-
<p>Documentation not found for this version.</p>
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>
4151
</DocsBody>
4252
</DocsPage>
4353
);
@@ -73,9 +83,6 @@ export default async function Page(props: Props) {
7383
},
7484
})}
7585
/>
76-
{/* {page.file.name === "index" && (
77-
<DocsCategory page={page} from={source} />
78-
)} */}
7986
</DocsBody>
8087
</DocsPage>
8188
);

components/mdx.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,15 @@ const mdxComponents = {
165165
: parseInt(props.height) || defaultHeight
166166
: defaultHeight;
167167

168+
let url = props.src;
169+
// if (url.startsWith('./') || url.startsWith('../')) {
170+
// url = siteConfig.baseUrl + '/' + url;
171+
// }
172+
168173
return (
169174
<div className="not-prose my-6 rounded-xl p-1 bg-gradient-to-br from-white/10 to-black/10 border shadow-lg">
170175
<ImageZoom
171-
src={props.src}
176+
src={url}
172177
height={height}
173178
width={width}
174179
loading="lazy"

0 commit comments

Comments
 (0)