116 lines
2.7 KiB
Go
116 lines
2.7 KiB
Go
package page
|
|
|
|
import (
|
|
"fmt"
|
|
. "git.gorlug.de/code/ersteller"
|
|
"time"
|
|
|
|
. "maragu.dev/gomponents"
|
|
. "maragu.dev/gomponents/components"
|
|
. "maragu.dev/gomponents/html"
|
|
)
|
|
|
|
var _texts *Texts
|
|
|
|
func CreatePage(req HtmxContext, metadata PageWebsiteMetaData, content ...Node) {
|
|
metadata.Lang = req.GetLanguage()
|
|
|
|
var contentForFunction Node
|
|
if len(content) > 0 {
|
|
contentForFunction = Div(content...)
|
|
} else if len(content) == 0 {
|
|
contentForFunction = Div()
|
|
} else if len(content) == 1 {
|
|
contentForFunction = content[0]
|
|
}
|
|
|
|
styles := []string{
|
|
"/static/styles.css",
|
|
}
|
|
for _, src := range metadata.StyleSrcs {
|
|
styles = append(styles, src)
|
|
}
|
|
|
|
scripts := []string{
|
|
"/static/scripts/language-select.js",
|
|
"/static/htmx.js",
|
|
}
|
|
for _, src := range metadata.ScriptSrcs {
|
|
scripts = append(scripts, src)
|
|
}
|
|
|
|
page := HTML5(HTML5Props{
|
|
Title: "White Label App " + metadata.Title.From(req),
|
|
Language: string(metadata.Lang),
|
|
Description: metadata.Description.From(req),
|
|
Head: []Node{
|
|
Map(styles, func(s string) Node {
|
|
return Link(Rel("stylesheet"), Href(s))
|
|
}),
|
|
Map(scripts, func(s string) Node {
|
|
return Script(Type("text/javascript"), Src(s))
|
|
}),
|
|
AddLanguageSelectScript(metadata),
|
|
},
|
|
Body: []Node{
|
|
Header(Class("header"),
|
|
Div(Class("header-content"),
|
|
Div(Class("logo"),
|
|
Span(Class("logo-icon"), Text("🚀")),
|
|
Span(Class("logo-text"), Text("White Label App")),
|
|
),
|
|
GetNav(req, metadata),
|
|
GetLanguageSwitcher(req, metadata),
|
|
),
|
|
),
|
|
Div(Class("container"),
|
|
contentForFunction,
|
|
),
|
|
Footer(Class("footer"),
|
|
Div(Class("footer-menu"), Aria("label", "Footer Menu"),
|
|
GetFooterMenu(req, metadata),
|
|
),
|
|
P(Class("footer-disclaimer"), Text(getTexts().disclaimer.From(req))),
|
|
P(Text(getTexts().getCopyright(req.GetLanguage()))),
|
|
),
|
|
},
|
|
})
|
|
req.Render(page)
|
|
}
|
|
|
|
type Texts struct {
|
|
disclaimer I18nText
|
|
copyright I18nText
|
|
}
|
|
|
|
func NewTexts() *Texts {
|
|
return &Texts{
|
|
disclaimer: NewI18nText(map[Language]string{
|
|
De: "Dies ist eine White-Label-Vorlage. Passen Sie den Inhalt an Ihre Bedürfnisse an.",
|
|
En: "This is a white label template. Customize the content to fit your needs.",
|
|
}),
|
|
copyright: NewI18nText(map[Language]string{
|
|
De: "© 2020 - $Year$ White Label App. Alle Rechte vorbehalten.",
|
|
En: "© 2020 - $Year$ White Label App. All rights reserved.",
|
|
}),
|
|
}
|
|
}
|
|
|
|
func (t *Texts) getCopyright(lang Language) string {
|
|
currentYear := fmt.Sprint(time.Now().Year())
|
|
text := t.copyright.FromLang(lang)
|
|
return InlineTemplate(text, struct {
|
|
Year string
|
|
}{
|
|
Year: currentYear,
|
|
})
|
|
}
|
|
|
|
func getTexts() *Texts {
|
|
if _texts != nil {
|
|
return _texts
|
|
}
|
|
_texts = NewTexts()
|
|
return _texts
|
|
}
|