mirror of
https://github.com/glanceapp/glance.git
synced 2024-12-14 08:11:59 +03:00
Allow specifying sort order and tags through config
This commit is contained in:
parent
3aa1f273b6
commit
720549ec7e
@ -2,6 +2,7 @@ package feed
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -54,7 +55,22 @@ func getLobstersPostsFromFeed(feedUrl string) (ForumPosts, error) {
|
||||
return posts, nil
|
||||
}
|
||||
|
||||
func FetchLobstersTopPosts(feedUrl string) (ForumPosts, error) {
|
||||
func FetchLobstersPosts(sortBy string, tags []string) (ForumPosts, error) {
|
||||
var feedUrl string
|
||||
|
||||
if sortBy == "hot" {
|
||||
sortBy = "hottest"
|
||||
} else if sortBy == "new" {
|
||||
sortBy = "newest"
|
||||
}
|
||||
|
||||
if len(tags) == 0 {
|
||||
feedUrl = "https://lobste.rs/" + sortBy + ".json"
|
||||
} else {
|
||||
tags := strings.Join(tags, ",")
|
||||
feedUrl = "https://lobste.rs/t/" + tags + ".json"
|
||||
}
|
||||
|
||||
posts, err := getLobstersPostsFromFeed(feedUrl)
|
||||
|
||||
if err != nil {
|
||||
|
@ -11,18 +11,19 @@ import (
|
||||
|
||||
type Lobsters struct {
|
||||
widgetBase `yaml:",inline"`
|
||||
FeedUrl string `yaml:"feed"`
|
||||
Posts feed.ForumPosts `yaml:"-"`
|
||||
Limit int `yaml:"limit"`
|
||||
CollapseAfter int `yaml:"collapse-after"`
|
||||
SortBy string `yaml:"sort-by"`
|
||||
Tags []string `yaml:"tags"`
|
||||
ShowThumbnails bool `yaml:"-"`
|
||||
}
|
||||
|
||||
func (widget *Lobsters) Initialize() error {
|
||||
widget.withTitle("Lobsters").withCacheDuration(30 * time.Minute)
|
||||
|
||||
if widget.FeedUrl == "" {
|
||||
widget.FeedUrl = "https://lobste.rs/hottest.json"
|
||||
if widget.SortBy == "" || (widget.SortBy != "hot" && widget.SortBy != "new") {
|
||||
widget.SortBy = "hot"
|
||||
}
|
||||
|
||||
if widget.Limit <= 0 {
|
||||
@ -37,7 +38,7 @@ func (widget *Lobsters) Initialize() error {
|
||||
}
|
||||
|
||||
func (widget *Lobsters) Update(ctx context.Context) {
|
||||
posts, err := feed.FetchLobstersTopPosts(widget.FeedUrl)
|
||||
posts, err := feed.FetchLobstersPosts(widget.SortBy, widget.Tags)
|
||||
|
||||
if !widget.canContinueUpdateAfterHandlingErr(err) {
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user