mirror of
https://github.com/by-jp/www.byjp.me.git
synced 2025-08-09 05:36:07 +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"
|
||||
"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] }
|
||||
|
|
Loading…
Reference in a new issue