39 lines
732 B
Go
39 lines
732 B
Go
package urls
|
|
|
|
import (
|
|
"net/url"
|
|
"path"
|
|
|
|
"source.toby3d.me/toby3d/home/internal/domain"
|
|
)
|
|
|
|
type Namespace struct {
|
|
site *domain.Site
|
|
}
|
|
|
|
func New(site *domain.Site) *Namespace {
|
|
return &Namespace{
|
|
site: site,
|
|
}
|
|
}
|
|
|
|
func (ns *Namespace) AbsURL(p string) string {
|
|
return ns.site.BaseURL.JoinPath(p).String()
|
|
}
|
|
|
|
func (ns *Namespace) RelURL(p string) string {
|
|
return path.Clean("/" + p)
|
|
}
|
|
|
|
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()
|
|
}
|