Fork
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
48
49
50
import { extractMetadata } from "https://esm.town/v/nbbaier/extractMetadata";
import getPosts from "https://esm.town/v/nbbaier/getPosts";
import { gfm } from "https://esm.town/v/nbbaier/gfm";
import { stripMetadata } from "https://esm.town/v/nbbaier/stripFrontmatter";
import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
import { fetch } from "https://esm.town/v/std/fetch?v=4";
import { Hono } from "npm:hono";
const app = new Hono();
const homepage = extractValInfo(import.meta.url);
const repo = "nbbaier/tidal-triaxial";
const content = "posts";
const apiUrl = `https://api.github.com/repos/${repo}/contents/${content}`;
const contentUrl = `https://raw.githubusercontent.com/${repo}/main/${content}`;
const editUrl = `https://github.com/${repo}/edit/main/${content}`;
app.get("/", async c => {
const posts = await getPosts(
apiUrl,
Deno.env.get("GH_BLOG_TOKEN"),
);
const items = await Promise.all(posts.map(async (post) => {
const data = await fetch(post.url);
const title = await extractMetadata("title", await data.text());
const segments = new URL(post.url).pathname.split("/").filter(Boolean);
const slug = segments[segments.length - 1].replace(".md", "");
return `- [${title}](/posts/${slug})`;
}));
const md = `# ${homepage.author}'s blog
A proof of concept blog inspired by [pomdtr's](url) [Val Town Blog](https://www.val.town/u/pomdtr). The infrastructure for the blog is hosted on [val.town](https://www.val.town),
while the content is hosted on github in [this repo](https://github.com/nbbaier/tidal-triaxial).
## Posts
${items.join("\n")}
`;
return c.html(await gfm(md));
});
app.get("/posts/:title", async c => {
const title = c.req.param("title");
const res = await fetch(`${contentUrl}/${title}.md`);
const md = await stripMetadata(await res.text());
return c.html(await gfm(md));
});
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.