Public
HTTP (deprecated)
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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;
postpostscript-blog.web.val.run
March 16, 2024