Update home config

This commit is contained in:
Tom 2023-04-27 14:57:43 +02:00
parent 44af84abe9
commit 8c4de32246
9 changed files with 30 additions and 18 deletions

View file

@ -80,7 +80,7 @@ func (config Config) MarshalSensitive() string {
var configBytes []byte
// Marshal marshals this configuration in nicely formatted form.
// Where possible, this will provided yaml comments.
// Where possible, this will maintain yaml comments.
//
// Previous may optionally provide the bytes of a previous configuration file to replace settings in.
// The previous yaml file must be a valid configuration yaml, meaning all fields should be set.
@ -103,7 +103,7 @@ func Marshal(config *Config, previous []byte) ([]byte, error) {
}
// transplant the configuration yaml into the template
if err := yamlx.Transplant(template, cfg); err != nil {
if err := yamlx.Transplant(template, cfg, true); err != nil {
return nil, err
}

View file

@ -41,9 +41,13 @@ http:
# Configuration for the (public) homepage of the distillery.
home:
# the title of the distillery to be set
title: null
# the url to redirect to for more information about this instance of the distillery.
# to be configured by default.
redirect: null
# configure the list of systems on the homepage.
list:

View file

@ -4,6 +4,7 @@ import "github.com/FAU-CDI/wisski-distillery/internal/config/validators"
// HomeConfig determines options for the homepage of the distillery
type HomeConfig struct {
Title string `yaml:"title" default:"WissKI Distillery" validate:"nonempty"`
SelfRedirect *validators.URL `yaml:"redirect" default:"https://github.com/FAU-CDI/wisski-distillery" validate:"https"`
List HomeListConfig `yaml:"list" recurse:"true"`
}

View file

@ -29,21 +29,17 @@ var (
_ component.Routeable = (*Home)(nil)
)
func (*Home) Routes() component.Routes {
func (home *Home) Routes() component.Routes {
return component.Routes{
Prefix: "/",
MatchAllDomains: true,
CSRF: false,
MenuTitle: "WissKI Distillery",
MenuTitle: home.Config.Home.Title,
MenuPriority: component.MenuHome,
}
}
var (
menuHome = component.MenuItem{Title: "WissKI Distillery", Path: "/"}
)
func (home *Home) HandleRoute(ctx context.Context, route string) (http.Handler, error) {
// generate a default handler
dflt, err := home.loadRedirect(ctx)

View file

@ -7,6 +7,7 @@ import (
"net/http"
"strings"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/assets"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/server/templating"
"github.com/FAU-CDI/wisski-distillery/internal/status"
@ -18,7 +19,6 @@ var publicHTML []byte
var publicTemplate = templating.Parse[publicContext](
"public.html", publicHTML, nil,
templating.Title("WissKI Distillery"),
templating.Assets(assets.AssetsDefault),
)
@ -49,11 +49,14 @@ type publicContext struct {
const logoHTML = template.HTML(`<img src="/logo.svg" alt="WissKI Distillery Logo" class="biglogo">`)
func (home *Home) publicHandler(ctx context.Context) http.Handler {
title := home.Config.Home.Title
tpl := publicTemplate.Prepare(
home.Dependencies.Templating,
// set title and menu item
templating.Title(title),
templating.Crumbs(
menuHome,
component.MenuItem{Title: title, Path: "/"},
),
)