From fa1faa3bc30eb32dec42282d8a4e8b884e3dc9df Mon Sep 17 00:00:00 2001 From: Maxim Lebedev Date: Sun, 19 Nov 2023 19:02:13 +0600 Subject: [PATCH] :sparkles: Added language specific URL transformers --- internal/templateutil/templateutil.go | 6 ++++-- internal/templateutil/urls/urls.go | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/templateutil/templateutil.go b/internal/templateutil/templateutil.go index 6f3c1ab..3929786 100644 --- a/internal/templateutil/templateutil.go +++ b/internal/templateutil/templateutil.go @@ -52,8 +52,10 @@ func New(partialsDir fs.FS, site *domain.Site) template.FuncMap { Name: "urls", Handler: func(v ...any) any { return urlsNamespace }, Methods: template.FuncMap{ - "absURL": urlsNamespace.AbsURL, - "relURL": urlsNamespace.RelURL, + "absLangURL": urlsNamespace.AbsLangURL, + "absURL": urlsNamespace.AbsURL, + "relLangURL": urlsNamespace.RelLangURL, + "relURL": urlsNamespace.RelURL, }, }) transformNamespace := transform.New() diff --git a/internal/templateutil/urls/urls.go b/internal/templateutil/urls/urls.go index 4d49b54..17b67d5 100644 --- a/internal/templateutil/urls/urls.go +++ b/internal/templateutil/urls/urls.go @@ -28,3 +28,11 @@ func (ns *Namespace) RelURL(p string) string { func (ns *Namespace) Parse(rawUrl string) (*url.URL, error) { return url.Parse(rawUrl) } + +func (ns *Namespace) RelLangURL(p string) string { + return path.Join(ns.site.BaseURL.Path, ns.site.LanguagePrefix(), p) +} + +func (ns *Namespace) AbsLangURL(p string) string { + return ns.site.BaseURL.JoinPath(ns.site.LanguagePrefix(), p).String() +}