andreterron avatar
andreterron
codeOnValTown
Script
Code on Val Town Adds a "Code on Val Town" ribbon to your page. This lets your website visitors navigate to the code behind it. This uses github-fork-ribbon-css under the hood. Usage Here are 2 different ways to add the "Code on Val Town" ribbon: 1. Wrap your fetch handler (recommended) import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=50"; import { html } from "https://esm.town/v/stevekrouse/html?v=5"; export default modifyFetchHandler(async (req: Request): Promise<Response> => { return html(`<h2>Hello world!</h2>`); }); Example: @andreterron/openable_handler 2. Wrap your HTML string import { modifyHtmlString } from "https://esm.town/v/andreterron/codeOnValTown?v=50"; import { html } from "https://esm.town/v/stevekrouse/html?v=5"; export default async (req: Request): Promise<Response> => { return html(modifyHtmlString(`<h2>Hello world!</h2>`)); }; Example: @andreterron/openable_html Other ways We made sure this was very modular, so you can also add the ribbon using these methods: Get the element string directly: @andreterron/codeOnVT_ribbonElement Modify an HTTP Response: @andreterron/codeOnVT_modifyResponse Use .pipeThrough to append to a stream: @andreterron/InjectCodeOnValTownStream Customization Linking to the val These 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: modifyFetchHandler(handler, {val: { handle: "andre", name: "foo" }}) modifyHtmlString("<html>...", {val: { handle: "andre", name: "foo" }}) Styling You can set the style parameter to a css string to customize the ribbon. Check out github-fork-ribbon-css to learn more about how to style the element. modifyFetchHandler(handler, {style: ".github-fork-ribbon:before { background-color: #333; }"}) modifyHtmlString("<html>...", {style: ".github-fork-ribbon:before { background-color: #333; }"}) Here's how you can hide the ribbon on small screens: modifyFetchHandler(handler, {style: `@media (max-width: 768px) { .github-fork-ribbon { display: none !important; } }`}) To-dos [ ] Let users customize the ribbon. Some ideas are the text, color or placement.
5
stevekrouse avatar
stevekrouse
ssr_react_mini
Script
Server-side Render React Mini Framework This is very experimental, more of a prototype of an architecture, than a true framework Example: https://www.val.town/v/stevekrouse/TodoApp
1
nbbaier avatar
nbbaier
cronLogger
Script
Log your cron evaluations to sqlite import { cronEvalLogger as logger } from "https://esm.town/v/nbbaier/cronLogger"; const run = async (interval: Interval) => { console.log("your code goes here"); }; export default logger(run);
0
pomdtr avatar
pomdtr
article
HTTP
Use readme as website Usage import {article} from "https://esm.town/v/pomdtr/article" export default article() See this val http endpoint as an example: https://pomdtr-article.web.val.run
1
pomdtr avatar
pomdtr
serve_readme
Script
Serve Readme Usage import codeOnValTown from "https://esm.town/v/andreterron/codeOnValTown?v=50"; import { serveReadme } from "https://esm.town/v/pomdtr/serve_readme"; const val = extractValInfo(import.meta.url); export default serveReadme({ val, title: "Code Search is Easy", }); Example @pomdtr/code_search_is_easy (rendered at https://code-search-is-easy.pomdtr.me )
0
stevekrouse avatar
stevekrouse
whoami
Script
Forked from easrng/whoami
0
pomdtr avatar
pomdtr
refs
Script
An interactive, runnable TypeScript val by pomdtr
0
neverstew avatar
neverstew
cronEvalLogger
Script
Forked from nbbaier/cronLogger
0
stevekrouse avatar
stevekrouse
refsExample
Script
An interactive, runnable TypeScript val by stevekrouse
0
stevekrouse avatar
stevekrouse
grantParentReference
Script
Forked from stevekrouse/parentReference
0
stevekrouse avatar
stevekrouse
editRedirect
Script
Redirect to Val Page Redirect from web val to val page by adding /edit to the URL. Convention by pomdtr . Usage import { editRedirect } from "https://esm.town/v/stevekrouse/editRedirect"; import { Hono } from "npm:hono@3"; const app = new Hono(); app.get("/", (c) => c.text("Hello world!")); app.get("/edit", (c) => editRedirect()); export default app.fetch; TODO [ ] turn this into middleware in the style of @pomdtr/basicAuth Live: https://stevekrouse-edit_redirect_example.web.val.run/edit
0
andreterron avatar
andreterron
inferRequestVal
Script
An interactive, runnable TypeScript val by andreterron
0
stevekrouse avatar
stevekrouse
parentReference
Script
Forked from easrng/thisReference
1
stevekrouse avatar
stevekrouse
untitled_limeBeetle
Script
// console.log(import.meta, getMeta());
0
stevekrouse avatar
stevekrouse
open_in_valtown
Script
Forked from andreterron/codeOnValTown
0
1
Next
Updated: September 16, 2024