mirror of
https://github.com/by-jp/www.byjp.me.git
synced 2025-08-10 19:05:41 +01:00
Import highlights in article order
This commit is contained in:
parent
3932b6bc68
commit
fc205a4eb5
1 changed files with 15 additions and 4 deletions
|
@ -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] }
|
||||||
|
|
Loading…
Reference in a new issue