Simplify getting the active path

This commit is contained in:
Achim Rohn
2025-08-22 18:37:13 +02:00
parent 7096a256a0
commit 3cc469c4a3
+2 -7
View File
@@ -1,7 +1,5 @@
package ersteller_lib package ersteller_lib
import "strings"
type Language string type Language string
const ( const (
@@ -95,9 +93,6 @@ func (a ActivePath) GetPath(language Language) string {
} }
func (a ActivePath) IsActive(c HtmxContext) bool { func (a ActivePath) IsActive(c HtmxContext) bool {
pathWithLang := a.GetPath(c.GetLanguage()) contextActivePath := c.GetActivePath()
if pathWithLang == c.GetLanguage().GetPath()+"/" { return contextActivePath != nil && contextActivePath.From(c) == a.From(c)
return pathWithLang == c.GetPath()
}
return strings.HasPrefix(c.GetPath(), pathWithLang)
} }