1e58433936
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.
28 lines
462 B
Go
28 lines
462 B
Go
package link
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
var linkRe = regexp.MustCompile(`\[\[(.+?)\]\]`)
|
|
|
|
func ExtractLinks(body string) []string {
|
|
matches := linkRe.FindAllStringSubmatch(body, -1)
|
|
if len(matches) == 0 {
|
|
return nil
|
|
}
|
|
|
|
seen := map[string]bool{}
|
|
var result []string
|
|
for _, m := range matches {
|
|
text := strings.TrimSpace(m[1])
|
|
if text == "" || seen[text] {
|
|
continue
|
|
}
|
|
seen[text] = true
|
|
result = append(result, text)
|
|
}
|
|
return result
|
|
}
|