mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
helpers: Return partially cleaned URL in case of error in URLPrep anyway
Closes #2987
This commit is contained in:
parent
74ea81b885
commit
7acec3c639
1 changed files with 6 additions and 9 deletions
|
@ -20,7 +20,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/PuerkitoBio/purell"
|
"github.com/PuerkitoBio/purell"
|
||||||
jww "github.com/spf13/jwalterweatherman"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type pathBridge struct {
|
type pathBridge struct {
|
||||||
|
@ -297,17 +296,15 @@ func (p *PathSpec) URLizeAndPrep(in string) string {
|
||||||
// URLPrep applies misc sanitation to the given URL.
|
// URLPrep applies misc sanitation to the given URL.
|
||||||
func (p *PathSpec) URLPrep(in string) string {
|
func (p *PathSpec) URLPrep(in string) string {
|
||||||
if p.uglyURLs {
|
if p.uglyURLs {
|
||||||
x := Uglify(SanitizeURL(in))
|
return Uglify(SanitizeURL(in))
|
||||||
return x
|
|
||||||
}
|
}
|
||||||
x := PrettifyURL(SanitizeURL(in))
|
pretty := PrettifyURL(SanitizeURL(in))
|
||||||
if path.Ext(x) == ".xml" {
|
if path.Ext(pretty) == ".xml" {
|
||||||
return x
|
return pretty
|
||||||
}
|
}
|
||||||
url, err := purell.NormalizeURLString(x, purell.FlagAddTrailingSlash)
|
url, err := purell.NormalizeURLString(pretty, purell.FlagAddTrailingSlash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
jww.ERROR.Printf("Failed to normalize URL string. Returning in = %q\n", in)
|
return pretty
|
||||||
return in
|
|
||||||
}
|
}
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue