import { extname } from "path/posix.ts"; import MarkdownRenderer from "./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(() => { fetch(src).then((res) => res.text()).then(setContent); }, [src]); switch (props.type) { case "text": return
{content}
);
//case "csv":
// return