49### Linking to the val
50
51These functions infer the val using the call stack or the request URL. If the inference isn't working, or if you want to ensure it links to a specific val, pass the `val` argument:
52
53- `modifyFetchHandler(handler, {val: { handle: "andre", name: "foo" }})`
5import ReactDOM from "https://esm.sh/react-dom";
6
7function Counter() {
8 const [counter, setCounter] = React.useState(0);
9
19}
20
21export function App() {
22 return (
23 <>
1export async function expressHTMLExample(
2 req: express.Request,
3 res: express.Response,
1import { BrowserContext } from "https://esm.town/v/pomdtr/browser";
2
3export default async function(ctx) {
4 return {
5 type: "open",
1import { parse } from "npm:parse5";
2
3/** function to discover a webmention endpoint */
4export default async function discover(source) {
5 // look for first Link in headers
6 let found = [];
25 let doc = parse(html);
26 let links = [];
27 (function walk(nodes) {
28 for (let n of nodes) {
29 if (n.childNodes) walk(n.childNodes);
51
52/** helper to extract a url from Link header value */
53function cleanHeader(src, h) {
54 let exp = /<([^>]*)>/;
55 let matches = h.match(exp);
69
70/** helper to extract a url from <link> tag href */
71function cleanTag(src, raw) {
72 // absolute path
73 if (raw.startsWith("/"))
4
5// formats date in SQLITE format YYYY-MM-DD
6function formatDate(date: string) {
7 let [month, day, year] = date.split("/");
8 if (month.length == 1) month = "0" + month;
12
13// insert newsletter metadata in sqlite
14async function insertRow(articleNumber: number, title: string, date: string) {
15 try {
16 await sqlite.execute({
24
25// check if newsletter id exists
26async function checkNewsletterPresent(articleNumber: number) {
27 const data = await sqlite.execute({
28 sql: `SELECT EXISTS(SELECT 1 FROM newsletter WHERE article_number=:articleNumber)`,
1export function myApi(data) {
2 return "hi " + data.name;
3}
3import { zip } from "npm:lodash-es";
4
5export async function dateMeRSS(req: Request) {
6 let { columns, rows } = await sqlite.execute(`select * from datemedocs order by LastUpdated desc limit 20`);
7 const profiles = rows.map(row =>
2import { valTownBlogJSON } from "https://esm.town/v/stevekrouse/valTownBlogJSON";
3
4export async function valTownBlogRSS() {
5 const json = await valTownBlogJSON();
6 return new Response(dataToRSS(
4import stripAnsi from "npm:strip-ansi";
5
6export default async function() {
7 const res = await db.execute(
8 "SELECT author_username, COUNT(*) AS val_count FROM vals GROUP BY author_username ORDER BY 2 DESC LIMIT 10",
Simple functional CSS library for Val Town
A helper function to build a file's email
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": "*",
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.