What if the an embeddable form in settings that create a post here but can be…

merged…
osebo30d ago

What if the an embeddable form in settings that create a post here but can be embedded on any site?

11 repliesoldestnewest
Osebotfable-5-130d ago

Yes, this fits what already exists: since thread c9013b60 any workspace takes a new thread from a visitor with no account, so an embeddable form needs no new write permission, it's a different front door to the same guest-thread path.

Plan:

  1. GET /embed/<slug>: a tiny self-contained HTML page (a route handler, not a Next page, so it skips the site header/sidebar and loads nothing but itself): name field, message textarea, "Post" button, "Posting as a guest to <workspace>" note. Follows prefers-color-scheme, or ?theme=light|dark to match the host site. No X-Frame-Options, so any site can <iframe> it.
  2. POST /embed/<slug>: the form posts to itself (works with JS disabled), creates the thread through the existing createThread guest path (same 4000-char cap, same name rules, never Osebot), then re-renders with "Posted" + a link to the thread that opens in a new tab. Honeypot field against drive-by spam. Records the embedding page's origin in posts.meta.embed.from, shown as a small "via example.com" chip on the opening post.
  3. Snippet in the workspace manage page (/workspaces/[id], the closest thing to settings): an "Embed" card with the <iframe> snippet, a Copy button and a live preview of the form.
  4. embed joins RESERVED_SLUGS.

Not doing: a per-workspace on/off switch (guest threads are already open everywhere, so the embed adds nothing new to turn off) and a <script> widget (the iframe is enough and keeps host-page CSS out).

Osebotfable-5-130d ago

Built and typechecked; next build is running as a last check before I commit.

What's there:

  • GET /embed/<slug> serves the form (screenshot 1 shows it inside a 320px iframe on a mock third-party page, screenshot 3 the ?theme=dark variant). It's a route handler returning one small HTML document, so no header/sidebar/fonts come along.
  • POST /embed/<slug> creates the guest thread through the existing createThread path and 303-redirects to ?posted=<id> (screenshot 4), so a reload inside the iframe can't double-post. Honeypot field, same 4000-char cap and name rules as guest posts on /<slug>.
  • The opening post records meta.embed.from = the embedding page's origin (nothing from the path) and shows a via example.com chip next to the guest badge.
  • Members see an Embed card on /workspaces/[id] (screenshot 2): Auto/Light/Dark, Copy snippet, the <iframe> snippet and a live preview of the real form.
  • embed added to RESERVED_SLUGS.

No migration (meta is jsonb), no new env vars.

The /embed/threads form inside a 320px iframe on a third-party page (mockup host site, light scheme)
The /embed/threads form inside a 320px iframe on a third-party page (mockup host site, light scheme)
New "Embed" card on the workspace manage page: Auto/Light/Dark, Copy snippet, the iframe snippet and a live preview
New "Embed" card on the workspace manage page: Auto/Light/Dark, Copy snippet, the iframe snippet and a live preview
/embed/threads?theme=dark at 400x320
/embed/threads?theme=dark at 400x320
After posting: redirect to ?posted=<threadId>, link opens the thread in a new tab
After posting: redirect to ?posted=<threadId>, link opens the thread in a new tab
Osebotfable-5-130d agothreadide@a93d909

Pushed to thread/7479f828 (a93d909); tsc and next build both clean.

How it's used

  1. Open the workspace's manage page (/workspaces/<id>), scroll to Embed.
  2. Pick Auto / Light / Dark (Auto follows the visitor's OS scheme; Light/Dark pin one so it matches the host site), hit Copy snippet.
  3. Paste the <iframe src="https://evenings.forum/embed/<slug>" … height="320"> on any page. Visitors type a name (optional) and a message; the first line becomes the title, like the home composer. After posting they see a link that opens the thread here in a new tab, and a "Post another".

Design notes for later readers

  • /embed/<slug> is a route handler serving one small self-contained HTML page (lib/embed.ts), not a Next page, so the forum chrome never loads inside the iframe. The form posts to itself and redirects (works with JS off, no double-post on reload).
  • Writes reuse the guest-thread path exactly (same 4000-char cap, name rules, never Osebot). No switch was added because every workspace already accepts guest threads on /<slug>; the embed is just another door.
  • The opening post keeps the embedding page's origin (never the path) in meta.embed.from and shows via example.com next to the guest badge, so you can tell embedded posts apart from forum ones.
  • embed is now a reserved slug.

Caveats

  • Not run against a live database here (sandbox can't start the app). Worth one real post from a test page after deploy.
  • Guest thread creation has never had a rate limit; the embed lowers the effort for bots a little. There's a honeypot field, and if spam appears a per-IP limit on POST /embed/<slug> + POST /api/threads is the obvious next step.
  • Possible follow-ups if wanted: a "reply to this thread" embed (same route shape, /embed/thread/<id>), or a <script> widget that auto-sizes the iframe.
oseboasked Osebot30d ago

I’d love to make the styles of the form customizable

Osebotfable-5-130d ago

Plan: make the embed's look configurable from the snippet itself, no database change.

  • Style lives in the iframe URL: /embed/<slug>?theme=dark&bg=0f172a&fg=e2e8f0&accent=f97316&radius=4&font=serif&name=0&button=Send. lib/embed.ts parses and validates each knob (hex colours only, radius 0–24, font from sans/serif/mono, button label ≤40 chars) and emits one html[data-custom] override rule after the built-in light/dark tokens, so the custom colours win whatever the visitor's OS scheme is. bg=transparent lets the form sit directly on the host page. Secondary colours (muted text, field fill, button text colour) are derived from the three you pick, so a dark background never gets a light fill or an unreadable button.
  • Designer on the manage page: the Embed card grows a small panel (colour pickers for Background / Text / Accent + transparent toggle, Corners, Font, "Ask for a name", Button label, Reset). Every change updates the snippet and the live preview immediately; Copy snippet carries the whole look.
  • Not doing arbitrary CSS through the URL (any page could then restyle the form into something misleading on our origin). A per-workspace stored stylesheet is the follow-up if the knobs aren't enough.

Will post screenshots of the designer and a couple of styled embeds.

Osebotfable-5-130d ago

Built and typechecked; next build is running before I commit.

How it works

The style is part of the snippet URL, nothing is stored: /embed/<slug>?theme=dark&bg=0f172a&fg=e2e8f0&accent=f97316&radius=4&font=serif&name=0&button=Send+it. Knobs:

paramacceptseffect
bg3/6-digit hex, or transparentpage background (transparent lets the host page show through, screenshot 2)
fghextext; muted text and field fills are derived from it
accenthexbutton + focus ring; button text goes black or white by the accent's luminance
radius0–24corners on fields and the button
fontsans serif monotype family
name0hides the name field (posts arrive as "guest")
button≤40 charsthe button label

Anything else is dropped silently (tested with bg=url(x)&fg=<script>&radius=99&font=comic → defaults). The values become one html[data-custom] { --bg… } rule after the built-in light/dark tokens, so custom colours win whichever scheme the visitor's OS is in; the POST and the "Posted." redirect carry the same params so the look never flips mid-flow.

The manage page's Embed card has the designer (screenshots 3 and 4): colour swatches with reset, Transparent toggle, Corners slider, Font, "Ask visitors for a name", Button label, and a Reset line when anything is custom. Snippet and the live preview update on every change; Copy snippet copies the configured URL. With the theme on Auto the untouched swatches show the defaults of whatever scheme your OS resolves to, since that is what the preview iframe follows.

Four looks from one /embed/threads route: default, dark brand palette with "Send it", paper serif without the name field, dark theme + blue accent + 20px corners + mono
Four looks from one /embed/threads route: default, dark brand palette with "Send it", paper serif without the name field, dark theme + blue accent + 20px corners + mono
On a mock host page: ?bg=transparent&fg=ffffff&accent=22c55e lets the gradient show through; below it the pinned brand palette
On a mock host page: ?bg=transparent&fg=ffffff&accent=22c55e lets the gradient show through; below it the pinned brand palette
The Embed card's designer on the workspace manage page (light): colours, transparent, corners, font, name field, button label; snippet and preview update live
The Embed card's designer on the workspace manage page (light): colours, transparent, corners, font, name field, button label; snippet and preview update live
Designer at 390px: knobs stack into one column
Designer at 390px: knobs stack into one column
Osebotfable-5-130d agothreadide@691f9f2

Pushed to thread/7479f828 (691f9f2); tsc and next build both clean.

What changed

  • The embed's look is set in the snippet URL, so one workspace can be embedded differently on different sites and nothing needs saving: bg, fg, accent (hex, bg may be transparent), radius (0–24), font (sans / serif / mono), name=0 to hide the name field, button for the label. Everything else is validated away; the URL can pick colours and sizes, never inject CSS.
  • Custom values go into one html[data-custom] rule after the built-in light/dark tokens, so they hold whichever scheme the visitor's OS is in. Muted text, field fills, focus ring and button text colour are derived from the three colours you pick, so a dark palette never gets a white field or an unreadable button.
  • The Embed card on /workspaces/<id> grew a designer: swatches with reset, Transparent, Corners, Font, "Ask visitors for a name", Button label, a Reset line. Snippet and live preview follow every change; Copy snippet copies the configured one.

Notes for later

  • The POST and the "Posted." redirect carry the style params, so the look never flips after submitting.
  • If the knobs aren't enough, the next step is a stored per-workspace stylesheet (owner-only, jsonb column), not a css= param. I'd keep the URL knobs even then, since they let the same form match several host sites.
  • Still unverified against a live database; one real post from a test page after deploy is the thing to do.
oseboasked Osebot30d ago

Couldn’t we just give people html and css that they can edit?

Osebotfable-5-130d ago

Yes, and it's simpler than the knobs. The form is just three fields posting to /embed/<slug>, so a site can hold the markup itself and style it like the rest of its page.

Plan (replaces the URL-parameter designer from 691f9f2):

  • HTML + CSS snippet: the Embed card gets an "HTML + CSS" mode (the default) next to the iframe one. It shows an editable HTML block (a plain <form action="https://evenings.forum/embed/<slug>" method="post"> with name, message, honeypot, a hidden return URL, a Post button and placeholders for the "Posted" / error lines) and an editable CSS block (variables for colours, radius and font on top; every rule below is theirs too). Live preview under them, Copy copies both. Only the action, the method and the field names have to stay; everything else, including the class names, can be rewritten.
  • The route accepts posts from any page: POST /embed/<slug> already takes a form-encoded body. Additions: when the request comes with Accept: application/json (the snippet's few lines of script use fetch, so the visitor stays on the host page and sees "Posted" in place) it answers JSON with Access-Control-Allow-Origin: *; without JS the plain POST works and we redirect back to the host page with ?posted=<threadId>, but only when that return URL has the same origin as the request's Origin header, so nobody can use the route as an open redirect. The host page's origin becomes meta.embed.from straight from that header, no referrer needed.
  • Drop the ?bg=&fg=&accent=… knobs and the designer: with the CSS in the host's hands they're a second way to do a weaker version of the same thing. The iframe snippet keeps Auto / Light / Dark only. (691f9f2 has the knobs if we ever want them back.)

Screenshots of the card and of a restyled form on a mock host page when done.

Osebotfable-5-130d agothreadide@d749f9b

Yes, done that way. Pushed to thread/7479f828 (d749f9b); tsc and next build clean.

What a site owner gets now (Embed card on /workspaces/<id>, screenshot 1)

  • HTML + CSS (default): the form's markup and its stylesheet in two editable blocks, a live preview under them, one Copy. The HTML is a plain <form action="https://evenings.forum/embed/<slug>" method="post"> with name, message, a hidden honeypot, a hidden return URL, the button and two placeholder lines ("Posted. Open the thread", error). The CSS has the variables (--bg, --text, --accent, --radius, --font…) on top and the drawing below; every rule is theirs, class names included. The only things the server reads are the action, method="post" and the field names name, body, website, redirect.
  • iframe: the one-tag option with the built-in look, Auto / Light / Dark. Unchanged apart from losing the style params.

Screenshot 2 is the snippet on a mock page after a handful of CSS edits (dark card, orange pill button, serif, new button text): same form, no forum code involved.

How a cross-site form talks to us

  • The snippet ends with ~25 lines of optional script: it posts with fetch + Accept: application/json, so the visitor stays on the page and sees "Posted. Open the thread" in place. The route answers JSON with Access-Control-Allow-Origin: * (no preflight: FormData + Accept is a simple request).
  • Without the script (or JS off) the plain POST works: we create the thread and 303 back to the page named in the redirect field with ?posted=<id> appended, but only when that URL has the same origin as the request's Origin header. Anything else falls back to our own posted page, so the route can't be used as an open redirect.
  • The host page's origin becomes meta.embed.from straight from the Origin header (the iframe keeps using its referrer field, since its own Origin is ours). Honeypot hits are answered like a success and post nothing.
  • The card's preview runs the pasted HTML in a sandboxed srcdoc iframe (opaque origin), so trying out markup there can never act as this site.

Removed: the ?bg=&fg=&accent=&radius=&font=&name=&button= knobs and the designer from 691f9f2. With the CSS in the host's hands they were a second, weaker way to do the same thing. That commit still has them if we ever want a no-code path beyond Light/Dark.

Caveats

  • Verified in Chromium with the endpoint mocked (the script's submit → "Posted" → correct /threads/<id> link); not yet against the live route. After deploy, one post each with JS, with JS off, and through the iframe is the check.
  • Still no rate limit on guest thread creation; honeypot only. Per-IP limiting on POST /embed/<slug> and POST /api/threads is the next step if spam appears.
Embed card on the workspace manage page: HTML + CSS mode with the two editable blocks and the live preview of what Copy gives
Embed card on the workspace manage page: HTML + CSS mode with the two editable blocks and the live preview of what Copy gives
The same form on a mock host page after a few CSS edits (dark card, orange pill button, serif), right after posting via the script's fetch path
The same form on a mock host page after a few CSS edits (dark card, orange pill button, serif), right after posting via the script's fetch path
Embed card at 390px: editors stack into one column
Embed card at 390px: editors stack into one column
Osebot30d ago

Merged threadide #153 by @osebo (merge, 83be328).