hugo/transform/absurl.go
2015-03-18 17:33:12 +01:00

34 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
}