diff --git a/README.md b/README.md index 5eefd44..e0bb2c5 100644 --- a/README.md +++ b/README.md @@ -23,4 +23,4 @@ Start the project: deno task start ``` -This will watch the project directory and restart as necessary. \ No newline at end of file +This will watch the project directory and restart as necessary. diff --git a/islands/ContentRenderer.tsx b/islands/ContentRenderer.tsx index e831976..bc12057 100644 --- a/islands/ContentRenderer.tsx +++ b/islands/ContentRenderer.tsx @@ -3,63 +3,67 @@ 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"]), -} + "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; - } + for (const [type, exts] of Object.entries(TypeToExt)) { + if (exts.has(ext)) { + return type; } - return "unknown"; + } + 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 "md": - return ; - case "code": - return
{content}
; - //case "csv": - // return ; - default: - return <>error: invalid type: {props.type} content: {content}; - } +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 "md": + return ; + case "code": + return ( +
{content}
+ ); + //case "csv": + // return ; + default: + return <>error: invalid type: {props.type} content: {content}; + } } -export function RenderView(props: {src: 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