tagliatelle

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 6c74e9928d1ae157ade5ce1b8ae03dddcfc2e329
parent a8aa7aafc1b80a238ef840134d9b9b03e9a4a18a
Author: breadcat <breadcat@users.noreply.github.com>
Date:   Sat, 11 Apr 2026 10:35:03 +0100

analyzeNotes replaces existing GetNoteStats, GetCategories and CountLines

Diffstat:
Minclude-notes.go | 77+++++++++++++++++++++++------------------------------------------------------
Minclude-types.go | 6++++++
2 files changed, 29 insertions(+), 54 deletions(-)

diff --git a/include-notes.go b/include-notes.go @@ -158,9 +158,11 @@ func FilterByCategory(content, category string) string { return strings.Join(filtered, "\n") } -// GetCategories returns a sorted list of unique categories -func GetCategories(content string) []string { +func analyzeNotes(content string) notesAnalysis { lines := strings.Split(content, "\n") + + totalLines := 0 + categorizedLines := 0 categoryMap := make(map[string]bool) for _, line := range lines { @@ -168,9 +170,10 @@ func GetCategories(content string) []string { if trimmed == "" { continue } - + totalLines++ note := ParseNote(trimmed) if note.Category != "" { + categorizedLines++ categoryMap[note.Category] = true } } @@ -179,52 +182,18 @@ func GetCategories(content string) []string { for cat := range categoryMap { categories = append(categories, cat) } - sort.Strings(categories) - return categories -} - -// GetNoteStats returns statistics about the notes -func GetNoteStats(content string) map[string]int { - lines := strings.Split(content, "\n") - totalLines := 0 - categorizedLines := 0 - categories := make(map[string]bool) - - for _, line := range lines { - trimmed := strings.TrimSpace(line) - if trimmed == "" { - continue - } - - totalLines++ - note := ParseNote(trimmed) - - if note.Category != "" { - categorizedLines++ - categories[note.Category] = true - } - } - - return map[string]int{ - "total_lines": totalLines, - "categorized_lines": categorizedLines, - "uncategorized": totalLines - categorizedLines, - "unique_categories": len(categories), - } -} - -// CountLines returns the number of non-empty lines -func CountLines(content string) int { - lines := strings.Split(content, "\n") - count := 0 - for _, line := range lines { - if strings.TrimSpace(line) != "" { - count++ - } + return notesAnalysis{ + Stats: map[string]int{ + "total_lines": totalLines, + "categorized_lines": categorizedLines, + "uncategorized": totalLines - categorizedLines, + "unique_categories": len(categories), + }, + Categories: categories, + LineCount: totalLines, } - return count } // notesViewHandler displays the notes editor page @@ -236,8 +205,7 @@ func notesViewHandler(w http.ResponseWriter, r *http.Request) { return } - stats := GetNoteStats(content) - categories := GetCategories(content) + analysis := analyzeNotes(content) notesData := struct { Content string @@ -246,8 +214,8 @@ func notesViewHandler(w http.ResponseWriter, r *http.Request) { SedRules []SedRule }{ Content: content, - Stats: stats, - Categories: categories, + Stats: analysis.Stats, + Categories: analysis.Categories, SedRules: config.SedRules, } @@ -318,7 +286,7 @@ func notesStatsHandler(w http.ResponseWriter, r *http.Request) { return } - stats := GetNoteStats(content) + stats := analyzeNotes(content).Stats w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(stats) @@ -374,7 +342,7 @@ func notesApplySedHandler(w http.ResponseWriter, r *http.Request) { response := map[string]interface{}{ "success": true, "content": result, - "stats": GetNoteStats(result), + "stats": analyzeNotes(result).Stats, } log.Printf("Info: notesApplySedHandler: sed rule success, returning %d bytes", len(result)) json.NewEncoder(w).Encode(response) @@ -391,13 +359,14 @@ func notesPreviewHandler(w http.ResponseWriter, r *http.Request) { // Process (deduplicate and sort) processed := ProcessNotes(content) + analysis := analyzeNotes(processed) w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(map[string]interface{}{ "success": true, "content": processed, - "stats": GetNoteStats(processed), - "lineCount": CountLines(processed), + "stats": analysis.Stats, + "lineCount": analysis.LineCount, }) } diff --git a/include-types.go b/include-types.go @@ -137,4 +137,10 @@ type AdminPageData struct { OrphanData OrphanData ActiveTab string MissingThumbnails []VideoFile +} + +type notesAnalysis struct { + Stats map[string]int + Categories []string + LineCount int } \ No newline at end of file