import { Hono } from "https://deno.land/x/hono@v4.0.6/mod.ts";
import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo?v=25";
import { htmlResponse } from "https://esm.town/v/postpostscript/html";
import { html } from "https://esm.town/v/postpostscript/htmlComponentLibrary";
import { Layout } from "https://esm.town/v/postpostscript/Layout";
import { MyFooter } from "https://esm.town/v/postpostscript/MyFooter";
import { readmeMarkdown, readmeMarkdownPage } from "https://esm.town/v/postpostscript/readmeMarkdown";
const app = new Hono();
const { author, slug, httpEndpoint } = extractValInfo(import.meta.url);
app.get("/", (c) => {
return app.fetch(new Request(`${httpEndpoint}/blog`));
});
app.get("/:name", async (c) => {
const url = `@${author}/${c.req.param("name")}`;
const [md, footer] = await Promise.all([
readmeMarkdown(url),
MyFooter(),
]);
let index;
if (url !== "@postpostscript/blog") {
index = html`<p><a href="/">back to index</a></p>`;
}
return htmlResponse`
${
Layout({
title: `${url}`,
val: {
handle: author,
name: c.req.param("name"),
},
}, {
default: () =>
html`<main>${index}${md}<p><a href="https://postpostscript-readmemanager.web.val.run/${
url.slice(1)
}">view page source</a></p><br></main>${footer}`,
})
}
`;
});
export default app.fetch;