UNPKG

@mintlify/common

Version:

Commonly shared code within Mintlify

67 lines (66 loc) 1.75 kB
import { parse } from 'path'; const excludedMdFiles = ['readme', 'license', 'contributing', 'contribute']; const supportedStaticFileExtensions = [ '.jpeg', '.jpg', '.jfif', '.pjpeg', '.pjp', '.png', '.svg', '.svgz', '.ico', '.webp', '.gif', '.apng', '.avif', '.bmp', '.mp4', ]; export const getFileCategory = (filePath) => { filePath = filePath.toLowerCase(); const parsed = parse(filePath); if (parsed.base === 'mint.json') { return 'mintConfig'; } if (parsed.base === 'docs.json') { return 'docsConfig'; } const fileName = parsed.name; const extension = parsed.ext; if ((filePath.startsWith('_snippets/') || filePath.startsWith('snippets/')) && (extension === '.mdx' || extension === '.md')) { if (filePath.startsWith('_snippets/')) { return 'snippet'; } else if (filePath.startsWith('snippets/')) { return 'snippet-v2'; } } else if (extension === '.mdx') { return 'page'; } else if (extension === '.md') { // Exclude common markdown files people don't want on their docs website if (excludedMdFiles.includes(fileName)) { return null; } return 'page'; } else if (extension === '.yaml' || extension === '.yml') { return 'potentialYamlOpenApiSpec'; } else if (extension === '.json') { return 'potentialJsonOpenApiSpec'; } else if (extension === '.css') { return 'css'; } else if (extension === '.js') { return 'js'; } else if (supportedStaticFileExtensions.includes(extension)) { return 'staticFile'; } return null; };