mirror of
https://github.com/Xevion/glance.git
synced 2025-12-14 04:11:49 -06:00
Add preserve-order and limit props to RSS widget
This commit is contained in:
@@ -490,9 +490,22 @@ Example:
|
|||||||
| thumbnail-height | float | no | 10 |
|
| thumbnail-height | float | no | 10 |
|
||||||
| card-height | float | no | 27 |
|
| card-height | float | no | 27 |
|
||||||
| limit | integer | no | 25 |
|
| limit | integer | no | 25 |
|
||||||
|
| preserve-order | bool | no | false |
|
||||||
| single-line-titles | boolean | no | false |
|
| single-line-titles | boolean | no | false |
|
||||||
| collapse-after | integer | no | 5 |
|
| 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`
|
##### `style`
|
||||||
Used to change the appearance of the widget. Possible values are:
|
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 | |
|
| title | string | no | the title provided by the feed | |
|
||||||
| hide-categories | boolean | no | false | Only applicable for `detailed-list` style |
|
| hide-categories | boolean | no | false | Only applicable for `detailed-list` style |
|
||||||
| hide-description | 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 | | |
|
| item-link-prefix | string | no | | |
|
||||||
| headers | key (string) & value (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`
|
###### `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.
|
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
|
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
|
### Videos
|
||||||
Display a list of the latest videos from specific YouTube channels.
|
Display a list of the latest videos from specific YouTube channels.
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ type rssWidget struct {
|
|||||||
Limit int `yaml:"limit"`
|
Limit int `yaml:"limit"`
|
||||||
CollapseAfter int `yaml:"collapse-after"`
|
CollapseAfter int `yaml:"collapse-after"`
|
||||||
SingleLineTitles bool `yaml:"single-line-titles"`
|
SingleLineTitles bool `yaml:"single-line-titles"`
|
||||||
|
PreserveOrder bool `yaml:"preserve-order"`
|
||||||
NoItemsMessage string `yaml:"-"`
|
NoItemsMessage string `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +76,10 @@ func (widget *rssWidget) update(ctx context.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !widget.PreserveOrder {
|
||||||
|
items.sortByNewest()
|
||||||
|
}
|
||||||
|
|
||||||
if len(items) > widget.Limit {
|
if len(items) > widget.Limit {
|
||||||
items = items[:widget.Limit]
|
items = items[:widget.Limit]
|
||||||
}
|
}
|
||||||
@@ -143,6 +148,7 @@ type rssFeedRequest struct {
|
|||||||
Title string `yaml:"title"`
|
Title string `yaml:"title"`
|
||||||
HideCategories bool `yaml:"hide-categories"`
|
HideCategories bool `yaml:"hide-categories"`
|
||||||
HideDescription bool `yaml:"hide-description"`
|
HideDescription bool `yaml:"hide-description"`
|
||||||
|
Limit int `yaml:"limit"`
|
||||||
ItemLinkPrefix string `yaml:"item-link-prefix"`
|
ItemLinkPrefix string `yaml:"item-link-prefix"`
|
||||||
Headers map[string]string `yaml:"headers"`
|
Headers map[string]string `yaml:"headers"`
|
||||||
IsDetailed bool `yaml:"-"`
|
IsDetailed bool `yaml:"-"`
|
||||||
@@ -190,6 +196,10 @@ func fetchItemsFromRSSFeedTask(request rssFeedRequest) ([]rssFeedItem, error) {
|
|||||||
return nil, err
|
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))
|
items := make(rssFeedItemList, 0, len(feed.Items))
|
||||||
|
|
||||||
for i := range feed.Items {
|
for i := range feed.Items {
|
||||||
@@ -320,7 +330,6 @@ func fetchItemsFromRSSFeeds(requests []rssFeedRequest) (rssFeedItemList, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
failed := 0
|
failed := 0
|
||||||
|
|
||||||
entries := make(rssFeedItemList, 0, len(feeds)*10)
|
entries := make(rssFeedItemList, 0, len(feeds)*10)
|
||||||
|
|
||||||
for i := range feeds {
|
for i := range feeds {
|
||||||
@@ -337,8 +346,6 @@ func fetchItemsFromRSSFeeds(requests []rssFeedRequest) (rssFeedItemList, error)
|
|||||||
return nil, errNoContent
|
return nil, errNoContent
|
||||||
}
|
}
|
||||||
|
|
||||||
entries.sortByNewest()
|
|
||||||
|
|
||||||
if failed > 0 {
|
if failed > 0 {
|
||||||
return entries, fmt.Errorf("%w: missing %d RSS feeds", errPartialContent, failed)
|
return entries, fmt.Errorf("%w: missing %d RSS feeds", errPartialContent, failed)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user