Skip to content

A self-hosted dashboard that puts all your feeds in one place

Add `preserve-order` and `limit` props to RSS widget

Svilen Markovaf70cc83bab6
diff --git a/docs/configuration.md b/docs/configuration.md
index cc24f56..05ca46a 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -490,9 +490,22 @@ Example:
| thumbnail-height | float | no | 10 |
| card-height | float | no | 27 |
| limit | integer | no | 25 |
+| preserve-order | bool | no | false |
| single-line-titles | boolean | no | false |
| collapse-after | integer | no | 5 |
+##### `limit`
+The maximum number of articles to show.
+
+##### `collapse-after`
+How many articles are visible before the "SHOW MORE" button appears. Set to `-1` to never collapse.
+
+##### `preserve-order`
+When set to `true`, the order of the articles will be preserved as they are in the feeds. Useful if a feed uses its own sorting order which denotes the importance of the articles. If you use this property while having a lot of feeds, it's recommended to set a `limit` to each individual feed since if the first defined feed has 15 articles, the articles from the second feed will start after the 15th article in the list.
+
+##### `single-line-titles`
+When set to `true`, truncates the title of each post if it exceeds one line. Only applies when the style is set to `vertical-list`.
+
##### `style`
Used to change the appearance of the widget. Possible values are:
@@ -535,9 +548,13 @@ An array of RSS/atom feeds. The title can optionally be changed.
| title | string | no | the title provided by the feed | |
| hide-categories | boolean | no | false | Only applicable for `detailed-list` style |
| hide-description | boolean | no | false | Only applicable for `detailed-list` style |
+| limit | integer | no | | |
| item-link-prefix | string | no | | |
| headers | key (string) & value (string) | no | | |
+###### `limit`
+The maximum number of articles to show from that specific feed. Useful if you have a feed which posts a lot of articles frequently and you want to prevent it from excessively pushing down articles from other feeds.
+
###### `item-link-prefix`
If an RSS feed isn't returning item links with a base domain and Glance has failed to automatically detect the correct domain you can manually add a prefix to each link with this property.
@@ -552,15 +569,6 @@ Optionally specify the headers that will be sent with the request. Example:
User-Agent: Custom User Agent
```
-##### `limit`
-The maximum number of articles to show.
-
-##### `single-line-titles`
-When set to `true`, truncates the title of each post if it exceeds one line. Only applies when the style is set to `vertical-list`.
-
-##### `collapse-after`
-How many articles are visible before the "SHOW MORE" button appears. Set to `-1` to never collapse.
-
### Videos
Display a list of the latest videos from specific YouTube channels.
diff --git a/internal/glance/widget-rss.go b/internal/glance/widget-rss.go
index f24d828..e7d2e8b 100644
--- a/internal/glance/widget-rss.go
+++ b/internal/glance/widget-rss.go
@@ -35,6 +35,7 @@ type rssWidget struct {
Limit int `yaml:"limit"`
CollapseAfter int `yaml:"collapse-after"`
SingleLineTitles bool `yaml:"single-line-titles"`
+ PreserveOrder bool `yaml:"preserve-order"`
NoItemsMessage string `yaml:"-"`
}
@@ -75,6 +76,10 @@ func (widget *rssWidget) update(ctx context.Context) {
return
}
+ if !widget.PreserveOrder {
+ items.sortByNewest()
+ }
+
if len(items) > widget.Limit {
items = items[:widget.Limit]
}
@@ -143,6 +148,7 @@ type rssFeedRequest struct {
Title string `yaml:"title"`
HideCategories bool `yaml:"hide-categories"`
HideDescription bool `yaml:"hide-description"`
+ Limit int `yaml:"limit"`
ItemLinkPrefix string `yaml:"item-link-prefix"`
Headers map[string]string `yaml:"headers"`
IsDetailed bool `yaml:"-"`
@@ -190,6 +196,10 @@ func fetchItemsFromRSSFeedTask(request rssFeedRequest) ([]rssFeedItem, error) {
return nil, err
}
+ if request.Limit > 0 && len(feed.Items) > request.Limit {
+ feed.Items = feed.Items[:request.Limit]
+ }
+
items := make(rssFeedItemList, 0, len(feed.Items))
for i := range feed.Items {
@@ -320,7 +330,6 @@ func fetchItemsFromRSSFeeds(requests []rssFeedRequest) (rssFeedItemList, error)
}
failed := 0
-
entries := make(rssFeedItemList, 0, len(feeds)*10)
for i := range feeds {
@@ -337,8 +346,6 @@ func fetchItemsFromRSSFeeds(requests []rssFeedRequest) (rssFeedItemList, error)
return nil, errNoContent
}
- entries.sortByNewest()
-
if failed > 0 {
return entries, fmt.Errorf("%w: missing %d RSS feeds", errPartialContent, failed)
}