links: a rename or a move no longer breaks them

A document links to another by its path, `[the plan](/n/work/plan)`, or
now by its title, `[[Plan]]` or `[[Plan|the plan]]`. What each document
links to is kept in a new `links` table, rebuilt whenever its text is
written: from the browser, over the mount, or by an import. A title is
looked for in the linking document's space first, then in every other.

Renaming or moving a document, or a folder above it, rewrites the links
to it in every document that has one, in the same transaction: the path
to the new one, a title to the new name, with the label left as it was.
Each rewritten document keeps a revision of what it said before. A link
to something in the trash keeps its row, so it follows the thing when it
is restored somewhere else. A document created, or renamed, under a title
that a link was waiting for is found by that link from then on.

The reader draws `[[titles]]` as links, and a title no document has yet
as a dimmed one that offers to write that document. `gf` follows either
from the editor, and `[[` there completes titles from the search. `gb`
and `:backlinks` list the documents that link to the open one, with the
line each does it on; the line under the title counts them. A share page
shows these links as plain text, as it does every /n/ link.

The documents written before this are indexed once, when the server
starts and finds the table empty.
This commit is contained in:
nvrl committed 2026-10-20 20:20:40 +02:00
1 parent fc2be66b0c
commit a42f9074a2
23 files changed
+1281 -35

No files matched your search

+16
View File
@@ -49,6 +49,19 @@ export interface Crumb {
export interface WorkspaceNode extends NodeSummary {
body: string
path: Crumb[]
/** How many documents link here. */
backlinks: number
/** Where each `[[title]]` in the body leads, as an /n/ path; a title that leads nowhere is missing. */
wikilinks: Record<string, string>
}
/** A document that links to the one asked about, and the line it does it on. */
export interface Backlink {
id: number
name: string
slug: string
path: string
context: string
}
/** A space as the overview shows it: itself, and what was last written in it. */
@@ -429,6 +442,9 @@ export const api = {
revision: (id: number, rev: number) => request<Revision>(`/nodes/${id}/revisions/${rev}`),
/** The documents that link to this one, the last written first. */
backlinks: (id: number) => request<Backlink[]>(`/nodes/${id}/backlinks`),
/** Into the trash; `purged` when it was in the trash already and is now gone. */
deleteNode: (id: number) =>
request<{ ok: true; removed: number; purged: boolean }>(`/nodes/${id}`, { method: 'DELETE' }),