import { extname } from "path/posix.ts"; import MarkdownRenderer from "../components/MarkdownRenderer.tsx"; import { useEffect, useState } from "preact/hooks"; const TypeToExt = { "image": new Set([".png", ".jpg", ".jpeg", ".gif", ".svg"]), "video": new Set([".mp4", ".webm", ".ogg"]), "audio": new Set([".mp3", ".wav", ".flac"]), "md": new Set([".md"]), "text": new Set([".txt"]), "code": new Set([".json", ".js", ".ts", ".css", ".tsx", ".jsx"]), }; function extToType(ext: string) { for (const [type, exts] of Object.entries(TypeToExt)) { if (exts.has(ext)) { return type; } } return "unknown"; } function FetchAndRender(props: { src: string; type: string }) { const src = props.src; const ext = extname(src); const [content, setContent] = useState(""); useEffect(() => { (async () => { const res = await fetch(src); const content = await res.text(); setContent(content); })(); }, [src]); switch (props.type) { case "text": return
{content}
; case "md": return ; case "code": return (
{content}
); //case "csv": // return ; default: return

error: invalid type: {props.type} content: {content}

; } } export function RenderView(props: { src: string; mdbase?: string }) { const src = props.src; const type = extToType(extname(src)); switch (type) { case "text": case "md": case "code": return ; //case "csv": // return ; case "image": return ; case "video": return