src/read/ids.ts is a pure module (no clock, no randomness, no fetch) that defines how the app names a document. Every package that builds a link to a document, an author or an image imports it.
The ref
A ref is uid or uid/path/segments: no version, no fragment (L1-L4). The doc route /d/:ref carries it URL-encoded. The same parameter may instead hold a whole URL (a deep link or a typed address); linkOfRef tells the two apart. See Deep links and URL handling and the glossary.
Functions
Function | Input to output |
|---|---|
| |
The block id in | |
The URL when the route parameter is one (decoded once if it arrived as | |
| |
Lowercased host, | |
| |
Joins, dropping empty segments. | |
| |
| |
Where a link inside a document goes, see below. | |
| |
|
linkTarget rules
A document link (refFromUrl succeeds) stays in the app. An hm:// link becomes /d/{ref}; an https://host/hm/… gateway link becomes /d/{the whole URL}, so it is later read from its own host.
A page of the current server's site (same host as server, and siteUrlParts accepts it) becomes /d/{the whole URL}.
Otherwise only http(s)://, mailto:, tel:, a root-relative path and #fragment are returned unchanged. Every other scheme returns "", so the renderer writes plain text instead of a link. The edge-case test "document links cannot execute active URL schemes" pins this.
Relative /d/… hrefs are further rewritten by the root contract's readScopedHref so they stay on the visible reader's server, see Root contract wiring.
Who uses it
load.ts and markdown.ts in this package.
Discuss logic for authorHref, docHref, hmUrl, mediaUrl, parseRef, refOf, shortId.
Activity model for docHref, mediaUrl, refOf.
Open a site by URL for refFromUrl and siteUrlParts.
Tests
markdown.test.ts ids group: 3 tests (URLs to refs, round trip through the route, media and short ids).
deep-links.test.ts: 7 tests, the first three on linkOfRef, siteUrlParts and linkTarget.
edge-cases.test.ts: literal percent escapes in refs, gateway contact pages, active URL schemes.
Known limits
mediaUrl does not trim a trailing slash from server.
A site page whose last path segment contains a dot followed by 2 to 5 alphanumerics is treated as a file and is not opened in the reader.
Do you like what you are reading? Subscribe to receive updates.
Unsubscribe anytime