diff --git a/models/theme.go b/models/theme.go index 3112c7d..392b348 100644 --- a/models/theme.go +++ b/models/theme.go @@ -2,10 +2,28 @@ package models import "io/fs" +type ThemeOptionType int + +const ( + ThemeOptionTypeString ThemeOptionType = iota + ThemeOptionTypeInt +) + +type ThemeOption struct { + Name string + Label string + Description string + Type ThemeOptionType + DefaultValue string +} + type ThemeMeta struct { ID string Name string + // Options + Options []ThemeOption + // Source repo URL string OverlayFS fs.FS diff --git a/providers/hugo/config.go b/providers/hugo/config.go index 8b04263..9fa24de 100644 --- a/providers/hugo/config.go +++ b/providers/hugo/config.go @@ -11,6 +11,7 @@ type hugoConfig struct { Theme string `yaml:"theme"` CanonifyURLs bool `yaml:"canonifyURLs,omitempty"` Permalinks permalinksConfig `yaml:"permalinks,omitempty"` + Params map[string]any `yaml:"params,omitempty"` Markup hugoConfigMarkup `yaml:"markup"` } diff --git a/providers/hugo/provider.go b/providers/hugo/provider.go index 511b067..552e440 100644 --- a/providers/hugo/provider.go +++ b/providers/hugo/provider.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "path/filepath" + "strconv" ) type Provider struct { @@ -123,6 +124,7 @@ func (p *Provider) ReconfigureSite(ctx context.Context, isPreviewConfig bool, co }, }, }, + Params: p.configureParams(ctx, site, meta), } if isPreviewConfig { @@ -146,3 +148,34 @@ func (p *Provider) ReconfigureSite(ctx context.Context, isPreviewConfig bool, co return nil } + +func (p *Provider) configureParams(ctx context.Context, site models.Site, meta models.ThemeMeta) map[string]any { + // Options from the theme + themeOptions := make(map[string]any) + for _, option := range meta.Options { + var typedVal any + + strVal := option.DefaultValue + + switch option.Type { + case models.ThemeOptionTypeString: + typedVal = strVal + case models.ThemeOptionTypeInt: + intVal, err := strconv.Atoi(strVal) + if err != nil { + log.Printf("invalid theme option value: name %v, type %v, value %v", option.Name, option.Type, strVal) + continue + } + typedVal = intVal + default: + log.Printf("unknown theme option type: name %v, type %v", option.Name, option.Type) + continue + } + + themeOptions[option.Name] = typedVal + } + + return map[string]any{ + "theme_options": themeOptions, + } +} diff --git a/providers/themes/meta.go b/providers/themes/meta.go index 5946b1f..6c2fb90 100644 --- a/providers/themes/meta.go +++ b/providers/themes/meta.go @@ -7,9 +7,19 @@ import ( var themes = []models.ThemeMeta{ { - ID: "bear", - Name: "Bear", - URL: "https://github.com/janraasch/hugo-bearblog", + ID: "bear", + Name: "Bear", + URL: "https://github.com/janraasch/hugo-bearblog", + Options: []models.ThemeOption{ + { + Name: "homepage_post_limit", + Label: "Homepage Post Limit", + Description: "Number of links to post on homepage", + Type: models.ThemeOptionTypeInt, + DefaultValue: "30", + }, + }, + OverlayFS: overlays.HugoBearblogFS, Overlays: map[string]string{ "hugo-bearblog/archetype-posts.md": "archetypes/posts.md", diff --git a/providers/themes/overlays/hugo-bearblog/index.html b/providers/themes/overlays/hugo-bearblog/index.html index 573123f..34af384 100644 --- a/providers/themes/overlays/hugo-bearblog/index.html +++ b/providers/themes/overlays/hugo-bearblog/index.html @@ -4,7 +4,7 @@

Recent Posts