Added theme options

This commit is contained in:
Leon Mika 2025-03-30 11:15:46 +11:00
parent 68a6169bc3
commit ab5c101fcc
5 changed files with 66 additions and 4 deletions

View file

@ -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"`
}

View file

@ -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,
}
}