simple-fs-server/routes/doc/index.tsx

35 lines
1.0 KiB
TypeScript
Raw Normal View History

2023-02-15 00:04:09 +09:00
import { Head, asset } from "$fresh/runtime.ts";
2023-01-14 03:03:22 +09:00
import { HandlerContext, Handlers, PageProps, Status } from "$fresh/server.ts";
2023-01-05 18:18:07 +09:00
import DocSearch from "../../islands/DocSearch.tsx";
import { Doc } from "../../src/collect.ts";
import { docCollector } from "../../src/store/doc.ts";
async function GET(req: Request, ctx: HandlerContext): Promise<Response> {
2023-01-14 03:03:22 +09:00
const url = new URL(req.url);
if (url.pathname.endsWith("/")) {
url.pathname = url.pathname.slice(0, -1);
return Response.redirect(url, Status.TemporaryRedirect);
2023-01-06 18:24:27 +09:00
}
const docs = docCollector.getDocs();
return await ctx.render({ docs });
2023-01-05 18:18:07 +09:00
}
export const handler: Handlers = {
2023-01-06 18:24:27 +09:00
GET,
};
2023-01-05 18:18:07 +09:00
2023-01-06 18:24:27 +09:00
export default function Docs(props: PageProps<{ docs: Doc[] }>) {
const { docs } = props.data;
2023-01-05 18:18:07 +09:00
return (
<>
<Head>
<title>Simple file server - Doc</title>
2023-02-15 00:04:09 +09:00
<link rel="stylesheet" href={asset("/base.css")} />
2023-01-05 18:18:07 +09:00
</Head>
<div class="p-4 mx-auto max-w-screen-md">
<DocSearch docs={docs}></DocSearch>
</div>
</>
);
2023-01-06 18:24:27 +09:00
}