hugo/transform/absurl.go

48 lines
977 B
Go
Raw Normal View History

2013-10-01 19:59:29 +00:00
package transform
import (
"github.com/spf13/viper"
"sync"
2013-10-01 19:59:29 +00:00
)
var absURLInit sync.Once
var ar *absURLReplacer
2013-10-01 19:59:29 +00:00
func AbsURL() (trs []link, err error) {
initAbsURLReplacer()
return absURLFromReplacer(ar)
}
2013-10-01 19:59:29 +00:00
func absURLFromURL(URL string) (trs []link, err error) {
return absURLFromReplacer(newAbsURLReplacer(URL))
}
2013-11-09 06:33:00 +00:00
func absURLFromReplacer(ar *absURLReplacer) (trs []link, err error) {
trs = append(trs, func(rw contentTransformer) {
ar.replaceInHTML(rw)
})
return
2013-10-01 19:59:29 +00:00
}
func AbsURLInXML() (trs []link, err error) {
initAbsURLReplacer()
return absURLInXMLFromReplacer(ar)
}
func absURLInXMLFromURL(URL string) (trs []link, err error) {
return absURLInXMLFromReplacer(newAbsURLReplacer(URL))
}
func absURLInXMLFromReplacer(ar *absURLReplacer) (trs []link, err error) {
trs = append(trs, func(rw contentTransformer) {
ar.replaceInXML(rw)
})
return
}
func initAbsURLReplacer() {
absURLInit.Do(func() {
ar = newAbsURLReplacer(viper.GetString("BaseURL"))
})
}