package server import "strings" type NavContext struct { Path string ObjectUUID string ObjectURI string RevisionHash string } func expandNavHref( href string, ctx NavContext, ) (string, bool) { replacements := map[string]string{ "{path}": ctx.Path, "{object_uuid}": ctx.ObjectUUID, "{object_uri}": ctx.ObjectURI, "{revision_hash}": ctx.RevisionHash, } for key, value := range replacements { if strings.Contains(href, key) { if value == "" { return "", false } href = strings.ReplaceAll( href, key, value, ) } } return href, true } func resolveNavItems( items []NavItem, ctx NavContext, ) []NavItem { var out []NavItem for _, item := range items { href, ok := expandNavHref( item.Href, ctx, ) if !ok { continue } item.ResolvedHref = href out = append(out, item) } return out }