mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Remove URL param from exported AbsURL methods
This is to make it clear that there is only one URL in play, the BaseURL.
This commit is contained in:
parent
e7099cfa26
commit
658cfb287e
3 changed files with 29 additions and 15 deletions
|
@ -1363,7 +1363,7 @@ func (s *Site) renderAndWriteXML(name string, dest string, d interface{}, layout
|
|||
|
||||
err := s.render(name, d, renderBuffer, layouts...)
|
||||
|
||||
absURLInXML, err := transform.AbsURLInXML(viper.GetString("BaseURL"))
|
||||
absURLInXML, err := transform.AbsURLInXML()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1393,7 +1393,7 @@ func (s *Site) renderAndWritePage(name string, dest string, d interface{}, layou
|
|||
transformLinks := transform.NewEmptyTransforms()
|
||||
|
||||
if viper.GetBool("CanonifyURLs") {
|
||||
absURL, err := transform.AbsURL(viper.GetString("BaseURL"))
|
||||
absURL, err := transform.AbsURL()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -1,33 +1,47 @@
|
|||
package transform
|
||||
|
||||
import (
|
||||
"github.com/spf13/viper"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var absURLInit sync.Once
|
||||
var ar *absURLReplacer
|
||||
|
||||
// for performance reasons, we reuse the first baseURL given
|
||||
func initAbsURLReplacer(baseURL string) {
|
||||
absURLInit.Do(func() {
|
||||
ar = newAbsURLReplacer(baseURL)
|
||||
})
|
||||
func AbsURL() (trs []link, err error) {
|
||||
initAbsURLReplacer()
|
||||
return absURLFromReplacer(ar)
|
||||
}
|
||||
|
||||
func AbsURL(absURL string) (trs []link, err error) {
|
||||
initAbsURLReplacer(absURL)
|
||||
func absURLFromURL(URL string) (trs []link, err error) {
|
||||
return absURLFromReplacer(newAbsURLReplacer(URL))
|
||||
}
|
||||
|
||||
func absURLFromReplacer(ar *absURLReplacer) (trs []link, err error) {
|
||||
trs = append(trs, func(rw contentRewriter) {
|
||||
ar.replaceInHTML(rw)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func AbsURLInXML(absURL string) (trs []link, err error) {
|
||||
initAbsURLReplacer(absURL)
|
||||
func AbsURLInXML() (trs []link, err error) {
|
||||
initAbsURLReplacer()
|
||||
return absURLInXMLFromReplacer(ar)
|
||||
}
|
||||
|
||||
func absURLInXMLFromURL(URL string) (trs []link, err error) {
|
||||
return absURLInXMLFromReplacer(newAbsURLReplacer(URL))
|
||||
}
|
||||
|
||||
func absURLInXMLFromReplacer(ar *absURLReplacer) (trs []link, err error) {
|
||||
trs = append(trs, func(rw contentRewriter) {
|
||||
ar.replaceInXML(rw)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func initAbsURLReplacer() {
|
||||
absURLInit.Do(func() {
|
||||
ar = newAbsURLReplacer(viper.GetString("BaseURL"))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ func TestChaingMultipleTransformers(t *testing.T) {
|
|||
}
|
||||
|
||||
func BenchmarkAbsURL(b *testing.B) {
|
||||
absURL, _ := AbsURL("http://base")
|
||||
absURL, _ := absURLFromURL("http://base")
|
||||
tr := NewChain(absURL...)
|
||||
|
||||
b.ResetTimer()
|
||||
|
@ -95,7 +95,7 @@ func BenchmarkAbsURL(b *testing.B) {
|
|||
}
|
||||
|
||||
func TestAbsURL(t *testing.T) {
|
||||
absURL, _ := AbsURL("http://base")
|
||||
absURL, _ := absURLFromURL("http://base")
|
||||
tr := NewChain(absURL...)
|
||||
|
||||
apply(t.Errorf, tr, abs_url_tests)
|
||||
|
@ -103,7 +103,7 @@ func TestAbsURL(t *testing.T) {
|
|||
}
|
||||
|
||||
func BenchmarkXMLAbsURL(b *testing.B) {
|
||||
absURLInXML, _ := AbsURLInXML("http://base")
|
||||
absURLInXML, _ := absURLInXMLFromURL("http://base")
|
||||
tr := NewChain(absURLInXML...)
|
||||
|
||||
b.ResetTimer()
|
||||
|
@ -113,7 +113,7 @@ func BenchmarkXMLAbsURL(b *testing.B) {
|
|||
}
|
||||
|
||||
func TestXMLAbsURL(t *testing.T) {
|
||||
absURLInXML, _ := AbsURLInXML("http://base")
|
||||
absURLInXML, _ := absURLInXMLFromURL("http://base")
|
||||
tr := NewChain(absURLInXML...)
|
||||
apply(t.Errorf, tr, xml_abs_url_tests)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue