mirror of
https://github.com/gohugoio/hugo.git
synced 2024-09-20 01:15:13 -04:00
33 lines
591 B
Go
33 lines
591 B
Go
package transform
|
|
|
|
import (
|
|
"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(absURL string) (trs []link, err error) {
|
|
initAbsURLReplacer(absURL)
|
|
|
|
trs = append(trs, func(rw contentRewriter) {
|
|
ar.replaceInHTML(rw)
|
|
})
|
|
return
|
|
}
|
|
|
|
func AbsURLInXML(absURL string) (trs []link, err error) {
|
|
initAbsURLReplacer(absURL)
|
|
|
|
trs = append(trs, func(rw contentRewriter) {
|
|
ar.replaceInXML(rw)
|
|
})
|
|
return
|
|
}
|