hugo/transform/absurl.go

34 lines
591 B
Go
Raw Normal View History

2013-10-01 15:59:29 -04:00
package transform
import (
"sync"
2013-10-01 15:59:29 -04:00
)
var absURLInit sync.Once
var ar *absURLReplacer
2013-10-01 15:59:29 -04:00
// for performance reasons, we reuse the first baseURL given
func initAbsURLReplacer(baseURL string) {
absURLInit.Do(func() {
ar = newAbsURLReplacer(baseURL)
})
}
2013-10-01 15:59:29 -04:00
func AbsURL(absURL string) (trs []link, err error) {
initAbsURLReplacer(absURL)
2013-11-09 01:33:00 -05:00
2015-03-18 12:33:12 -04:00
trs = append(trs, func(rw contentRewriter) {
ar.replaceInHTML(rw)
})
return
2013-10-01 15:59:29 -04:00
}
func AbsURLInXML(absURL string) (trs []link, err error) {
initAbsURLReplacer(absURL)
2015-03-18 12:33:12 -04:00
trs = append(trs, func(rw contentRewriter) {
ar.replaceInXML(rw)
})
return
}