Add flag to specify number of articles per source
This commit is contained in:
parent
b0904bf2ae
commit
4c35eaad3b
1 changed files with 25 additions and 14 deletions
15
openring.go
15
openring.go
|
@ -28,11 +28,12 @@ type Article struct {
|
||||||
func main() {
|
func main() {
|
||||||
var (
|
var (
|
||||||
narticles int = 3
|
narticles int = 3
|
||||||
|
perSource int = 1
|
||||||
summaryLen int = 256
|
summaryLen int = 256
|
||||||
sources []*url.URL
|
sources []*url.URL
|
||||||
)
|
)
|
||||||
|
|
||||||
opts, optind, err := getopt.Getopts(os.Args[1:], "l:n:s:")
|
opts, optind, err := getopt.Getopts(os.Args[1:], "l:n:p:s:")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -48,6 +49,11 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
case 'p':
|
||||||
|
perSource, err = strconv.Atoi(opt.Value)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
case 's':
|
case 's':
|
||||||
u, err := url.Parse(opt.Value)
|
u, err := url.Parse(opt.Value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -103,7 +109,11 @@ func main() {
|
||||||
log.Printf("Warning: feed %s has no items", feed.Title)
|
log.Printf("Warning: feed %s has no items", feed.Title)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
item := feed.Items[0]
|
items := feed.Items
|
||||||
|
if len(items) > perSource {
|
||||||
|
items = items[:perSource]
|
||||||
|
}
|
||||||
|
for _, item := range items {
|
||||||
summary := runewidth.Truncate(
|
summary := runewidth.Truncate(
|
||||||
policy.Sanitize(item.Summary), summaryLen, "…")
|
policy.Sanitize(item.Summary), summaryLen, "…")
|
||||||
articles = append(articles, &Article{
|
articles = append(articles, &Article{
|
||||||
|
@ -115,6 +125,7 @@ func main() {
|
||||||
Link: item.Link,
|
Link: item.Link,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
sort.Slice(articles, func(i, j int) bool {
|
sort.Slice(articles, func(i, j int) bool {
|
||||||
return articles[i].Date.After(articles[j].Date)
|
return articles[i].Date.After(articles[j].Date)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue