Search
valle_tmp_016298797667905655232930394407136
@janpaul123
@jsxImportSource https://esm.sh/react
HTTP
/** @jsxImportSource https://esm.sh/react */
import valleGetValsContextWindow from "https://esm.town/v/janpaul123/valleGetValsContextWindow";
import archiveVal from "https://esm.town/v/nbbaier/archiveVal?v=10";
import _ from "npm:lodash@4";
import OpenAI from "npm:openai";
import { renderToString } from "npm:react-dom/server";
// Set these to your own
const username = "janpaul123";
tomatoMarsupial
@westbrookdaniel
@jsxImportSource npm:react
HTTP
/** @jsxImportSource npm:react **/
import { renderToString } from "npm:react-dom@18/server";
export default (req: Request) => {
return new Response(
dotcom
@jxnblk
Overengineered personal site and blog built on Val Town. https://jxnblk.com I started rebuilding my site using Val Town with the intent to create a val that would fetch static HTML and commit to a GitHub repo to host with gh-pages.
After building the site out, I found that the performance seemed good enough – at least in the US – to host it directly on Val Town. How it works The old site still exists at on GitHub at jxnblk/blog and includes the source markdown files, build script, and static JSON API.
I experimented with storing JSON in Val Town storage, but for now, the site imports a static JSON file for content.
This content is passed to the App React component that includes the entire HTML and handles routing.
The component is rendered using ReactStream which can render React to stream in Val Town and hydrate the component in the browser.
For performance reasons, I'm not using React on the client, but using small vanilla JS scripts to handle color modes. ReactStream also accepts middleware, and this site uses middleware to: Record server analytics in Val Town SQLite Respond to /robots.txt Handle redirects Generate an /rss.xml file Pass the blog content as props to the App component Set cache headers The favicon, avatar image, and OG images are also built in Val Town.
The avatar val exports an Avatar React component that's used in the site and
exposes an image service at https://jxnblk-avatar.web.val.run/ that accepts search parameters.
This image service is used for the site's favicon.
The blogOGImage val is used to generate PNG OG images from SVG and take search parameters to make dynamic
images for each blog post. Styling is handled by importing CSS from JxnblkCSS and rendering an inline <style> tag in the HTML head.
I experimented with some other approaches, but this seemed to be the simplest solution. What's next There are still some content issues in the markdown that need to be updated for the new site and there are likely bugs to fix.
If you spot anything, you can leave a comment on this val below.
I experimented with a few different approaches and plan to consolidate JxnblkApp and this val and clean up some of the structure of the site. I started building out a custom Reddit embed widget to help with front-end performance, but it's buggy and needs some work.
I'd also like to build a custom Val Town embed widget to add custom demo vals to future posts, but that's still a work in progress. Let me know what you think of the site so far, and if you have any ideas on how to make this better, I'd love to hear them!
HTTP
This content is passed to the [App][JxnblkApp] React component that includes the entire HTML and handles routing.
The component is rendered using [ReactStream][] which can render React to stream in Val Town and hydrate the component in the browser.
For performance reasons, I'm not using React on the client, but using small [vanilla JS scripts][jxnblkioVanillaJS] to handle color modes.
ReactStream also accepts middleware, and this site uses middleware to:
The [avatar][] val exports an `Avatar` React component that's used in the site and
[ReactStream]: https://val.town/v/jxnblk/ReactStream
/** @jsxImportSource https://esm.sh/react@18.3.1 */
import React from "https://esm.sh/react@18.3.1";
import { useMemo, useState } from "https://esm.sh/react@18.3.1";
import { DataRequest, render, robots } from "https://esm.town/v/jxnblk/ReactStream";
sqliteExplorerApp
@wilt
SQLite Explorer View and interact with your Val Town SQLite data. It's based off Steve's excellent SQLite Admin val, adding the ability to run SQLite queries directly in the interface. This new version has a revised UI and that's heavily inspired by LibSQL Studio by invisal . This is now more an SPA, with tables, queries and results showing up on the same page. Install Install the latest stable version (v86) by forking this val: Authentication Login to your SQLite Explorer with password authentication with your Val Town API Token as the password. Todos / Plans [ ] improve error handling [ ] improve table formatting [ ] sticky table headers [x] add codemirror [ ] add loading indication to the run button (initial version shipped) [ ] add ability to favorite queries [ ] add saving of last query run for a table (started) [ ] add visible output for non-query statements [ ] add schema viewing [ ] add refresh to table list sidebar after CREATE/DROP/ALTER statements [ ] add automatic execution of initial select query on double click [x] add views to the sidebar [ ] add triggers to sidebar [ ] add upload from SQL, CSV and JSON [ ] add ability to connect to a non-val town Turso database [x] fix wonky sidebar separator height problem (thanks to @stevekrouse) [x] make result tables scrollable [x] add export to CSV, and JSON (CSV and JSON helper functions written in this val . Thanks to @pomdtr for merging the initial version!) [x] add listener for cmd+enter to submit query
HTTP
- [ ] add schema viewing
- [ ] add refresh to table list sidebar after `CREATE/DROP/ALTER` statements
- [ ] add automatic execution of initial select query on double click
- [x] add views to the sidebar
- [ ] add triggers to sidebar
- [ ] add upload from SQL, CSV and JSON
- [ ] add ability to connect to a non-val town Turso database
- [x] fix wonky sidebar separator height problem (thanks to @stevekrouse)
- [x] make result tables scrollable
return c.render(
<main class="sidebar-layout">
<div class="sidebar">
<TablesList tables={[...tables, ...views]}></TablesList>
<Separator direction="horizontal"></Separator>
<div class="not-sidebar">
<EditorSection />
pioneeringAzurePenguin
@saadstore
@jsxImportSource https://esm.sh/react@18.2.0
HTTP
/** @jsxImportSource https://esm.sh/react@18.2.0 */
import React, { useState } from "https://esm.sh/react@18.2.0";
import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
const mockVideos = [
</div>
function client() {
createRoot(document.getElementById("root")).render(<App />);
if (typeof document !== "undefined") { client(); }
export default async function server(request: Request): Promise<Response> {
preactTest
@neverstew
An interactive, runnable TypeScript val by neverstew
HTTP
export const preactTest = async () => {
const { useState, h, htm, renderToString } = await import(
"https://npm.reversehttp.com/preact,htm,preact/hooks,preact-render-to-string"
const html = htm.bind(h);
function Component() {
reactExample
@johndevor
asdfasdf
HTTP
/** @jsxImportSource https://esm.sh/react@18.2.0 */
import { renderToString } from "npm:react-dom@18.2.0/server";
export const reactExample = (request: Request) =>
new Response(renderToString(<div>Test {1 + 31111}</div>), {
HTMXQuill
@rayman
@jsxImportSource https://esm.sh/preact
HTTP
/** @jsxImportSource https://esm.sh/preact */
import { render } from "npm:preact-render-to-string";
// import Quill from "npm:quill";
export default async function(req: Request) {
chocolateCanid
@willthereader
ChatGPT Implemented in Val Town Demonstrated how to use assistants and threads with the OpenAI SDK and how to stream the response with Server-Sent Events.
HTTP
/** @jsxImportSource https://esm.sh/react */
import { OpenAI } from "https://esm.town/v/std/openai";
import { Hono } from "npm:hono@3";
import { renderToString } from "npm:react-dom/server";
const openai = new OpenAI();
return new Response(renderToString(jsx), { headers: { "Content-Type": "text/html" } });
const clientCode = () => {
document.getElementById("input").addEventListener("submit", async function(event) {
</form>
<script dangerouslySetInnerHTML={{ __html: `(${clientCode.toString()})()` }}>
</script>
valle_tmp_54185991019187464068579562776686
@janpaul123
@jsxImportSource https://esm.sh/react
HTTP
/** @jsxImportSource https://esm.sh/react */
import valleGetValsContextWindow from "https://esm.town/v/janpaul123/valleGetValsContextWindow";
import archiveVal from "https://esm.town/v/nbbaier/archiveVal?v=10";
import _ from "npm:lodash@4";
import OpenAI from "npm:openai";
import { renderToString } from "npm:react-dom/server";
// Set these to your own
const username = "janpaul123";
wide
@maxm
WIDE Store any unstructured JSON data. Retrieve it with an expressive and efficient query system. WIDE is a library and service hosted on Val Town. Authenticate and use it with your Val Town credentials, or fork it and connect it to your own Clickhouse Instance. import { ValSession } from 'https://esm.town/v/maxm/valSession';
import { Wide } from 'https://esm.town/v/maxm/wide';
// Use your Val Town API Token to create a session
const wide = new Wide(await ValSession.new(Deno.env.get("valtown")))
// Write any data.
await wide.write([
{ user: {id: 1, name: 'Alice', email: 'alice@example.com' }},
{ user: {id: 2, name: 'Bob', email: 'bob@example.com' }},
{ user: {id: 3, name: 'Charlie', email: 'charlie@example.com' }},
]);
await wide.fields("user.")
// => [
// { fieldName: "user.email", fieldType: "string", count: 3 },
// { fieldName: "user.id", fieldType: "number", count: 3 },
// { fieldName: "user.name", fieldType: "string", count: 3 }
// ]
await wide.values("user.email")
// [
// { value: "bob@example.com", count: 1 },
// { value: "charlie@example.com", count: 1 },
// { value: "alice@example.com", count: 1 }
// ]
await wide.search({
start: new Date(Date.now() - 1000 * 60 * 10),
end: new Date(),
filters: [{ fieldName: "user.name", operator: "equals", value: "Alice" }],
})
// [{ user: { name: "Alice", email: "alice@example.com", id: 1 } }];
HTTP
import { hc } from "npm:hono/client";
const _client = hc<WideApi>("https://maxm-wideapi.web.val.run/");
#client: typeof _client;
// TODO: can we use a global client?
this.#client = hc<WideApi>("https://maxm-wideapi.web.val.run/");
const resp = await this.#client.v1.fields.$get({
const resp = await this.#client.v1.write.$post({
const resp = await this.#client.v1.search.$get({
const fieldsResp = await this.#client.v1.fields.$get({
const resp = await this.#client.v1.values.$get({
remark
@stevekrouse
@jsxImportSource https://esm.sh/preact
Script
/** @jsxImportSource https://esm.sh/preact */
import { render } from "npm:preact-render-to-string";
export const remark = ({ title, content }) => async (req: Request) =>
new Response(
linkInBioTemplate
@saludes
@jsxImportSource https://esm.sh/react
HTTP
/** @jsxImportSource https://esm.sh/react */
import { renderToString } from "npm:react-dom/server";
export default async function(req: Request) {
return new Response(
virtuousBlackAnt
@spedrox
@jsxImportSource https://esm.sh/react@18.2.0
HTTP
/** @jsxImportSource https://esm.sh/react@18.2.0 **/
import { renderToString } from "https://esm.sh/react-dom@18.2.0/server";
export default (req: Request) => {
return new Response(
contrast_swatch
@jxnblk
@jsxImportSource https://esm.sh/preact
HTTP
/** @jsxImportSource https://esm.sh/preact */
import { Color } from "https://deno.land/x/color/mod.ts";
import { render } from "https://deno.land/x/resvg_wasm/mod.ts";
import { render as preact } from "npm:preact-render-to-string";
const HEXRE = /^[A-Fa-f0-9]{3,6}$/;
const text = data.contrast.toFixed(2);
const svg = preact(
<svg