ForcePilot/web/src/utils/file_preview.js

19 lines
567 B
JavaScript
Raw Normal View History

const MARKDOWN_EXTENSIONS = new Set(['.md', '.markdown', '.mdx'])
export const getPreviewFileExtension = (path) => {
const normalizedPath = String(path || '')
.trim()
.toLowerCase()
if (!normalizedPath) return ''
const fileName = normalizedPath.split('/').pop() || ''
const dotIndex = fileName.lastIndexOf('.')
if (dotIndex <= 0) return ''
return fileName.slice(dotIndex)
}
export const isMarkdownPreview = (path, previewType) => {
if (previewType === 'markdown') return true
return MARKDOWN_EXTENSIONS.has(getPreviewFileExtension(path))
}