mirror of
https://github.com/glanceapp/glance.git
synced 2024-11-24 17:35:06 +01:00
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package widget
|
|
|
|
import (
|
|
"context"
|
|
"html/template"
|
|
"time"
|
|
|
|
"github.com/glanceapp/glance/internal/assets"
|
|
"github.com/glanceapp/glance/internal/feed"
|
|
)
|
|
|
|
type TwitchGames struct {
|
|
widgetBase `yaml:",inline"`
|
|
Categories []feed.TwitchCategory `yaml:"-"`
|
|
Exclude []string `yaml:"exclude"`
|
|
Limit int `yaml:"limit"`
|
|
CollapseAfter int `yaml:"collapse-after"`
|
|
}
|
|
|
|
func (widget *TwitchGames) Initialize() error {
|
|
widget.
|
|
withTitle("Top games on Twitch").
|
|
withTitleURL("https://www.twitch.tv/directory?sort=VIEWER_COUNT").
|
|
withCacheDuration(time.Minute * 10)
|
|
|
|
if widget.Limit <= 0 {
|
|
widget.Limit = 10
|
|
}
|
|
|
|
if widget.CollapseAfter == 0 || widget.CollapseAfter < -1 {
|
|
widget.CollapseAfter = 5
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (widget *TwitchGames) Update(ctx context.Context) {
|
|
categories, err := feed.FetchTopGamesFromTwitch(widget.Exclude, widget.Limit)
|
|
|
|
if !widget.canContinueUpdateAfterHandlingErr(err) {
|
|
return
|
|
}
|
|
|
|
widget.Categories = categories
|
|
}
|
|
|
|
func (widget *TwitchGames) Render() template.HTML {
|
|
return widget.render(widget, assets.TwitchGamesListTemplate)
|
|
}
|