mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 23:49:51 +00:00
MDX: Change cache path of manifest files
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-mdx': patch
|
||||
---
|
||||
|
||||
Change cache path of manifest files
|
||||
@@ -8,7 +8,7 @@ import { findCollectionId } from '@/utils/find-collection';
|
||||
import { getConfigHash, loadConfigCached } from '@/config/cached';
|
||||
import { buildMDX } from '@/utils/build-mdx';
|
||||
import { getDefaultMDXOptions, type TransformContext } from '@/config';
|
||||
import { getKey } from '@/map/manifest';
|
||||
import { getManifestEntryPath } from '@/map/manifest';
|
||||
import { formatError } from '@/utils/format-error';
|
||||
import { getGitTimestamp } from './utils/git-timestamp';
|
||||
|
||||
@@ -154,7 +154,7 @@ export default async function loader(
|
||||
if (config.global?.generateManifest) {
|
||||
await fs.mkdir('.next/cache/fumadocs', { recursive: true });
|
||||
await fs.writeFile(
|
||||
path.resolve('.next/cache/fumadocs', `${getKey(filePath)}.json`),
|
||||
getManifestEntryPath(filePath),
|
||||
JSON.stringify({
|
||||
path: filePath,
|
||||
data: file.data,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import fs from 'node:fs';
|
||||
import { createHash } from 'node:crypto';
|
||||
import path from 'node:path';
|
||||
import { type LoadedConfig } from '@/config/load';
|
||||
import type { MetaFile } from '@/loader-mdx';
|
||||
@@ -11,8 +10,13 @@ export interface Manifest {
|
||||
})[];
|
||||
}
|
||||
|
||||
export function getKey(key: string): string {
|
||||
return createHash('sha256').update(key).digest('hex');
|
||||
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 {
|
||||
@@ -24,9 +28,7 @@ export function writeManifest(to: string, config: LoadedConfig): void {
|
||||
if (type === 'meta') continue;
|
||||
|
||||
try {
|
||||
const content = fs.readFileSync(
|
||||
path.resolve('.next/cache/fumadocs', `${getKey(file)}.json`),
|
||||
);
|
||||
const content = fs.readFileSync(getManifestEntryPath(file));
|
||||
const meta = JSON.parse(content.toString()) as MetaFile;
|
||||
|
||||
output.files.push({
|
||||
|
||||
Reference in New Issue
Block a user