// Hex Labs on the web: a page per lab at /hex/labs/, the index at // /hex/labs, and each lab's social card. labs.json comes from the Rust Labs // registry (src/labs/web.rs in the app), so a lab's title, line, group, and // OSes are never copied by hand; scripts/labs.ts writes the pages at build. import { DEV_DOWNLOAD_PATH, withBase } from "./base" export type Os = "macos" | "windows" | "linux" export type Lab = { id: string title: string summary: string group: string groupTitle: string oses: Os[] added: string } // Where a lab ships. `stable` names the stable version that has it; a lab // it doesn't have (or every lab, when the build couldn't tell) is in the Dev // build only. export type Channel = { stable: string } | { dev: true } const OS_NAMES: Record = { macos: "Mac", windows: "Windows", linux: "Linux" } // The dev build's download per OS: the Worker's /hex/download/dev/ // redirects, and /hex/download/dev the Mac's. const DEV_DOWNLOADS: Record = { macos: DEV_DOWNLOAD_PATH, windows: withBase("/download/dev/windows-x64-setup"), linux: withBase("/download/dev/linux-x64-deb"), } export function escape(text: string): string { return text.replace(/[&<>"']/g, (character) => `&#${character.charCodeAt(0)};`) } // A card's line as a sentence: the window's lines mostly leave off the stop. export function sentence(text: string): string { return /[.!?]$/.test(text) ? text : `${text}.` } // The social card's line: the first sentence of a long one. export function cardLine(summary: string): string { const line = sentence(summary) if (line.length <= 130) return line const end = line.search(/[.;](\s|$)/) return end > 0 ? `${line.slice(0, end)}.` : line } export function osList(oses: Os[]): string { const names = oses.map((os) => OS_NAMES[os]) return names.length < 3 ? names.join(" and ") : `${names.slice(0, -1).join(", ")}, and ${names.at(-1)}` } // Newest first; labs added the same day keep the registry's order. export function newestFirst(labs: Lab[]): Lab[] { return labs .map((lab, index) => ({ lab, index })) .sort((a, b) => b.lab.added.localeCompare(a.lab.added) || a.index - b.index) .map(({ lab }) => lab) } // The `hex labs …` names a stable version's Rust source knows: its // `Feature::name` strings, which every lab id is. export function inSource(lab: Lab, source: string): boolean { return source.includes(`"${lab.id}"`) } export const pagePath = (lab: Lab) => withBase(`/labs/${lab.id}`) // The card's ?v= changes with what it shows, so link previews that cached an // older card fetch the new one. export function cardVersion(lab: Lab): string { let hash = 0x811c9dc5 for (const character of `${lab.title}\n${lab.summary}\n${lab.oses.join(",")}`) { hash = Math.imul(hash ^ character.codePointAt(0)!, 0x01000193) >>> 0 } return hash.toString(36) } export const cardPath = (lab: Lab) => withBase(`/labs/${lab.id}.png?v=${cardVersion(lab)}`) export const INDEX_PATH = withBase("/labs") export const INDEX_CARD_PATH = withBase("/labs.png") const LABS = { crumb: { href: INDEX_PATH, label: "Labs" } } const STYLE = ` :root { color-scheme: only dark; } * { box-sizing: border-box; } body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 50% -10%, rgba(255,255,255,0.06), transparent 520px), #070707; color: #f2f2ef; font: 16px/1.55 Inter, ui-sans-serif, system-ui, sans-serif; font-feature-settings: "cv02", "cv03", "cv04", "cv11", "ss01"; -webkit-font-smoothing: antialiased; } a { color: inherit; } header { max-width: 720px; margin: 0 auto; padding: 28px 24px 0; display: flex; align-items: center; gap: 10px; font-weight: 600; } header a { text-decoration: none; display: inline-flex; align-items: center; gap: 10px; } header svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 3.5; stroke-linejoin: round; } header .crumb { color: #8a8b90; font-weight: 500; } main { max-width: 720px; margin: 0 auto; padding: 72px 24px 96px; } .eyebrow { margin: 0 0 14px; color: #8a8b90; font-size: 14px; font-weight: 500; letter-spacing: 0.01em; } h1 { margin: 0; font-size: clamp(40px, 8vw, 64px); font-weight: 600; letter-spacing: -0.035em; line-height: 1.04; text-wrap: balance; } .summary { margin: 18px 0 0; color: #b4b5ba; font-size: 20px; line-height: 1.45; max-width: 32em; text-wrap: pretty; } .actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 40px 0 0; } .button { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 22px; border-radius: 999px; font-weight: 600; text-decoration: none; transition: background-color 120ms ease, border-color 120ms ease; } .button--primary { background: #f2f2ef; color: #070707; } .button--primary:hover { background: #ffffff; } .button--secondary { border: 1px solid #2c2d31; background: #121214; } .button--secondary:hover { border-color: #46474d; } .note + .note { margin-top: 6px; } .note { margin: 18px 0 0; color: #8a8b90; font-size: 15px; max-width: 36em; } .note a { text-decoration-color: #4a4b50; text-underline-offset: 3px; } .note a:hover { text-decoration-color: currentColor; } code { white-space: nowrap; font: 14px ui-monospace, SFMono-Regular, Menlo, monospace; color: #d6d7db; background: #141416; border: 1px solid #222326; border-radius: 6px; padding: 2px 6px; } .about { margin: 56px 0 0; padding: 24px 0 0; border-top: 1px solid #1d1e21; color: #8a8b90; font-size: 15px; } .about p { margin: 0 0 8px; } ol { list-style: none; margin: 40px 0 0; padding: 0; } li { border-top: 1px solid #1d1e21; } li a { display: grid; grid-template-columns: 1fr auto; gap: 4px 24px; padding: 18px 0; text-decoration: none; } li a:hover .title { text-decoration: underline; text-decoration-color: #4a4b50; text-underline-offset: 4px; } .title { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; } .line { grid-column: 1; color: #a3a4a9; font-size: 15px; } .meta { grid-row: 1 / span 2; grid-column: 2; align-self: center; color: #6f7075; font-size: 13px; text-align: right; white-space: nowrap; } .index-intro { margin: 18px 0 0; color: #b4b5ba; font-size: 18px; max-width: 34em; } ` const MARK = `` export type Meta = { title: string; description: string; url: string; image: string; imageAlt: string } function head(origin: string, meta: Meta, style: string): string { const url = `${origin}${meta.url.slice("/hex".length)}` const image = `${origin}${meta.image.slice("/hex".length)}` const tags = [ ``, ``, ``, `${escape(meta.title)}`, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ``, ] return tags.join("\n") } // A static page in the Labs pages' look: the Hex mark and a crumb, then the body. // The iPhone pages (src/iphone.ts) use it too, with their own crumb and styles. export function shell(origin: string, meta: Meta, body: string, page: { crumb: { href: string; label: string }; style?: string } = LABS): string { return ` ${head(origin, meta, page.style ?? "")}
${MARK}Hex/${escape(page.crumb.label)}
${body}
` } function getHex(lab: Lab, channel: Channel): { href: string; label: string; where: string } { if ("stable" in channel) { return { href: withBase("/"), label: "Get Hex", where: `In Hex ${escape(channel.stable)} and later.` } } const [first, ...rest] = lab.oses const others = rest.map((os) => `${OS_NAMES[os]}`) return { href: DEV_DOWNLOADS[first], label: `Get Hex Dev for ${OS_NAMES[first]}`, where: `In the Dev build, not yet in a stable release.${others.length ? ` Dev build for ${others.join(" or ")}.` : ""}`, } } // The deep link opens Settings › Labs on the lab's card. Only the Mac app // registers hex://, so labs Mac doesn't have offer the command alone. export function renderLab(lab: Lab, channel: Channel, origin: string): string { const description = `${sentence(lab.summary)} A Hex Labs feature for ${osList(lab.oses)}.` const get = getHex(lab, channel) const mac = lab.oses.includes("macos") const open = mac ? `Open in Hex` : "" const getClass = mac ? "button--secondary" : "button--primary" const first = mac ? "No Hex yet? Get it first, then come back and press Open in Hex." : `Turn it on in Settings › Labs.` const body = `

Hex Labs · ${escape(lab.groupTitle)} · ${escape(osList(lab.oses))}

${escape(lab.title)}

${escape(sentence(lab.summary))}

${get.where}

${first} Or run hex labs on ${escape(lab.id)}.

Labs are features we're trying out, each off until you turn it on in Settings › Labs.

Every lab

` return shell( origin, { title: `${lab.title} · Hex Labs`, description, url: pagePath(lab), image: cardPath(lab), imageAlt: `Hex Labs: ${lab.title}. ${cardLine(lab.summary)}`, }, body, ) } export function renderIndex(labs: Lab[], origin: string): string { const items = newestFirst(labs) .map( (lab) => `
  • ${escape(lab.title)}${escape(sentence(lab.summary))}${escape(lab.groupTitle)} · ${escape(osList(lab.oses))}
  • `, ) .join("\n") const body = `

    Hex Labs

    Features we're trying out, newest first. Each is off until you turn it on in Settings › Labs.

      ${items}
    ` return shell( origin, { title: "Hex Labs", description: "Features Hex is trying out, each off until you turn it on in Settings › Labs.", url: INDEX_PATH, image: INDEX_CARD_PATH, imageAlt: "Hex Labs: features Hex is trying out.", }, body, ) }