Skip to content

Commit a290304

Browse files
committed
chore: comment out deprecated Filaletter repository configuration, and add local storage
1 parent ad87897 commit a290304

14 files changed

Lines changed: 123 additions & 114 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
# test & build
1313
/coverage
14+
/fi-plugins/
1415
/.next/
1516
/out/
1617
/build
@@ -35,4 +36,4 @@ next-env.d.ts
3536
/.vscode/
3637

3738
# static export
38-
/out/
39+
/out/

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from "@/lib/repo-config";
99
import { notFound } from "next/navigation";
1010
import { DocPageHeading } from "../../../components";
11-
import { source } from "@/lib/source";
11+
import { source, isLocal } from "@/lib/source";
1212
import { createMdxComponents, createRelativeLink } from "@/components/mdx";
1313

1414
type Props = {
@@ -105,6 +105,11 @@ export async function generateMetadata({ params }: Props) {
105105
}
106106

107107
export async function generateStaticParams() {
108+
// if (isLocal) {
109+
// const localParams = source.generateParams();
110+
// // console.debug("### Local params:", localParams);
111+
// return localParams;
112+
// }
108113
// Generate params for all repository and version combinations with their actual pages
109114
const params: { plugin: string; version: string; slug: string[] }[] = [];
110115

app/docs/layout.client.tsx

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

app/docs/layout.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ import { DocsLayout } from "fumadocs-ui/layouts/notebook";
22
import type { ReactNode } from "react";
33
import { baseOptions } from "@/app/layout.config";
44
import { source } from "@/lib/source";
5-
import { Body } from "./layout.client";
65

76
export default function Layout({ children }: { children: ReactNode }) {
87
return (
9-
<Body>
10-
<DocsLayout tree={source.pageTree} {...baseOptions}>
11-
{children}
12-
</DocsLayout>
13-
</Body>
8+
<DocsLayout tree={source.pageTree} {...baseOptions}>
9+
{children}
10+
</DocsLayout>
1411
);
1512
}

app/global.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@
1313

1414
:root {
1515
--fd-layout-width: 1600px;
16+
--color-fd-primary: #007C90;
1617
}

lib/compile-md.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ export interface CompiledPage {
1818

1919
toc: TableOfContents;
2020
body: FC<{ components?: MDXComponents }>;
21-
22-
staticHtmlSource?: string;
2321
}
2422

2523
// Create a cached compile function using React cache

lib/repo-config.ts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,36 +67,36 @@ const rawRepositories = [
6767
},
6868
],
6969
},
70-
{
71-
description: 'Effortlessly manage your newsletters with our Filament Newsletter package, designed for seamless integration with the Filament Admin Panel. Enjoy flexible and user-friendly email marketing directly within your admin panel.',
72-
repository_url: 'https://github.com/solutionforest/filaletter',
73-
latest_version: '3.x',
74-
is_private: true,
75-
versions: [
76-
{
77-
version: '2.x',
78-
github_branch: 'v2.x',
79-
limited_files: [
80-
{ name: "README.md", title: "Overview", slug: "overview" },
81-
]
82-
},
83-
{
84-
version: '3.x',
85-
github_branch: 'v3.x',
86-
limited_files: [
87-
{ name: "README.md", title: "Overview", slug: "overview" },
88-
]
89-
},
90-
{
91-
version: '4.x',
92-
github_branch: 'v4.x',
93-
limited_files: [
94-
{ name: "README.md", title: "Overview", slug: "overview" },
95-
]
96-
},
97-
],
98-
docsPath: "filaletter/public/docs", // include docs
99-
},
70+
// {
71+
// description: 'Effortlessly manage your newsletters with our Filament Newsletter package, designed for seamless integration with the Filament Admin Panel. Enjoy flexible and user-friendly email marketing directly within your admin panel.',
72+
// repository_url: 'https://github.com/solutionforest/filaletter',
73+
// latest_version: '3.x',
74+
// is_private: true,
75+
// versions: [
76+
// {
77+
// version: '2.x',
78+
// github_branch: 'v2.x',
79+
// limited_files: [
80+
// { name: "README.md", title: "Overview", slug: "overview" },
81+
// ]
82+
// },
83+
// {
84+
// version: '3.x',
85+
// github_branch: 'v3.x',
86+
// limited_files: [
87+
// { name: "README.md", title: "Overview", slug: "overview" },
88+
// ]
89+
// },
90+
// {
91+
// version: '4.x',
92+
// github_branch: 'v4.x',
93+
// limited_files: [
94+
// { name: "README.md", title: "Overview", slug: "overview" },
95+
// ]
96+
// },
97+
// ],
98+
// docsPath: "filaletter/public/docs", // include docs
99+
// },
100100
{
101101
description:
102102
"A powerful tree structure management plugin for Filament with drag-and-drop functionality and hierarchical data organization.",

lib/source.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ import { createLocalSource } from "./sources/local";
55

66
const FileNameRegex = /^\d\d-(.+)$/;
77

8-
// export const isLocal =
9-
// process.env.NODE_ENV !== "production" || process.env.NEXT_PHASE === "phase-production-build";
10-
// // process.env.ENV === "local" || process.env.NEXT_PHASE === "phase-production-build";
118
export const isLocal =
12-
process.env.LOCAL || process.env.NEXT_PHASE === "phase-production-build";
9+
process.env.NEXT_DOC_SOURCE === 'local'; // || process.env.NEXT_PHASE === "phase-production-build";
10+
11+
console.debug('#### Is Local: ', isLocal);
1312

1413
export const source = loader({
1514
baseUrl: "/docs",
1615
// source: await createLocalSource(),
17-
source: await createGitHubSource(),
18-
// source: isLocal ? await createLocalSource() : await createGitHubSource(),
16+
// source: await createGitHubSource(),
17+
source: isLocal ? await createLocalSource() : await createGitHubSource(),
1918
slugs(info) {
2019
try {
2120
const segments = info.path

lib/sources/github.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
type VersionConfig,
1212
} from "../repo-config";
1313
import { cache as reactCache } from 'react';
14+
import { buildMarkdownFileToLocal } from "./local";
1415

1516
const token = process.env.GITHUB_TOKEN;
1617
if (!token) throw new Error(`environment variable GITHUB_TOKEN is needed.`);
@@ -243,6 +244,8 @@ async function fetchRepositoryFiles(
243244
const versionSlug = version.version;
244245
const allFiles: VirtualFile[] = [];
245246

247+
const rawMarkdownFiles = new Map<string, string>();
248+
246249
// 1. Fetch limited files (README.md, CHANGELOG.md, etc.)
247250
// All repositories should now have version-specific limited_files
248251
const limitedFiles = version.limited_files || [];
@@ -253,7 +256,9 @@ async function fetchRepositoryFiles(
253256
const pagePath = `${repoSlug}/${versionSlug}/${limitedFile.slug}`;
254257
const pageTitle = limitedFile.title || getTitleFromFile(limitedFile.name);
255258

256-
// console.debug(`1| Adding limited file: ${pagePath} (title: ${pageTitle})`);
259+
console.debug(`1| Adding limited file: ${pagePath} (title: ${pageTitle})`);
260+
261+
rawMarkdownFiles.set(pagePath, content);
257262

258263
allFiles.push({
259264
type: "page",
@@ -324,6 +329,10 @@ async function fetchRepositoryFiles(
324329

325330
// console.debug(`2| Adding doc file: ${pagePath} (title: ${pageTitle})`);
326331

332+
const content = await fetchBlob(file.url as string);
333+
334+
rawMarkdownFiles.set(pagePath, content);
335+
327336
docsFiles.push({
328337
type: "page",
329338
path: pagePath,
@@ -333,7 +342,6 @@ async function fetchRepositoryFiles(
333342
version: version,
334343

335344
async load() {
336-
const content = await fetchBlob(file.url as string);
337345
return compile(file.path!, content);
338346
},
339347
},
@@ -379,6 +387,8 @@ async function fetchRepositoryFiles(
379387
}
380388
}
381389

390+
await buildMarkdownFileToLocal(rawMarkdownFiles);
391+
382392
return allFiles;
383393
}
384394

@@ -426,4 +436,4 @@ export async function createGitHubSource(): Promise<
426436
return {
427437
files: [...allPages, ...fumadocMeta],
428438
};
429-
}
439+
}

lib/sources/local.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Source, VirtualFile } from "fumadocs-core/source";
22
import { compile, type CompiledPage } from "../compile-md";
33
import * as path from "node:path";
4+
import fs from 'fs';
45
import { getTitleFromFile } from "../source";
56
import { fumadocMeta } from "../meta";
67
import {
@@ -13,7 +14,7 @@ import {
1314
import FastGlob from "fast-glob";
1415
import { readFile } from "node:fs/promises";
1516

16-
const dir = "out/docs";
17+
const dir = "fi-plugins/docs";
1718

1819
export async function createLocalSource(): Promise<
1920
Source<{
@@ -31,7 +32,7 @@ export async function createLocalSource(): Promise<
3132
};
3233
}>
3334
> {
34-
const files = await FastGlob(`${dir}/**/*.{md,mdx,json,html}`);
35+
const files = await FastGlob(`${dir}/**/*.{md,mdx,json}`);
3536

3637
const pages = files.flatMap((file) => {
3738
const relativePath = path.relative(dir, file);
@@ -79,7 +80,7 @@ export async function createLocalSource(): Promise<
7980
const pagePath = `${repoSlug}/${version}/${getBaseFileName(fileName)}`;
8081

8182
console.debug(
82-
`Adding local page: ${pagePath} (title: ${getTitleFromFile(fileName)})`,
83+
`Read local page: ${pagePath} (title: ${getTitleFromFile(fileName)})`,
8384
);
8485

8586
return {
@@ -92,10 +93,10 @@ export async function createLocalSource(): Promise<
9293

9394
async load() {
9495
const content = await readFile(file);
95-
console.debug(
96-
`### Loaded content for ${pagePath}, content: `,
97-
content,
98-
);
96+
// console.debug(
97+
// `### Loaded content for ${pagePath}, content: `,
98+
// content,
99+
// );
99100
return compile(file, content.toString());
100101
},
101102
},
@@ -121,3 +122,24 @@ export async function createLocalSource(): Promise<
121122
files: [...pages, ...fumadocMeta],
122123
};
123124
}
125+
126+
127+
export async function buildMarkdownFileToLocal(files: Map<string,string>): Promise<void> {
128+
for (const [filePath, content] of files) {
129+
try {
130+
131+
const realPath = path.join(dir, filePath + ".md");
132+
console.info("Writing local file:", realPath);
133+
134+
// Ensure the directory exists before writing the file
135+
fs.mkdirSync(path.dirname(realPath), { recursive: true });
136+
137+
// Here you would write the markdown content to a local file
138+
fs.writeFileSync(realPath, content);
139+
// fs.writeFileSync(realPath, content, { encoding: "utf-8", mode: 0o644, flag: "w" });
140+
141+
} catch (error) {
142+
console.error(`Failed to write local file for ${filePath}:`, error);
143+
}
144+
}
145+
}

0 commit comments

Comments
 (0)