feat(release): v0.1.0
commit06ed2c3cbeAuthor: adminoo <git@kadath.corp> Date: Tue Feb 3 11:34:24 2026 +0100 fix: changed detected by scanner but no updated by render layer commit01dcaf882aAuthor: adminoo <git@kadath.corp> Date: Tue Feb 3 10:19:05 2026 +0100 feat: VERSION bumb commit229223f77aAuthor: adminoo <git@kadath.corp> Date: Tue Feb 3 09:53:08 2026 +0100 feat: filter and search by tag commitcb11e34798Author: adminoo <git@kadath.corp> Date: Tue Feb 3 09:41:03 2026 +0100 feat: tag system commit3f5cf0d673Author: adminoo <git@kadath.corp> Date: Tue Feb 3 09:15:29 2026 +0100 feat: sqlite storage draft commitd6617cec02Author: adminoo <git@kadath.corp> Date: Tue Feb 3 09:04:11 2026 +0100 feat: metadata draft commit7238d02a13Author: adminoo <git@kadath.corp> Date: Mon Feb 2 10:18:42 2026 +0100 fix: body overflowing commit16ff836274Author: adminoo <git@kadath.corp> Date: Mon Feb 2 10:09:01 2026 +0100 feat: tests for http handlers and render package commit36ac3f03aaAuthor: adminoo <git@kadath.corp> Date: Mon Feb 2 09:45:29 2026 +0100 feat: Dark theme, placeholder metadata panel commite6923fa4f5Author: adminoo <git@kadath.corp> Date: Sun Feb 1 18:26:59 2026 +0100 fix: uneeded func + uneeded bogus note creation logic commit4458ba2d15Author: adminoo <git@kadath.corp> Date: Sun Feb 1 18:26:21 2026 +0100 feat: log when changing note states commit92a6f84540Author: adminoo <git@kadath.corp> Date: Sun Feb 1 16:55:40 2026 +0100 possibly first working draft commite27aadc603Author: adminoo <git@kadath.corp> Date: Sun Feb 1 11:55:16 2026 +0100 draft shits
This commit is contained in:
74
internal/note/note.go
Normal file
74
internal/note/note.go
Normal file
@ -0,0 +1,74 @@
|
||||
package note
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Note struct {
|
||||
ID string
|
||||
Path string
|
||||
Title string
|
||||
Content string
|
||||
Size int64
|
||||
// HTMLContent string
|
||||
// Directly in Note
|
||||
Tags []string
|
||||
UpdatedAt time.Time
|
||||
Published bool
|
||||
}
|
||||
|
||||
func NewNote() *Note {
|
||||
return &Note{}
|
||||
}
|
||||
|
||||
func formatDateRep(date time.Time) string {
|
||||
return date.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
func (n *Note) GetUpdateDateRep() string {
|
||||
return formatDateRep(n.UpdatedAt)
|
||||
}
|
||||
|
||||
// ExtractTitle return the first level heading content ('# title')
|
||||
func ExtractTitle(mkd string) string {
|
||||
if mkd == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
lines := strings.Split(mkd, "\n")
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if strings.HasPrefix(line, "# ") {
|
||||
// Extract title from # heading
|
||||
title := strings.TrimPrefix(line, "# ")
|
||||
title = strings.TrimSpace(title)
|
||||
// Remove common markdown formatting
|
||||
title = removeMarkdownFormatting(title)
|
||||
return title
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// removeMarkdownFormatting removes common markdown formatting from text
|
||||
func removeMarkdownFormatting(text string) string {
|
||||
// Remove **bold** and *italic* formatting
|
||||
result := text
|
||||
result = strings.ReplaceAll(result, "**", "")
|
||||
result = strings.ReplaceAll(result, "*", "")
|
||||
result = strings.ReplaceAll(result, "_", "")
|
||||
result = strings.ReplaceAll(result, "`", "")
|
||||
result = strings.ReplaceAll(result, "~~", "")
|
||||
|
||||
// Clean up multiple spaces
|
||||
result = strings.Join(strings.Fields(result), " ")
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func GenerateNoteID(path string) string {
|
||||
return fmt.Sprintf("%x", sha256.Sum256([]byte(path)))[:10]
|
||||
}
|
||||
87
internal/note/note_test.go
Normal file
87
internal/note/note_test.go
Normal file
@ -0,0 +1,87 @@
|
||||
package note
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestExtractTitle(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
markdown string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "first h1 becomes title",
|
||||
markdown: "# My Note\n\nSome content",
|
||||
want: "My Note",
|
||||
},
|
||||
{
|
||||
name: "no h1 uses filename",
|
||||
markdown: "## Just h2\n\nContent",
|
||||
want: "", // or filename from context
|
||||
},
|
||||
{
|
||||
name: "multiple h1s takes first",
|
||||
markdown: "# First\n\n# Second",
|
||||
want: "First",
|
||||
},
|
||||
{
|
||||
name: "h1 with formatting",
|
||||
markdown: "# **Bold** and *italic* title",
|
||||
want: "Bold and italic title",
|
||||
},
|
||||
{
|
||||
name: "empty file",
|
||||
markdown: "",
|
||||
want: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range cases {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := ExtractTitle(tt.markdown)
|
||||
if got != tt.want {
|
||||
t.Errorf("got %q, want %q", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateNoteID(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
want string // SHA-256 hash
|
||||
}{
|
||||
{
|
||||
name: "consistent hashing",
|
||||
path: "notes/test.md",
|
||||
want: "110bab5b8f",
|
||||
},
|
||||
{
|
||||
name: "different paths different ids",
|
||||
path: "notes/other.md",
|
||||
want: "858d15849b",
|
||||
},
|
||||
{
|
||||
name: "root folder as 'current folder'",
|
||||
path: ".",
|
||||
want: "cdb4ee2aea",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := GenerateNoteID(tt.path)
|
||||
if got != tt.want {
|
||||
t.Errorf("got %q, want %q", got, tt.want)
|
||||
}
|
||||
|
||||
// Test consistency
|
||||
got2 := GenerateNoteID(tt.path)
|
||||
if got != got2 {
|
||||
t.Error("same path should produce same ID")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user