2023-11-09 01:50:08 +00:00
|
|
|
package urls
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
"path"
|
|
|
|
|
2023-11-12 23:18:56 +00:00
|
|
|
"source.toby3d.me/toby3d/home/internal/domain"
|
2023-11-09 01:50:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Namespace struct {
|
2023-11-19 12:39:54 +00:00
|
|
|
site *domain.Site
|
2023-11-09 01:50:08 +00:00
|
|
|
}
|
|
|
|
|
2023-11-19 12:39:54 +00:00
|
|
|
func New(site *domain.Site) *Namespace {
|
2023-11-09 01:50:08 +00:00
|
|
|
return &Namespace{
|
2023-11-19 12:39:54 +00:00
|
|
|
site: site,
|
2023-11-09 01:50:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-19 12:39:54 +00:00
|
|
|
func (ns *Namespace) AbsURL(p string) string {
|
|
|
|
return ns.site.BaseURL.JoinPath(p).String()
|
2023-11-09 01:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ns *Namespace) RelURL(p string) string {
|
|
|
|
return path.Clean("/" + p)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ns *Namespace) Parse(rawUrl string) (*url.URL, error) {
|
|
|
|
return url.Parse(rawUrl)
|
|
|
|
}
|