diff --git a/htmx_route.go b/htmx_route.go index 0e83917..877bbec 100644 --- a/htmx_route.go +++ b/htmx_route.go @@ -12,6 +12,7 @@ type HtmxContext interface { GetActivePath() *ActivePath HasActivePath() bool SetActivePath(activePath *ActivePath) + GetPath() string } type HtmxContextImpl struct { @@ -21,6 +22,10 @@ type HtmxContextImpl struct { activePath *ActivePath } +func (c *HtmxContextImpl) GetPath() string { + return c.req.URL.Path +} + func (c *HtmxContextImpl) SetActivePath(activePath *ActivePath) { c.activePath = activePath } @@ -65,6 +70,7 @@ type HtmxRoute interface { ToUrl(queryParams ...HtmxPathParam) string GetHtmx(queryParams ...HtmxPathParam) gomponents.Node SetActivePath(activePath *ActivePath) HtmxRoute + Add(server *http.ServeMux) } type HtmxGetRoute struct { diff --git a/i18n.go b/i18n.go index 8a61c18..2a3abd8 100644 --- a/i18n.go +++ b/i18n.go @@ -1,5 +1,7 @@ package ersteller_lib +import "strings" + type Language string const ( @@ -81,3 +83,12 @@ func NewActivePath(path string, langMap map[Language]string) ActivePath { Path: path, } } + +func (a ActivePath) GetPath(language Language) string { + return "/" + string(language) + a.Path +} + +func (a ActivePath) IsActive(c HtmxContext) bool { + pathWithLang := a.GetPath(c.GetLanguage()) + return strings.HasPrefix(c.GetPath(), pathWithLang) +} diff --git a/page.go b/page.go index 5055cce..5add093 100644 --- a/page.go +++ b/page.go @@ -23,7 +23,7 @@ type PageWebsiteMetaData struct { Title string Lang Language Description string - NavItems []NavItem + NavItems []ActivePath ScriptSrcs []string StyleSrcs []string ActiveNavPath string