9 const buttons = [csvBtn, jsonBtn, runBtn];
10
11 function checkForText() {
12 if (editor.view.state.doc.toString().trim() === "") {
13 buttons.forEach(btn => btn.disabled = true);
25 });
26
27 document.addEventListener("DOMContentLoaded", function() {
28 // Initial check
29 checkForText();
3const iconSize = "1.125rem";
4
5export function RunSVG() {
6 return (
7 <svg
22}
23
24export function TableSVG() {
25 return (
26 <svg
41}
42
43export function ViewSVG() {
44 return (
45 <svg
10 * @param val Define which val should open. Defaults to the root reference.
11 */
12export function modifyHtmlString(
13 bodyText: string,
14 { val, style }: { val?: ValRef; style?: string } = {},
41 * @param val Define which val should open
42 */
43export function modifyFetchHandler(
44 handler: (req: Request) => Response | Promise<Response>,
45 { val, style }: { val?: ValRef; style?: string } = {},
54
55export const honoMiddleware = (options: { val?: ValRef; style?: string } = {}): MiddlewareHandler => {
56 return async function(c, next) {
57 await next();
58 if (c.res.headers.get("Content-Type")?.startsWith("text/html")) {
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}
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": "*",