diff --git a/docs/configuration.md b/docs/configuration.md index 9a8c2be..2dffb2e 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -357,6 +357,7 @@ pages: | ---- | ---- | -------- | | type | string | yes | | title | string | no | +| title-url | string | no | | cache | string | no | | css-class | string | no | @@ -366,6 +367,9 @@ Used to specify the widget. #### `title` The title of the widget. If left blank it will be defined by the widget. +#### `title-url` +The URL to go to when clicking on the widget's title. If left blank it will be defined by the widget (if available). + #### `cache` How long to keep the fetched data in memory. The value is a string and must be a number followed by one of s, m, h, d. Examples: diff --git a/internal/assets/templates/widget-base.html b/internal/assets/templates/widget-base.html index c32f9d0..eed89e1 100644 --- a/internal/assets/templates/widget-base.html +++ b/internal/assets/templates/widget-base.html @@ -1,6 +1,6 @@
-
{{ .Title }}
+ {{ if ne "" .TitleURL}}{{ .Title }}{{ else }}
{{ .Title }}
{{ end }} {{ if and .Error .ContentAvailable }}
{{ else if .Notice }} diff --git a/internal/widget/hacker-news.go b/internal/widget/hacker-news.go index 9beccb7..f2db6e3 100644 --- a/internal/widget/hacker-news.go +++ b/internal/widget/hacker-news.go @@ -21,7 +21,10 @@ type HackerNews struct { } func (widget *HackerNews) Initialize() error { - widget.withTitle("Hacker News").withCacheDuration(30 * time.Minute) + widget. + withTitle("Hacker News"). + withTitleURL("https://news.ycombinator.com/"). + withCacheDuration(30 * time.Minute) if widget.Limit <= 0 { widget.Limit = 15 diff --git a/internal/widget/lobsters.go b/internal/widget/lobsters.go index 61f8261..a783c31 100644 --- a/internal/widget/lobsters.go +++ b/internal/widget/lobsters.go @@ -24,6 +24,12 @@ type Lobsters struct { func (widget *Lobsters) Initialize() error { widget.withTitle("Lobsters").withCacheDuration(time.Hour) + if widget.InstanceURL == "" { + widget.withTitleURL("https://lobste.rs") + } else { + widget.withTitleURL(widget.InstanceURL) + } + if widget.SortBy == "" || (widget.SortBy != "hot" && widget.SortBy != "new") { widget.SortBy = "hot" } diff --git a/internal/widget/reddit.go b/internal/widget/reddit.go index 0aa5f93..1aa16fb 100644 --- a/internal/widget/reddit.go +++ b/internal/widget/reddit.go @@ -54,7 +54,10 @@ func (widget *Reddit) Initialize() error { } } - widget.withTitle("/r/" + widget.Subreddit).withCacheDuration(30 * time.Minute) + widget. + withTitle("/r/" + widget.Subreddit). + withTitleURL("https://www.reddit.com/r/" + widget.Subreddit + "/"). + withCacheDuration(30 * time.Minute) return nil } diff --git a/internal/widget/twitch-channels.go b/internal/widget/twitch-channels.go index 3b728b8..b06c986 100644 --- a/internal/widget/twitch-channels.go +++ b/internal/widget/twitch-channels.go @@ -18,7 +18,10 @@ type TwitchChannels struct { } func (widget *TwitchChannels) Initialize() error { - widget.withTitle("Twitch Channels").withCacheDuration(time.Minute * 10) + widget. + withTitle("Twitch Channels"). + withTitleURL("https://www.twitch.tv/directory/following"). + withCacheDuration(time.Minute * 10) if widget.CollapseAfter == 0 || widget.CollapseAfter < -1 { widget.CollapseAfter = 5 diff --git a/internal/widget/twitch-top-games.go b/internal/widget/twitch-top-games.go index 812c3c6..85933a6 100644 --- a/internal/widget/twitch-top-games.go +++ b/internal/widget/twitch-top-games.go @@ -18,7 +18,10 @@ type TwitchGames struct { } func (widget *TwitchGames) Initialize() error { - widget.withTitle("Top games on Twitch").withCacheDuration(time.Minute * 10) + 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 diff --git a/internal/widget/widget.go b/internal/widget/widget.go index 574db1d..324477f 100644 --- a/internal/widget/widget.go +++ b/internal/widget/widget.go @@ -119,6 +119,7 @@ const ( type widgetBase struct { Type string `yaml:"type"` Title string `yaml:"title"` + TitleURL string `yaml:"title-url"` CSSClass string `yaml:"css-class"` CustomCacheDuration DurationField `yaml:"cache"` ContentAvailable bool `yaml:"-"` @@ -186,6 +187,14 @@ func (w *widgetBase) withTitle(title string) *widgetBase { return w } +func (w *widgetBase) withTitleURL(titleURL string) *widgetBase { + if w.TitleURL == "" { + w.TitleURL = titleURL + } + + return w +} + func (w *widgetBase) withCacheDuration(duration time.Duration) *widgetBase { w.cacheType = cacheTypeDuration