diff --git a/src/components/Type.tsx b/src/components/Type.tsx index 4271d71..1f33642 100644 --- a/src/components/Type.tsx +++ b/src/components/Type.tsx @@ -1,3 +1,4 @@ +import exts from 'lib/exts'; import { Alert, Box, @@ -55,10 +56,11 @@ export default function Type({ file, popup = false, disableMediaPreview, ...prop const [text, setText] = useState(''); const shouldRenderMarkdown = file.name.endsWith('.md'); const shouldRenderTex = file.name.endsWith('.tex'); + const shouldRenderCode: boolean = Object.keys(exts).includes(file.name.split('.').pop()); const [loading, setLoading] = useState(type === 'text' && popup); - if (type === 'text' && popup) { + if ((type === 'text' || shouldRenderMarkdown || shouldRenderTex || shouldRenderCode) && popup) { useEffect(() => { (async () => { const res = await fetch('/r/' + file.name); @@ -86,13 +88,16 @@ export default function Type({ file, popup = false, disableMediaPreview, ...prop ); }; - if ((shouldRenderMarkdown || shouldRenderTex) && !props.overrideRender && popup) + if ((shouldRenderMarkdown || shouldRenderTex || shouldRenderCode) && !props.overrideRender && popup) return ( <> {renderAlert()} {shouldRenderMarkdown && } {shouldRenderTex && } + {shouldRenderCode && !(shouldRenderTex || shouldRenderMarkdown) && ( + + )} ); @@ -115,14 +120,14 @@ export default function Type({ file, popup = false, disableMediaPreview, ...prop return popup ? ( media ? ( { - video: