Changement des ilink vers markdown pur
This commit is contained in:
@ -33,6 +33,7 @@ type Document struct {
|
||||
LastModified string
|
||||
Body string
|
||||
Summary string
|
||||
Links []string // Liens Markdown vers d'autres notes
|
||||
|
||||
lowerTitle string
|
||||
lowerBody string
|
||||
@ -115,11 +116,11 @@ func (i *Indexer) Load(root string) error {
|
||||
indexed[tag] = list
|
||||
}
|
||||
|
||||
// Build backlinks index
|
||||
// Build backlinks index from Markdown links
|
||||
backlinksMap := make(map[string][]string)
|
||||
for sourcePath, doc := range documents {
|
||||
links := extractInternalLinks(doc.Body)
|
||||
for _, targetPath := range links {
|
||||
// Use the Links field which contains extracted Markdown links
|
||||
for _, targetPath := range doc.Links {
|
||||
// Add sourcePath to the backlinks of targetPath
|
||||
if _, ok := backlinksMap[targetPath]; !ok {
|
||||
backlinksMap[targetPath] = make([]string, 0)
|
||||
@ -169,6 +170,45 @@ func normalizeTags(tags []string) []string {
|
||||
return result
|
||||
}
|
||||
|
||||
// extractMarkdownLinks extrait tous les liens Markdown du body
|
||||
// Format : [texte](chemin/vers/note.md)
|
||||
// Retourne une liste de chemins vers d'autres notes
|
||||
func extractMarkdownLinks(body string) []string {
|
||||
// Regex pour capturer [texte](chemin.md)
|
||||
// Groupe 1 : texte du lien, Groupe 2 : chemin
|
||||
re := regexp.MustCompile(`\[([^\]]+)\]\(([^)]+\.md)\)`)
|
||||
matches := re.FindAllStringSubmatch(body, -1)
|
||||
|
||||
links := make([]string, 0, len(matches))
|
||||
seen := make(map[string]bool) // Éviter les doublons
|
||||
|
||||
for _, match := range matches {
|
||||
if len(match) < 3 {
|
||||
continue
|
||||
}
|
||||
|
||||
linkPath := strings.TrimSpace(match[2])
|
||||
|
||||
// Ignorer les URLs absolues (http://, https://, //)
|
||||
if strings.HasPrefix(linkPath, "http://") ||
|
||||
strings.HasPrefix(linkPath, "https://") ||
|
||||
strings.HasPrefix(linkPath, "//") {
|
||||
continue
|
||||
}
|
||||
|
||||
// Normaliser le chemin (convertir \ en / pour Windows)
|
||||
linkPath = filepath.ToSlash(linkPath)
|
||||
|
||||
// Éviter les doublons
|
||||
if !seen[linkPath] {
|
||||
seen[linkPath] = true
|
||||
links = append(links, linkPath)
|
||||
}
|
||||
}
|
||||
|
||||
return links
|
||||
}
|
||||
|
||||
func buildDocument(path string, fm FullFrontMatter, body string, tags []string) *Document {
|
||||
title := strings.TrimSpace(fm.Title)
|
||||
if title == "" {
|
||||
@ -176,6 +216,7 @@ func buildDocument(path string, fm FullFrontMatter, body string, tags []string)
|
||||
}
|
||||
|
||||
summary := buildSummary(body)
|
||||
links := extractMarkdownLinks(body)
|
||||
|
||||
lowerTags := make([]string, len(tags))
|
||||
for idx, tag := range tags {
|
||||
@ -190,6 +231,7 @@ func buildDocument(path string, fm FullFrontMatter, body string, tags []string)
|
||||
LastModified: strings.TrimSpace(fm.LastModified),
|
||||
Body: body,
|
||||
Summary: summary,
|
||||
Links: links,
|
||||
lowerTitle: strings.ToLower(title),
|
||||
lowerBody: strings.ToLower(body),
|
||||
lowerTags: lowerTags,
|
||||
|
||||
Reference in New Issue
Block a user