Allow arbitrary data to be passed to templates

This commit is contained in:
Marc-André Dufresne
2019-08-06 13:14:53 -04:00
parent 6ae11a1cfe
commit d458e882aa
4 changed files with 43 additions and 0 deletions

View File

@@ -107,6 +107,9 @@ type WebConfig struct {
// Defaults to "coreos"
Theme string
// Map of extra values passed into the templates
Extra map[string]string
}
func value(val, defaultValue time.Duration) time.Duration {
@@ -181,6 +184,7 @@ func newServer(ctx context.Context, c Config, rotationStrategy rotationStrategy)
issuerURL: c.Issuer,
issuer: c.Web.Issuer,
theme: c.Web.Theme,
extra: c.Web.Extra,
}
static, theme, tmpls, err := loadWebConfig(web)

View File

@@ -42,6 +42,7 @@ type webConfig struct {
issuer string
theme string
issuerURL string
extra map[string]string
}
func join(base, path string) string {
@@ -140,6 +141,7 @@ func loadTemplates(c webConfig, templatesDir string) (*templates, error) {
"logo": func() string { return c.logoURL },
"url": func(s string) string { return join(c.issuerURL, s) },
"lower": strings.ToLower,
"extra": func(k string) string { return c.extra[k] },
}
tmpls, err := template.New("").Funcs(funcs).ParseFiles(filenames...)