From fc205a4eb5f8b36d5565229ffa86d27427c473d2 Mon Sep 17 00:00:00 2001 From: JP Hastings-Spital Date: Fri, 11 Oct 2024 09:32:47 +0100 Subject: [PATCH] Import highlights in article order --- tools/import/omnivore/main.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/tools/import/omnivore/main.go b/tools/import/omnivore/main.go index efebcc92..53c65a50 100644 --- a/tools/import/omnivore/main.go +++ b/tools/import/omnivore/main.go @@ -12,6 +12,7 @@ import ( "path" "regexp" "slices" + "sort" "strings" "time" @@ -223,8 +224,9 @@ type Article struct { } type ArticleHighlight struct { - Quote string - Comment string + Quote string + Comment string + Position float64 } type FrontMatter struct { @@ -362,12 +364,15 @@ func parseResponse(body []byte) ([]Article, string, error) { annotation = highlight.Annotation } else { highlights = append(highlights, ArticleHighlight{ - Quote: highlight.Quote, - Comment: highlight.Annotation, + Quote: highlight.Quote, + Comment: highlight.Annotation, + Position: highlight.Position, }) } } + sort.Sort(ByPosition(highlights)) + if len(annotation) == 0 { continue } @@ -447,3 +452,9 @@ func stripMarketing(rawURL string) 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] }