UNPKG

@mintlify/prebuild

Version:

Helpful functions for Mintlify's prebuild step

22 lines (21 loc) 1.06 kB
import fse from 'fs-extra'; import { readFile } from 'fs/promises'; import * as path from 'path'; export async function getCustomLanguages({ config, contentDirectoryPath, }) { const customLanguagesFilenames = typeof config.styling?.codeblocks === 'object' && config.styling.codeblocks.languages?.custom ? config.styling.codeblocks.languages.custom : []; if (customLanguagesFilenames.length === 0) { return []; } const customLanguages = await Promise.all(customLanguagesFilenames.map(async (filename) => { const filePath = path.join(contentDirectoryPath, filename); if (!fse.existsSync(filePath)) { console.error(`Custom language file "${filePath}" defined in docs.json is not found`); return undefined; } const customLanguage = await readFile(filePath, 'utf8'); return { content: customLanguage, filePath: filename }; })).then((customLanguages) => customLanguages.filter((customLanguage) => customLanguage !== undefined)); return customLanguages; }