Add separate about and contact pages
This commit is contained in:
@@ -0,0 +1,83 @@
|
|||||||
|
package about
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "ersteller-lib"
|
||||||
|
|
||||||
|
. "maragu.dev/gomponents"
|
||||||
|
. "maragu.dev/gomponents/html"
|
||||||
|
)
|
||||||
|
|
||||||
|
const AboutPath = "/about"
|
||||||
|
const AboutPathDe = "/de/ueber-uns"
|
||||||
|
|
||||||
|
var aboutTexts *AboutTexts
|
||||||
|
|
||||||
|
type AboutTexts struct {
|
||||||
|
PageTitle I18nText
|
||||||
|
PageDescription I18nText
|
||||||
|
HeroTitle I18nText
|
||||||
|
HeroDescription I18nText
|
||||||
|
}
|
||||||
|
|
||||||
|
type Page struct {
|
||||||
|
createPage CreateHtmxPageFunc
|
||||||
|
ViewRoute HtmxRoute
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPage(createPage CreateHtmxPageFunc, server HtmxServer, path *ActivePath) *Page {
|
||||||
|
if aboutTexts == nil {
|
||||||
|
createAboutTexts()
|
||||||
|
}
|
||||||
|
page := &Page{
|
||||||
|
createPage: createPage,
|
||||||
|
}
|
||||||
|
page.ViewRoute = NewHtmxGetRoute(page.View, LanguagePaths{
|
||||||
|
En: AboutPath,
|
||||||
|
De: AboutPathDe,
|
||||||
|
}).SetActivePath(path)
|
||||||
|
page.ViewRoute.Add(server)
|
||||||
|
return page
|
||||||
|
}
|
||||||
|
|
||||||
|
func createAboutTexts() {
|
||||||
|
aboutTexts = &AboutTexts{
|
||||||
|
PageTitle: NewI18nText(map[Language]string{
|
||||||
|
En: "About",
|
||||||
|
De: "Über uns",
|
||||||
|
}),
|
||||||
|
PageDescription: NewI18nText(map[Language]string{
|
||||||
|
En: "Learn more about us",
|
||||||
|
De: "Erfahren Sie mehr über uns",
|
||||||
|
}),
|
||||||
|
HeroTitle: NewI18nText(map[Language]string{
|
||||||
|
En: "About Us",
|
||||||
|
De: "Über uns",
|
||||||
|
}),
|
||||||
|
HeroDescription: NewI18nText(map[Language]string{
|
||||||
|
En: "This is a placeholder about page. Customize this content to tell your story.",
|
||||||
|
De: "Dies ist eine Platzhalter-Über-uns-Seite. Passen Sie diesen Inhalt an, um Ihre Geschichte zu erzählen.",
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Page) getMetaData() PageWebsiteMetaData {
|
||||||
|
return PageWebsiteMetaData{
|
||||||
|
Title: aboutTexts.PageTitle,
|
||||||
|
Lang: En,
|
||||||
|
Description: aboutTexts.PageDescription,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Page) View(c HtmxContext) {
|
||||||
|
content := AboutContent(c.GetLanguage())
|
||||||
|
p.createPage(c, p.getMetaData(), content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func AboutContent(language Language) Group {
|
||||||
|
return []Node{
|
||||||
|
Div(Class("hero-section"),
|
||||||
|
H1(Class("hero-title"), Text(aboutTexts.HeroTitle.FromLang(language))),
|
||||||
|
P(Class("hero-description"), Text(aboutTexts.HeroDescription.FromLang(language))),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package contact
|
||||||
|
|
||||||
|
import (
|
||||||
|
. "ersteller-lib"
|
||||||
|
|
||||||
|
. "maragu.dev/gomponents"
|
||||||
|
. "maragu.dev/gomponents/html"
|
||||||
|
)
|
||||||
|
|
||||||
|
const ContactPath = "/contact"
|
||||||
|
const ContactPathDe = "/de/kontakt"
|
||||||
|
|
||||||
|
var contactTexts *ContactTexts
|
||||||
|
|
||||||
|
type ContactTexts struct {
|
||||||
|
PageTitle I18nText
|
||||||
|
PageDescription I18nText
|
||||||
|
HeroTitle I18nText
|
||||||
|
HeroDescription I18nText
|
||||||
|
}
|
||||||
|
|
||||||
|
type Page struct {
|
||||||
|
createPage CreateHtmxPageFunc
|
||||||
|
ViewRoute HtmxRoute
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewPage(createPage CreateHtmxPageFunc, server HtmxServer, path *ActivePath) *Page {
|
||||||
|
if contactTexts == nil {
|
||||||
|
createContactTexts()
|
||||||
|
}
|
||||||
|
page := &Page{
|
||||||
|
createPage: createPage,
|
||||||
|
}
|
||||||
|
page.ViewRoute = NewHtmxGetRoute(page.View, LanguagePaths{
|
||||||
|
En: ContactPath,
|
||||||
|
De: ContactPathDe,
|
||||||
|
}).SetActivePath(path)
|
||||||
|
page.ViewRoute.Add(server)
|
||||||
|
return page
|
||||||
|
}
|
||||||
|
|
||||||
|
func createContactTexts() {
|
||||||
|
contactTexts = &ContactTexts{
|
||||||
|
PageTitle: NewI18nText(map[Language]string{
|
||||||
|
En: "Contact",
|
||||||
|
De: "Kontakt",
|
||||||
|
}),
|
||||||
|
PageDescription: NewI18nText(map[Language]string{
|
||||||
|
En: "Get in touch with us",
|
||||||
|
De: "Nehmen Sie Kontakt mit uns auf",
|
||||||
|
}),
|
||||||
|
HeroTitle: NewI18nText(map[Language]string{
|
||||||
|
En: "Contact Us",
|
||||||
|
De: "Kontaktieren Sie uns",
|
||||||
|
}),
|
||||||
|
HeroDescription: NewI18nText(map[Language]string{
|
||||||
|
En: "This is a placeholder contact page. Add your contact information and forms here.",
|
||||||
|
De: "Dies ist eine Platzhalter-Kontakt-Seite. Fügen Sie hier Ihre Kontaktinformationen und Formulare hinzu.",
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Page) getMetaData() PageWebsiteMetaData {
|
||||||
|
return PageWebsiteMetaData{
|
||||||
|
Title: contactTexts.PageTitle,
|
||||||
|
Lang: En,
|
||||||
|
Description: contactTexts.PageDescription,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Page) View(c HtmxContext) {
|
||||||
|
content := ContactContent(c.GetLanguage())
|
||||||
|
p.createPage(c, p.getMetaData(), content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ContactContent(language Language) Group {
|
||||||
|
return []Node{
|
||||||
|
Div(Class("hero-section"),
|
||||||
|
H1(Class("hero-title"), Text(contactTexts.HeroTitle.FromLang(language))),
|
||||||
|
P(Class("hero-description"), Text(contactTexts.HeroDescription.FromLang(language))),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,12 +2,13 @@ package routes
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
. "ersteller-lib"
|
. "ersteller-lib"
|
||||||
|
"ersteller-lib/starter/about"
|
||||||
|
"ersteller-lib/starter/contact"
|
||||||
"ersteller-lib/starter/index"
|
"ersteller-lib/starter/index"
|
||||||
"ersteller-lib/starter/page"
|
"ersteller-lib/starter/page"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
. "maragu.dev/gomponents"
|
. "maragu.dev/gomponents"
|
||||||
. "maragu.dev/gomponents/html"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateApi() http.Handler {
|
func CreateApi() http.Handler {
|
||||||
@@ -27,16 +28,16 @@ func CreateApi() http.Handler {
|
|||||||
En: "About",
|
En: "About",
|
||||||
De: "Über uns",
|
De: "Über uns",
|
||||||
}, LanguagePaths{
|
}, LanguagePaths{
|
||||||
En: "/about",
|
En: about.AboutPath,
|
||||||
De: "/de/ueber-uns",
|
De: about.AboutPathDe,
|
||||||
})
|
})
|
||||||
|
|
||||||
contactActivePath := NewActivePath(map[Language]string{
|
contactActivePath := NewActivePath(map[Language]string{
|
||||||
En: "Contact",
|
En: "Contact",
|
||||||
De: "Kontakt",
|
De: "Kontakt",
|
||||||
}, LanguagePaths{
|
}, LanguagePaths{
|
||||||
En: "/contact",
|
En: contact.ContactPath,
|
||||||
De: "/de/kontakt",
|
De: contact.ContactPathDe,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Main navigation items
|
// Main navigation items
|
||||||
@@ -49,53 +50,9 @@ func CreateApi() http.Handler {
|
|||||||
indexPage := index.NewPage(createPageFunc, server, &indexActivePath)
|
indexPage := index.NewPage(createPageFunc, server, &indexActivePath)
|
||||||
server.HandleStaticAndDefaultPath(indexPage.ViewRoute, En)
|
server.HandleStaticAndDefaultPath(indexPage.ViewRoute, En)
|
||||||
|
|
||||||
// Add placeholder routes for About and Contact pages
|
// Create About and Contact pages using the new packages
|
||||||
// These can be implemented as needed
|
_ = about.NewPage(createPageFunc, server, &aboutActivePath)
|
||||||
aboutRoute := NewHtmxGetRoute(func(c HtmxContext) {
|
_ = contact.NewPage(createPageFunc, server, &contactActivePath)
|
||||||
content := []Node{
|
|
||||||
Div(Class("hero-section"),
|
|
||||||
H1(Class("hero-title"), Text("About Us")),
|
|
||||||
P(Class("hero-description"), Text("This is a placeholder about page. Customize this content to tell your story.")),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
createPageFunc(c, PageWebsiteMetaData{
|
|
||||||
Title: NewI18nText(map[Language]string{
|
|
||||||
En: "About",
|
|
||||||
De: "Über uns",
|
|
||||||
}),
|
|
||||||
Description: NewI18nText(map[Language]string{
|
|
||||||
En: "Learn more about us",
|
|
||||||
De: "Erfahren Sie mehr über uns",
|
|
||||||
}),
|
|
||||||
}, content...)
|
|
||||||
}, LanguagePaths{
|
|
||||||
En: "/about",
|
|
||||||
De: "/de/ueber-uns",
|
|
||||||
}).SetActivePath(&aboutActivePath)
|
|
||||||
aboutRoute.Add(server)
|
|
||||||
|
|
||||||
contactRoute := NewHtmxGetRoute(func(c HtmxContext) {
|
|
||||||
content := []Node{
|
|
||||||
Div(Class("hero-section"),
|
|
||||||
H1(Class("hero-title"), Text("Contact Us")),
|
|
||||||
P(Class("hero-description"), Text("This is a placeholder contact page. Add your contact information and forms here.")),
|
|
||||||
),
|
|
||||||
}
|
|
||||||
createPageFunc(c, PageWebsiteMetaData{
|
|
||||||
Title: NewI18nText(map[Language]string{
|
|
||||||
En: "Contact",
|
|
||||||
De: "Kontakt",
|
|
||||||
}),
|
|
||||||
Description: NewI18nText(map[Language]string{
|
|
||||||
En: "Get in touch with us",
|
|
||||||
De: "Nehmen Sie Kontakt mit uns auf",
|
|
||||||
}),
|
|
||||||
}, content...)
|
|
||||||
}, LanguagePaths{
|
|
||||||
En: "/contact",
|
|
||||||
De: "/de/kontakt",
|
|
||||||
}).SetActivePath(&contactActivePath)
|
|
||||||
contactRoute.Add(server)
|
|
||||||
|
|
||||||
serverWithMiddleWare := UseMiddleware(server, LoggingMiddleware, MakeGzipHandler)
|
serverWithMiddleWare := UseMiddleware(server, LoggingMiddleware, MakeGzipHandler)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user