Fork Notesium source and restructure into Go package layout
Initial fork of github.com/alonswartz/notesium into librenotes: - Source moved to internal/notesium/ (package notesium) - Thin entry point at cmd/librenotes/main.go - Module renamed to git.librete.ch/public/librenotes - main() exposed as notesium.Run() - LICENSE preserved (MIT), NOTICE added with attribution - Web assets and completion.bash co-located with embedding code to satisfy go:embed path constraints Closes #3, #34, #35. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package notesium
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type SortByCtime []*Note
|
||||
type SortByMtime []*Note
|
||||
type SortByTitle []*Note
|
||||
|
||||
func (n SortByCtime) Len() int { return len(n) }
|
||||
func (n SortByCtime) Less(i, j int) bool { return n[i].Ctime.After(n[j].Ctime) }
|
||||
func (n SortByCtime) Swap(i, j int) { n[i], n[j] = n[j], n[i] }
|
||||
|
||||
func (n SortByMtime) Len() int { return len(n) }
|
||||
func (n SortByMtime) Less(i, j int) bool { return n[i].Mtime.After(n[j].Mtime) }
|
||||
func (n SortByMtime) Swap(i, j int) { n[i], n[j] = n[j], n[i] }
|
||||
|
||||
func (n SortByTitle) Len() int { return len(n) }
|
||||
func (n SortByTitle) Less(i, j int) bool { return n[i].Title < n[j].Title }
|
||||
func (n SortByTitle) Swap(i, j int) { n[i], n[j] = n[j], n[i] }
|
||||
|
||||
func getSortedNotes(sortBy string) []*Note {
|
||||
notes := make([]*Note, 0, len(noteCache))
|
||||
|
||||
for _, note := range noteCache {
|
||||
notes = append(notes, note)
|
||||
}
|
||||
|
||||
switch sortBy {
|
||||
case "ctime":
|
||||
sort.Sort(SortByCtime(notes))
|
||||
case "mtime":
|
||||
sort.Sort(SortByMtime(notes))
|
||||
case "alpha":
|
||||
sort.Sort(SortByTitle(notes))
|
||||
}
|
||||
|
||||
return notes
|
||||
}
|
||||
|
||||
func sortLinesByField(lines []string, separator string, fieldIndex int) {
|
||||
sort.Slice(lines, func(i, j int) bool {
|
||||
subI := strings.SplitN(lines[i], separator, fieldIndex+1)[fieldIndex]
|
||||
subJ := strings.SplitN(lines[j], separator, fieldIndex+1)[fieldIndex]
|
||||
return subI < subJ
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user