Add recemment modifié page accueil
This commit is contained in:
@ -279,9 +279,9 @@ func (h *Handler) buildCalendarData(year int, month time.Month) *CalendarData {
|
||||
// Calculer mois précédent et suivant
|
||||
prevMonth := firstDay.AddDate(0, -1, 0)
|
||||
nextMonth := firstDay.AddDate(0, 1, 0)
|
||||
data.PrevMonth = fmt.Sprintf("%d-%02d", prevMonth.Year(), prevMonth.Month())
|
||||
data.NextMonth = fmt.Sprintf("%d-%02d", nextMonth.Year(), nextMonth.Month())
|
||||
data.CurrentMonth = fmt.Sprintf("%d-%02d", year, month)
|
||||
data.PrevMonth = fmt.Sprintf("%d/%02d", prevMonth.Year(), prevMonth.Month())
|
||||
data.NextMonth = fmt.Sprintf("%d/%02d", nextMonth.Year(), nextMonth.Month())
|
||||
data.CurrentMonth = fmt.Sprintf("%d/%02d", year, month)
|
||||
|
||||
// Construire les semaines
|
||||
// Lundi = 0, Dimanche = 6
|
||||
|
||||
@ -335,6 +335,9 @@ func (h *Handler) generateHomeMarkdown() string {
|
||||
// Section des favoris (après les tags)
|
||||
h.generateFavoritesSection(&sb)
|
||||
|
||||
// Section des notes récemment modifiées (après les favoris)
|
||||
h.generateRecentNotesSection(&sb)
|
||||
|
||||
// Titre de l'arborescence avec le nombre de notes
|
||||
sb.WriteString(fmt.Sprintf("## 📂 Toutes les notes (%d)\n\n", noteCount))
|
||||
|
||||
@ -407,6 +410,56 @@ func (h *Handler) generateFavoritesSection(sb *strings.Builder) {
|
||||
sb.WriteString("</div>\n\n")
|
||||
}
|
||||
|
||||
// generateRecentNotesSection génère la section des notes récemment modifiées
|
||||
func (h *Handler) generateRecentNotesSection(sb *strings.Builder) {
|
||||
recentDocs := h.idx.GetRecentDocuments(5)
|
||||
|
||||
if len(recentDocs) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
sb.WriteString("## 🕒 Récemment modifiés\n\n")
|
||||
sb.WriteString("<div class=\"recent-notes-container\">\n")
|
||||
|
||||
for _, doc := range recentDocs {
|
||||
// Extraire les premières lignes du corps (max 150 caractères)
|
||||
preview := doc.Summary
|
||||
if len(preview) > 150 {
|
||||
preview = preview[:150] + "..."
|
||||
}
|
||||
|
||||
// Parser la date de modification pour un affichage plus lisible
|
||||
dateStr := doc.LastModified
|
||||
if dateStr == "" {
|
||||
dateStr = doc.Date
|
||||
}
|
||||
|
||||
sb.WriteString(" <div class=\"recent-note-card\">\n")
|
||||
sb.WriteString(fmt.Sprintf(" <a href=\"#\" class=\"recent-note-link\" hx-get=\"/api/notes/%s\" hx-target=\"#editor-container\" hx-swap=\"innerHTML\">\n", doc.Path))
|
||||
sb.WriteString(fmt.Sprintf(" <div class=\"recent-note-title\">%s</div>\n", doc.Title))
|
||||
sb.WriteString(fmt.Sprintf(" <div class=\"recent-note-meta\">\n"))
|
||||
sb.WriteString(fmt.Sprintf(" <span class=\"recent-note-date\">📅 %s</span>\n", dateStr))
|
||||
if len(doc.Tags) > 0 {
|
||||
sb.WriteString(fmt.Sprintf(" <span class=\"recent-note-tags\">"))
|
||||
for i, tag := range doc.Tags {
|
||||
if i > 0 {
|
||||
sb.WriteString(" ")
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf("#%s", tag))
|
||||
}
|
||||
sb.WriteString("</span>\n")
|
||||
}
|
||||
sb.WriteString(" </div>\n")
|
||||
if preview != "" {
|
||||
sb.WriteString(fmt.Sprintf(" <div class=\"recent-note-preview\">%s</div>\n", preview))
|
||||
}
|
||||
sb.WriteString(" </a>\n")
|
||||
sb.WriteString(" </div>\n")
|
||||
}
|
||||
|
||||
sb.WriteString("</div>\n\n")
|
||||
}
|
||||
|
||||
// generateFavoriteFolderContent génère le contenu d'un dossier favori
|
||||
func (h *Handler) generateFavoriteFolderContent(sb *strings.Builder, folderPath string, depth int) {
|
||||
// Construire le chemin absolu
|
||||
|
||||
@ -710,6 +710,30 @@ func (i *Indexer) GetBacklinks(path string) []string {
|
||||
return result
|
||||
}
|
||||
|
||||
// GetRecentDocuments retourne les N documents les plus récemment modifiés
|
||||
func (i *Indexer) GetRecentDocuments(limit int) []*Document {
|
||||
i.mu.RLock()
|
||||
defer i.mu.RUnlock()
|
||||
|
||||
// Copier tous les documents dans un slice
|
||||
docs := make([]*Document, 0, len(i.docs))
|
||||
for _, doc := range i.docs {
|
||||
docs = append(docs, doc)
|
||||
}
|
||||
|
||||
// Trier par date de dernière modification (décroissant)
|
||||
sort.Slice(docs, func(i, j int) bool {
|
||||
return docs[i].LastModified > docs[j].LastModified
|
||||
})
|
||||
|
||||
// Limiter le nombre de résultats
|
||||
if limit > 0 && len(docs) > limit {
|
||||
docs = docs[:limit]
|
||||
}
|
||||
|
||||
return docs
|
||||
}
|
||||
|
||||
// extractInternalLinks extrait tous les liens internes d'un texte Markdown/HTML
|
||||
// Format: <a ... hx-get="/api/notes/path/to/note.md" ...>
|
||||
func extractInternalLinks(body string) []string {
|
||||
|
||||
Reference in New Issue
Block a user