2013-10-01 19:59:29 +00:00
|
|
|
package transform
|
|
|
|
|
|
|
|
import (
|
2015-02-16 09:48:15 +00:00
|
|
|
"sync"
|
2013-10-01 19:59:29 +00:00
|
|
|
)
|
|
|
|
|
2015-02-16 09:48:15 +00:00
|
|
|
var absUrlInit sync.Once
|
|
|
|
var ar *absurlReplacer
|
2013-10-01 19:59:29 +00:00
|
|
|
|
2015-02-16 09:48:15 +00:00
|
|
|
// for performance reasons, we reuse the first baseUrl given
|
|
|
|
func initAbsurlReplacer(baseURL string) {
|
|
|
|
absUrlInit.Do(func() {
|
|
|
|
ar = newAbsurlReplacer(baseURL)
|
|
|
|
})
|
|
|
|
}
|
2013-10-01 19:59:29 +00:00
|
|
|
|
2015-02-16 09:48:15 +00:00
|
|
|
func AbsURL(absURL string) (trs []link, err error) {
|
|
|
|
initAbsurlReplacer(absURL)
|
2013-11-09 06:33:00 +00:00
|
|
|
|
2013-11-05 22:28:06 +00:00
|
|
|
trs = append(trs, func(content []byte) []byte {
|
2015-02-16 09:48:15 +00:00
|
|
|
return ar.replaceInHtml(content)
|
2013-11-05 22:28:06 +00:00
|
|
|
})
|
2013-11-01 05:14:11 +00:00
|
|
|
return
|
2013-10-01 19:59:29 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 19:59:39 +00:00
|
|
|
func AbsURLInXML(absURL string) (trs []link, err error) {
|
2015-02-16 09:48:15 +00:00
|
|
|
initAbsurlReplacer(absURL)
|
2014-12-18 19:59:39 +00:00
|
|
|
|
|
|
|
trs = append(trs, func(content []byte) []byte {
|
2015-02-16 09:48:15 +00:00
|
|
|
return ar.replaceInXml(content)
|
2014-12-18 19:59:39 +00:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|