mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-28 02:10:50 +00:00
438c219892
Be able to inhibit AbsURL canonicalization of content, on a site configuration basis. Advantages of being able to inhibit this include making it easier to rendering on other hostnames, and being able to include resources on http or https depending on how this page was retrieved, avoiding mixed-mode client complaints without adding latency for plain http.
34 lines
465 B
Go
34 lines
465 B
Go
package transform
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
)
|
|
|
|
type trans func([]byte) []byte
|
|
|
|
type link trans
|
|
|
|
type chain []link
|
|
|
|
func NewChain(trs ...link) chain {
|
|
return trs
|
|
}
|
|
|
|
func NewEmptyTransforms() []link {
|
|
return make([]link, 0, 20)
|
|
}
|
|
|
|
func (c *chain) Apply(w io.Writer, r io.Reader) (err error) {
|
|
|
|
buffer := new(bytes.Buffer)
|
|
buffer.ReadFrom(r)
|
|
b := buffer.Bytes()
|
|
for _, tr := range *c {
|
|
b = tr(b)
|
|
}
|
|
buffer.Reset()
|
|
buffer.Write(b)
|
|
buffer.WriteTo(w)
|
|
return
|
|
}
|