Import highlights in article order

This commit is contained in:
JP Hastings-Spital 2024-10-11 09:32:47 +01:00
parent 3932b6bc68
commit fc205a4eb5

View file

@ -12,6 +12,7 @@ import (
"path" "path"
"regexp" "regexp"
"slices" "slices"
"sort"
"strings" "strings"
"time" "time"
@ -223,8 +224,9 @@ type Article struct {
} }
type ArticleHighlight struct { type ArticleHighlight struct {
Quote string Quote string
Comment string Comment string
Position float64
} }
type FrontMatter struct { type FrontMatter struct {
@ -362,12 +364,15 @@ func parseResponse(body []byte) ([]Article, string, error) {
annotation = highlight.Annotation annotation = highlight.Annotation
} else { } else {
highlights = append(highlights, ArticleHighlight{ highlights = append(highlights, ArticleHighlight{
Quote: highlight.Quote, Quote: highlight.Quote,
Comment: highlight.Annotation, Comment: highlight.Annotation,
Position: highlight.Position,
}) })
} }
} }
sort.Sort(ByPosition(highlights))
if len(annotation) == 0 { if len(annotation) == 0 {
continue continue
} }
@ -447,3 +452,9 @@ func stripMarketing(rawURL string) string {
return u.String() return u.String()
} }
type ByPosition []ArticleHighlight
func (p ByPosition) Len() int { return len(p) }
func (p ByPosition) Less(i, j int) bool { return p[i].Position < p[j].Position }
func (p ByPosition) Swap(i, j int) { p[i], p[j] = p[j], p[i] }