1export default async function (req: Request): Promise<Response> {
2 console.log("test");
3 return new Response(
2import type { ReactNode } from "npm:react@18.2.0";
3
4export function Layout({ children }: { children: ReactNode }) {
5 return (
6 <html lang="en">
5import { Layout } from "./Layout.tsx";
6
7function PostComponent({ markdown, link }: { markdown: string; link?: string }) {
8 return (
9 <div style={{ border: "1px solid gray", padding: "10px", marginBottom: "20px", borderRadius: "5px" }}>
14}
15
16export default async function(req: Request): Promise<Response> {
17 const url = new URL(req.url);
18 if (url.pathname === "/") {
44}
45
46function html(children: React.ReactNode) {
47 return new Response(
48 renderToString(
10});
11
12export default async function(req: Request): Promise<Response> {
13 const searchParams = new URL(req.url).searchParams;
14 const to = searchParams.get("to");
13
14// Parse frontmatter from markdown content
15function parseFrontmatter(content: string) {
16 const frontmatterRegex = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/;
17 const match = content.match(frontmatterRegex);
43
44// Get all blog posts
45async function getAllPosts() {
46 const files = await listFiles(import.meta.url);
47 const postFiles = files.filter(file => file.startsWith('/posts/') && file.endsWith('.md'));
65
66// Get a single blog post by slug
67async function getPost(slug: string) {
68 try {
69 const content = await readFile(`/posts/${slug}.md`, import.meta.url);
72
73 // Parse the current route
74 function parseRoute() {
75 const path = window.location.pathname;
76
109
110 // Show the list of posts
111 async function showPostList() {
112 const appElement = document.getElementById('app');
113
143
144 // Show a single post
145 async function showPost(params) {
146 const appElement = document.getElementById('app');
147 appElement.innerHTML = `
201
202 // Add event listeners to internal links
203 function addLinkEventListeners() {
204 document.querySelectorAll('a').forEach(link => {
205 const href = link.getAttribute('href');
216
217 // Navigate to a new route
218 function navigateTo(path) {
219 window.history.pushState({}, '', path);
220 handleRouteChange();
222
223 // Handle route changes
224 function handleRouteChange() {
225 const { handler, params } = parseRoute();
226 handler(params);
2import process from "node:process";
3
4export default async function server(request: Request): Promise<Response> {
5 await sodium.ready;
6
33- [x] fix wonky sidebar separator height problem (thanks to @stevekrouse)
34- [x] make result tables scrollable
35- [x] add export to CSV, and JSON (CSV and JSON helper functions written in [this val](https://www.val.town/v/nbbaier/sqliteExportHelpers). Thanks to @pomdtr for merging the initial version!)
36- [x] add listener for cmd+enter to submit query
37
15
16```javascript
17function hello() {
18 console.log("Hello, world!");
19}
82});
83
84// Helper function to list blog posts
85async function listBlogPosts() {
86 try {
87 const posts = [];
106}
107
108// Helper function to get a blog post by slug
109async function getBlogPost(slug: string) {
110 try {
111 const filePath = `/content/posts/${slug}.md`;
133}
134
135// Helper function to parse frontmatter
136function parseFrontmatter(content: string) {
137 const frontmatterRegex = /^---\s*([\s\S]*?)\s*---\s*([\s\S]*)$/;
138 const match = content.match(frontmatterRegex);
A helper function to build a file's email
Simple functional CSS library for Val Town
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",