import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
import { gfm } from "https://esm.town/v/pomdtr/gfm";
import { readme } from "https://esm.town/v/pomdtr/readme";
import { Hono } from "npm:hono@3.11.11";
const script = (esmUrl) =>
`#!/bin/sh
# check if deno is installed
if ! command -v deno >/dev/null; then
echo "Please install deno first: https://deno.land/#installation"
exit 1
fi
exec deno eval --quiet --reload=https://esm.town/v/ '(await import("${esmUrl}")).default()' "$@"
`;
const app = new Hono();
app.get("/", async c => {
const html = await gfm(await readme());
return c.html(html);
});
app.get("/v/:author/:name", c => {
const { author, name } = c.req.param();
const { version } = c.req.query();
let esmUrl = `https://esm.town/v/${author}/${name}`;
if (version) {
esmUrl = `${esmUrl}?version=${version}`;
}
return new Response(script(esmUrl));
});
export default app.fetch;