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