rev.ts
This file
Path
apps/web/src/features/code/rev.ts
29 lines · 1.2 KiB · TypeScript
Last changed by
Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215
History of this fileTake it
Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a
lines 1–25why, one step back1/**2 * A revision as one segment of a code page's path3 * (`/$project/tree/$rev/$`): `main`, a 40-hex commit SHA, or a tag name.4 * A tag name may hold `/` and `@` (`@changesets/cli@2.27.1`), so it is5 * URL-encoded into one segment; `main` and a SHA encode to themselves.6 * Whether a revision names anything is the platform's to say (`readTree`7 * and the other code reads refuse with `UnknownRevision`).8 */9import { Rev } from "@repo/protocol/domain/code";10import { Option, Schema } from "effect";1112/** `rev` as one path segment. */13export const revSegment = (rev: string): string => encodeURIComponent(rev);1415const decodeSegment = Option.liftThrowable(decodeURIComponent);1617const asRev = Schema.decodeUnknownOption(Rev);1819/**20 * The revision a path segment names: none for a segment that is not a21 * valid encoding (`%`) or not a revision at all (empty, too long). A22 * segment the router already decoded reads as itself.23 */24export const revOf = (segment: string): Option.Option<string> =>25 Option.flatMap(decodeSegment(segment), asRev);Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215
lines 26–29why, one step back2627/** The revision a page reads, beside its title: a commit by its short id. */28export const revLabel = (rev: string) =>29 /^[0-9a-f]{40}$/u.test(rev) ? rev.slice(0, 7) : rev;