Browse Source

Allow setting widget title URL

Svilen Markov 1 year ago
parent
commit
514cf2b81c

+ 4 - 0
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:
 

+ 1 - 1
internal/assets/templates/widget-base.html

@@ -1,6 +1,6 @@
 <div class="widget widget-type-{{ .GetType }}{{ if ne "" .CSSClass }} {{ .CSSClass }}{{ end }}">
     <div class="widget-header">
-        <div class="uppercase">{{ .Title }}</div>
+        {{ if ne "" .TitleURL}}<a href="{{ .TitleURL }}" target="_blank" rel="noreferrer" class="uppercase">{{ .Title }}</a>{{ else }}<div class="uppercase">{{ .Title }}</div>{{ end }}
         {{ if and .Error .ContentAvailable }}
         <div class="notice-icon notice-icon-major" title="{{ .Error }}"></div>
         {{ else if .Notice }}

+ 4 - 1
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

+ 6 - 0
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"
 	}

+ 4 - 1
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
 }

+ 4 - 1
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

+ 4 - 1
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

+ 9 - 0
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