Add backlink
This commit is contained in:
@ -27,6 +27,12 @@ type TreeNode struct {
|
||||
Children []*TreeNode `json:"children,omitempty"`
|
||||
}
|
||||
|
||||
// BacklinkInfo représente une note qui référence la note courante
|
||||
type BacklinkInfo struct {
|
||||
Path string `json:"path"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
// Handler gère toutes les routes de l'API.
|
||||
type Handler struct {
|
||||
notesDir string
|
||||
@ -696,14 +702,20 @@ func (h *Handler) handleGetNote(w http.ResponseWriter, r *http.Request, filename
|
||||
content = []byte(initialContent)
|
||||
}
|
||||
|
||||
// Récupérer les backlinks pour cette note
|
||||
backlinks := h.idx.GetBacklinks(filename)
|
||||
backlinkData := h.buildBacklinkData(backlinks)
|
||||
|
||||
data := struct {
|
||||
Filename string
|
||||
Content string
|
||||
IsHome bool
|
||||
Filename string
|
||||
Content string
|
||||
IsHome bool
|
||||
Backlinks []BacklinkInfo
|
||||
}{
|
||||
Filename: filename,
|
||||
Content: string(content),
|
||||
IsHome: false,
|
||||
Filename: filename,
|
||||
Content: string(content),
|
||||
IsHome: false,
|
||||
Backlinks: backlinkData,
|
||||
}
|
||||
|
||||
err = h.templates.ExecuteTemplate(w, "editor.html", data)
|
||||
@ -1135,3 +1147,35 @@ func (h *Handler) removeEmptyDirRecursive(relPath string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// buildBacklinkData transforme une liste de chemins de notes en BacklinkInfo avec titres
|
||||
func (h *Handler) buildBacklinkData(paths []string) []BacklinkInfo {
|
||||
if len(paths) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
result := make([]BacklinkInfo, 0, len(paths))
|
||||
|
||||
for _, path := range paths {
|
||||
// Lire le fichier pour extraire le titre du front matter
|
||||
fullPath := filepath.Join(h.notesDir, path)
|
||||
fm, _, err := indexer.ExtractFrontMatterAndBody(fullPath)
|
||||
|
||||
title := ""
|
||||
if err == nil && fm.Title != "" {
|
||||
title = fm.Title
|
||||
} else {
|
||||
// Fallback: dériver le titre du nom de fichier
|
||||
title = strings.TrimSuffix(filepath.Base(path), ".md")
|
||||
title = strings.ReplaceAll(title, "-", " ")
|
||||
title = strings.Title(title)
|
||||
}
|
||||
|
||||
result = append(result, BacklinkInfo{
|
||||
Path: path,
|
||||
Title: title,
|
||||
})
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user