mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
tpl: Add urls.Parse function
Add a urls.Parse template function that front-ends url.Parse from the Go stdlib. Fixes #3849
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
19c5910485
commit
81ed564793
@@ -15,7 +15,9 @@ package urls
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/url"
|
||||
|
||||
"github.com/gohugoio/hugo/deps"
|
||||
"github.com/spf13/cast"
|
||||
@@ -43,6 +45,17 @@ func (ns *Namespace) AbsURL(a interface{}) (template.HTML, error) {
|
||||
return template.HTML(ns.deps.PathSpec.AbsURL(s, false)), nil
|
||||
}
|
||||
|
||||
// Parse parses rawurl into a URL structure. The rawurl may be relative or
|
||||
// absolute.
|
||||
func (ns *Namespace) Parse(rawurl interface{}) (*url.URL, error) {
|
||||
s, err := cast.ToStringE(rawurl)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error in Parse: %s", err)
|
||||
}
|
||||
|
||||
return url.Parse(s)
|
||||
}
|
||||
|
||||
// RelURL takes a given string and prepends the relative path according to a
|
||||
// page's position in the project directory structure.
|
||||
func (ns *Namespace) RelURL(a interface{}) (template.HTML, error) {
|
||||
|
Reference in New Issue
Block a user