19 lines
567 B
JavaScript
19 lines
567 B
JavaScript
|
|
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))
|
||
|
|
}
|