Press [ in detail view to open link picker showing all [[links]] in the current entry. Enter follows a link, resolving by title then body substring. Navigation history stack enables esc to pop back through followed links before returning to list. Adds Store.ResolveLink() for non-transactional link resolution from the TUI layer.
This commit is contained in:
@@ -55,6 +55,26 @@ func syncLinks(ctx context.Context, tx *sql.Tx, s *Store, entityID string, body
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) ResolveLink(ctx context.Context, linkText string) (*Entity, error) {
|
||||
lower := strings.ToLower(linkText)
|
||||
|
||||
var id string
|
||||
err := s.db.QueryRowContext(ctx, `
|
||||
SELECT id FROM entities
|
||||
WHERE LOWER(title) = ? AND deleted_at IS NULL
|
||||
ORDER BY created_at DESC LIMIT 1`, lower).Scan(&id)
|
||||
if err != nil {
|
||||
err = s.db.QueryRowContext(ctx, `
|
||||
SELECT id FROM entities
|
||||
WHERE LOWER(body) LIKE ? AND deleted_at IS NULL
|
||||
ORDER BY created_at DESC LIMIT 1`, "%"+lower+"%").Scan(&id)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
return s.Get(ctx, id)
|
||||
}
|
||||
|
||||
func (s *Store) LoadBacklinks(ctx context.Context, entityID string) ([]Backlink, error) {
|
||||
rows, err := s.db.QueryContext(ctx, `
|
||||
SELECT e.id, e.title, e.body, el.link_text
|
||||
|
||||
Reference in New Issue
Block a user