diff --git a/islands/MarkdownRenderer.tsx b/components/MarkdownRenderer.tsx similarity index 69% rename from islands/MarkdownRenderer.tsx rename to components/MarkdownRenderer.tsx index 877ab67..3fa3523 100644 --- a/islands/MarkdownRenderer.tsx +++ b/components/MarkdownRenderer.tsx @@ -5,13 +5,17 @@ export function MarkdownRenderer(props: { text: string | undefined }) { if (text === undefined) { text = ""; } - const index = text.indexOf("\n---", 3); - const c = text.slice(index + 4, text.length); + let c = text; + if (text.startsWith("---")) { + const index = text.indexOf("\n---", 3); + c = text.slice(index + 4, text.length); + } return (
+ > +
); } diff --git a/fresh.gen.ts b/fresh.gen.ts index 4f5d92f..67451cb 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -5,34 +5,29 @@ import config from "./deno.json" assert { type: "json" }; import * as $0 from "./routes/_404.tsx"; import * as $1 from "./routes/_middleware.ts"; -import * as $2 from "./routes/api/doc.ts"; -import * as $3 from "./routes/api/login.ts"; -import * as $4 from "./routes/api/logout.ts"; -import * as $5 from "./routes/dir/[...path].tsx"; -import * as $6 from "./routes/doc/index.tsx"; -import * as $7 from "./routes/fs/[...path].ts"; -import * as $8 from "./routes/index.tsx"; -import * as $9 from "./routes/login.tsx"; +import * as $2 from "./routes/api/login.ts"; +import * as $3 from "./routes/api/logout.ts"; +import * as $4 from "./routes/dir/[...path].tsx"; +import * as $5 from "./routes/doc/index.tsx"; +import * as $6 from "./routes/index.tsx"; +import * as $7 from "./routes/login.tsx"; import * as $$0 from "./islands/ContentRenderer.tsx"; import * as $$1 from "./islands/Counter.tsx"; import * as $$2 from "./islands/DirList.tsx"; import * as $$3 from "./islands/DocSearch.tsx"; import * as $$4 from "./islands/FileViewer.tsx"; -import * as $$5 from "./islands/MarkdownRenderer.tsx"; -import * as $$6 from "./islands/UpList.tsx"; +import * as $$5 from "./islands/UpList.tsx"; const manifest = { routes: { "./routes/_404.tsx": $0, "./routes/_middleware.ts": $1, - "./routes/api/doc.ts": $2, - "./routes/api/login.ts": $3, - "./routes/api/logout.ts": $4, - "./routes/dir/[...path].tsx": $5, - "./routes/doc/index.tsx": $6, - "./routes/fs/[...path].ts": $7, - "./routes/index.tsx": $8, - "./routes/login.tsx": $9, + "./routes/api/login.ts": $2, + "./routes/api/logout.ts": $3, + "./routes/dir/[...path].tsx": $4, + "./routes/doc/index.tsx": $5, + "./routes/index.tsx": $6, + "./routes/login.tsx": $7, }, islands: { "./islands/ContentRenderer.tsx": $$0, @@ -40,8 +35,7 @@ const manifest = { "./islands/DirList.tsx": $$2, "./islands/DocSearch.tsx": $$3, "./islands/FileViewer.tsx": $$4, - "./islands/MarkdownRenderer.tsx": $$5, - "./islands/UpList.tsx": $$6, + "./islands/UpList.tsx": $$5, }, baseUrl: import.meta.url, config, diff --git a/islands/ContentRenderer.tsx b/islands/ContentRenderer.tsx index bc12057..adaade2 100644 --- a/islands/ContentRenderer.tsx +++ b/islands/ContentRenderer.tsx @@ -1,5 +1,5 @@ import { extname } from "path/posix.ts"; -import MarkdownRenderer from "./MarkdownRenderer.tsx"; +import MarkdownRenderer from "../components/MarkdownRenderer.tsx"; import { useEffect, useState } from "preact/hooks"; const TypeToExt = { @@ -25,8 +25,13 @@ function FetchAndRender(props: { src: string; type: string }) { const ext = extname(src); const [content, setContent] = useState(""); useEffect(() => { - fetch(src).then((res) => res.text()).then(setContent); + (async () => { + const res = await fetch(src); + const content = await res.text(); + setContent(content); + })(); }, [src]); + switch (props.type) { case "text": return
{content}
; @@ -41,7 +46,7 @@ function FetchAndRender(props: { src: string; type: string }) { //case "csv": // return ; default: - return <>error: invalid type: {props.type} content: {content}; + return

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

; } } @@ -62,7 +67,7 @@ export function RenderView(props: { src: string }) { case "audio": return