Merge remote-tracking branch 'upstream/dev' into theme_switcher

This commit is contained in:
Svilen Markov
2025-04-29 18:55:30 +01:00
parent 62e9c32082
commit a68805b55d
116 changed files with 8020 additions and 3095 deletions
+31 -5
View File
@@ -15,8 +15,9 @@ import (
const videosWidgetPlaylistPrefix = "playlist:"
var (
videosWidgetTemplate = mustParseTemplate("videos.html", "widget-base.html", "video-card-contents.html")
videosWidgetGridTemplate = mustParseTemplate("videos-grid.html", "widget-base.html", "video-card-contents.html")
videosWidgetTemplate = mustParseTemplate("videos.html", "widget-base.html", "video-card-contents.html")
videosWidgetGridTemplate = mustParseTemplate("videos-grid.html", "widget-base.html", "video-card-contents.html")
videosWidgetVerticalListTemplate = mustParseTemplate("videos-vertical-list.html", "widget-base.html")
)
type videosWidget struct {
@@ -24,8 +25,10 @@ type videosWidget struct {
Videos videoList `yaml:"-"`
VideoUrlTemplate string `yaml:"video-url-template"`
Style string `yaml:"style"`
CollapseAfter int `yaml:"collapse-after"`
CollapseAfterRows int `yaml:"collapse-after-rows"`
Channels []string `yaml:"channels"`
Playlists []string `yaml:"playlists"`
Limit int `yaml:"limit"`
IncludeShorts bool `yaml:"include-shorts"`
}
@@ -41,6 +44,22 @@ func (widget *videosWidget) initialize() error {
widget.CollapseAfterRows = 4
}
if widget.CollapseAfter == 0 || widget.CollapseAfter < -1 {
widget.CollapseAfter = 7
}
// A bit cheeky, but from a user's perspective it makes more sense when channels and
// playlists are separate things rather than specifying a list of channels and some of
// them awkwardly have a "playlist:" prefix
if len(widget.Playlists) > 0 {
initialLen := len(widget.Channels)
widget.Channels = append(widget.Channels, make([]string, len(widget.Playlists))...)
for i := range widget.Playlists {
widget.Channels[initialLen+i] = videosWidgetPlaylistPrefix + widget.Playlists[i]
}
}
return nil
}
@@ -59,11 +78,18 @@ func (widget *videosWidget) update(ctx context.Context) {
}
func (widget *videosWidget) Render() template.HTML {
if widget.Style == "grid-cards" {
return widget.renderTemplate(widget, videosWidgetGridTemplate)
var template *template.Template
switch widget.Style {
case "grid-cards":
template = videosWidgetGridTemplate
case "vertical-list":
template = videosWidgetVerticalListTemplate
default:
template = videosWidgetTemplate
}
return widget.renderTemplate(widget, videosWidgetTemplate)
return widget.renderTemplate(widget, template)
}
type youtubeFeedResponseXml struct {