-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathpreprocessContent.ts
More file actions
33 lines (28 loc) · 934 Bytes
/
preprocessContent.ts
File metadata and controls
33 lines (28 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Settings } from '../../types/index.js';
import { preprocessMdx } from './preprocess/mdx.js';
import { preprocessMintlify } from './preprocess/mintlify.js';
import sanitizeFileContent from '../../utils/sanitizeFileContent.js';
/**
* Preprocesses file content before upload. Returns the processed content,
* or { skip: reason } if the file should be skipped.
*/
export function preprocessContent(
content: string,
filePath: string,
fileType: string,
settings: Settings
): string | { skip: string } {
let result = content;
// File-type-specific
if (fileType === 'mdx') {
const skipReason = preprocessMdx(result, filePath, settings);
if (skipReason) return { skip: skipReason };
}
// Framework-specific
if (settings.framework === 'mintlify') {
result = preprocessMintlify(result, filePath, fileType, settings);
}
// Universal
result = sanitizeFileContent(result);
return result;
}