feat(db): add wiki-link extraction, resolution, and backlinks
CI / test (pull_request) Successful in 2m27s

[[wiki-links]] in entry bodies are extracted at save time, resolved
to entity IDs (title match first, body substring fallback), and
stored in entity_links junction table. Backlinks surface in TUI
detail view showing entries that link to the current entry.

Schema migration v5 adds entity_links with CASCADE/SET NULL
semantics. Links sync on Create, Update, and Absorb.
This commit is contained in:
2026-05-21 13:34:56 -04:00
parent d24df8432f
commit 1e58433936
10 changed files with 454 additions and 8 deletions
+28 -7
View File
@@ -21,13 +21,14 @@ const (
)
type detailModel struct {
entity *db.Entity
scroll int
height int
width int
mode detailMode
run runModel
fill fillModel
entity *db.Entity
backlinks []db.Backlink
scroll int
height int
width int
mode detailMode
run runModel
fill fillModel
}
func newDetailModel() detailModel {
@@ -36,6 +37,7 @@ func newDetailModel() detailModel {
func (d *detailModel) setEntity(e *db.Entity) {
d.entity = e
d.backlinks = nil
d.scroll = 0
d.mode = detailPreview
}
@@ -144,6 +146,25 @@ func (d detailModel) previewView(width int) string {
b.WriteString("\n")
}
if len(d.backlinks) > 0 {
b.WriteString("\n")
b.WriteString(detailLabelStyle.Render(" ← backlinks"))
b.WriteString("\n")
for _, bl := range d.backlinks {
label := bl.Body
if bl.Title != nil {
label = *bl.Title
} else if len(label) > 40 {
label = label[:40] + "…"
}
line := " " + backlinkStyle.Render(label)
if bl.LinkText != "" {
line += " " + hintDescStyle.Render("(as \""+bl.LinkText+"\")")
}
b.WriteString(line + "\n")
}
}
b.WriteString("\n")
meta := fmt.Sprintf("created %s", e.CreatedAt.Format(time.DateTime))
if e.ModifiedAt != e.CreatedAt {