2013-10-01 19:59:29 +00:00
|
|
|
package transform
|
|
|
|
|
|
|
|
import (
|
2015-03-18 18:42:46 +00:00
|
|
|
"github.com/spf13/viper"
|
2015-02-16 09:48:15 +00:00
|
|
|
"sync"
|
2013-10-01 19:59:29 +00:00
|
|
|
)
|
|
|
|
|
2015-03-11 17:34:57 +00:00
|
|
|
var absURLInit sync.Once
|
|
|
|
var ar *absURLReplacer
|
2013-10-01 19:59:29 +00:00
|
|
|
|
2015-03-18 18:42:46 +00:00
|
|
|
func AbsURL() (trs []link, err error) {
|
|
|
|
initAbsURLReplacer()
|
|
|
|
return absURLFromReplacer(ar)
|
2015-02-16 09:48:15 +00:00
|
|
|
}
|
2013-10-01 19:59:29 +00:00
|
|
|
|
2015-03-18 18:42:46 +00:00
|
|
|
func absURLFromURL(URL string) (trs []link, err error) {
|
|
|
|
return absURLFromReplacer(newAbsURLReplacer(URL))
|
|
|
|
}
|
2013-11-09 06:33:00 +00:00
|
|
|
|
2015-03-18 18:42:46 +00:00
|
|
|
func absURLFromReplacer(ar *absURLReplacer) (trs []link, err error) {
|
2015-03-19 00:55:49 +00:00
|
|
|
trs = append(trs, func(rw contentTransformer) {
|
2015-03-17 23:36:48 +00:00
|
|
|
ar.replaceInHTML(rw)
|
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
|
|
|
}
|
|
|
|
|
2015-03-18 18:42:46 +00:00
|
|
|
func AbsURLInXML() (trs []link, err error) {
|
|
|
|
initAbsURLReplacer()
|
|
|
|
return absURLInXMLFromReplacer(ar)
|
|
|
|
}
|
|
|
|
|
|
|
|
func absURLInXMLFromURL(URL string) (trs []link, err error) {
|
|
|
|
return absURLInXMLFromReplacer(newAbsURLReplacer(URL))
|
|
|
|
}
|
2014-12-18 19:59:39 +00:00
|
|
|
|
2015-03-18 18:42:46 +00:00
|
|
|
func absURLInXMLFromReplacer(ar *absURLReplacer) (trs []link, err error) {
|
2015-03-19 00:55:49 +00:00
|
|
|
trs = append(trs, func(rw contentTransformer) {
|
2015-03-17 23:36:48 +00:00
|
|
|
ar.replaceInXML(rw)
|
2014-12-18 19:59:39 +00:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2015-03-18 18:42:46 +00:00
|
|
|
|
|
|
|
func initAbsURLReplacer() {
|
|
|
|
absURLInit.Do(func() {
|
|
|
|
ar = newAbsURLReplacer(viper.GetString("BaseURL"))
|
|
|
|
})
|
|
|
|
}
|