mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 23:49:51 +00:00
MDX: Deprecate generateManifest option: use a route handler to export build time information
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-mdx': minor
|
||||
---
|
||||
|
||||
Deprecate `generateManifest` option: use a route handler to export build time information
|
||||
@@ -3,6 +3,10 @@ title: Manifest
|
||||
description: Generate manifest for production builds
|
||||
---
|
||||
|
||||
<Callout type="warn" title="Deprecated">
|
||||
Use a route handler to export build time information instead.
|
||||
</Callout>
|
||||
|
||||
## Usage
|
||||
|
||||
Enable it from global config.
|
||||
|
||||
@@ -20,6 +20,7 @@ export interface GlobalConfig {
|
||||
* Generate manifest file on build mode
|
||||
*
|
||||
* @defaultValue false
|
||||
* @deprecated No longer needed, use a route handler to export build time info
|
||||
*/
|
||||
generateManifest?: boolean;
|
||||
}
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
export * from './runtime';
|
||||
export type { Manifest } from './map/manifest';
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import * as path from 'node:path';
|
||||
import * as fs from 'node:fs/promises';
|
||||
import { parse } from 'node:querystring';
|
||||
import grayMatter from 'gray-matter';
|
||||
import { type LoaderContext } from 'webpack';
|
||||
import { type StructuredData } from 'fumadocs-core/mdx-plugins';
|
||||
import { getConfigHash, loadConfigCached } from '@/config/cached';
|
||||
import { buildMDX } from '@/utils/build-mdx';
|
||||
import { getManifestEntryPath } from '@/map/manifest';
|
||||
import { formatError } from '@/utils/format-error';
|
||||
import { getGitTimestamp } from './utils/git-timestamp';
|
||||
|
||||
@@ -129,17 +127,6 @@ export default async function loader(
|
||||
);
|
||||
|
||||
callback(undefined, String(file.value), file.map ?? undefined);
|
||||
|
||||
if (config.global?.generateManifest) {
|
||||
await fs.mkdir('.next/cache/fumadocs', { recursive: true });
|
||||
await fs.writeFile(
|
||||
getManifestEntryPath(filePath),
|
||||
JSON.stringify({
|
||||
path: filePath,
|
||||
data: file.data,
|
||||
} as MetaFile),
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
if (!(error instanceof Error)) throw error;
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import { readFile, writeFile } from 'node:fs/promises';
|
||||
import grayMatter from 'gray-matter';
|
||||
import { getConfigHash, loadConfigCached } from '@/config/cached';
|
||||
import { generateJS, generateTypes } from '@/map/generate';
|
||||
import { writeManifest } from '@/map/manifest';
|
||||
|
||||
/**
|
||||
* Start a MDX server that builds index and manifest files.
|
||||
@@ -18,7 +17,6 @@ export async function start(
|
||||
): Promise<void> {
|
||||
let configHash = await getConfigHash(configPath);
|
||||
let config = await loadConfigCached(configPath, configHash);
|
||||
const manifestPath = path.resolve(outDir, 'manifest.json');
|
||||
const jsOut = path.resolve(outDir, `index.js`);
|
||||
const typeOut = path.resolve(outDir, `index.d.ts`);
|
||||
|
||||
@@ -91,11 +89,4 @@ export async function start(
|
||||
void instance.close();
|
||||
});
|
||||
}
|
||||
|
||||
if (config.global?.generateManifest && !dev) {
|
||||
process.on('exit', () => {
|
||||
console.log('[MDX] writing manifest');
|
||||
writeManifest(manifestPath, config);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
import { type LoadedConfig } from '@/config/load';
|
||||
import type { MetaFile } from '@/loader-mdx';
|
||||
import { getTypeFromPath } from '@/utils/get-type-from-path';
|
||||
|
||||
export interface Manifest {
|
||||
files: (MetaFile & {
|
||||
collection: string;
|
||||
})[];
|
||||
}
|
||||
|
||||
export function getManifestEntryPath(originalPath: string): string {
|
||||
const toName = path
|
||||
.relative(process.cwd(), originalPath)
|
||||
.replaceAll(`..${path.sep}`, '-')
|
||||
.replaceAll(path.sep, '_');
|
||||
|
||||
return path.resolve('.next/cache/fumadocs', `${toName}.json`);
|
||||
}
|
||||
|
||||
export function writeManifest(to: string, config: LoadedConfig): void {
|
||||
const output: Manifest = { files: [] };
|
||||
|
||||
for (const [file, collection] of config._runtime.files.entries()) {
|
||||
const type =
|
||||
config.collections.get(collection)?.type ?? getTypeFromPath(file);
|
||||
if (type === 'meta') continue;
|
||||
|
||||
try {
|
||||
const content = fs.readFileSync(getManifestEntryPath(file));
|
||||
const meta = JSON.parse(content.toString()) as MetaFile;
|
||||
|
||||
output.files.push({
|
||||
...meta,
|
||||
collection,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(`cannot find the search index of ${file}`, e);
|
||||
}
|
||||
}
|
||||
|
||||
fs.writeFileSync(to, JSON.stringify(output));
|
||||
}
|
||||
Reference in New Issue
Block a user