diff options
author | bep <bjorn.erik.pedersen@gmail.com> | 2015-05-16 00:11:39 +0200 |
---|---|---|
committer | bep <bjorn.erik.pedersen@gmail.com> | 2015-05-16 00:11:44 +0200 |
commit | beaa8b1bcabd4be25ac26bea39ab9f7290147e67 (patch) | |
tree | 76095c2b6ec9ddf22477c188c87f47e4c6cee8d6 /transform/chain.go | |
parent | e522e5f4154cb6a5d960aeb8920fa3e433641cf6 (diff) |
Add support for URLs relative to context root
Setting `RelativeURLs` to `true` will make all relative URLs in the site *really* relative.
And will do so with speed.
So:
In `/post/myblogpost.html`:
`/mycss.css` becomes `../mycss.css`
The same in `/index.html` will become:
`./mycss.css` etc.
Note that absolute URLs will not be touched (either external resources, or URLs constructed with `BaseURL`).
The speediness is about the same as before:
```
benchmark old ns/op new ns/op delta
BenchmarkAbsURL 17462 18164 +4.02%
BenchmarkAbsURLSrcset 18842 19632 +4.19%
BenchmarkXMLAbsURLSrcset 18643 19313 +3.59%
BenchmarkXMLAbsURL 9283 9656 +4.02%
benchmark old allocs new allocs delta
BenchmarkAbsURL 24 28 +16.67%
BenchmarkAbsURLSrcset 29 32 +10.34%
BenchmarkXMLAbsURLSrcset 27 30 +11.11%
BenchmarkXMLAbsURL 12 14 +16.67%
benchmark old bytes new bytes delta
BenchmarkAbsURL 3154 3404 +7.93%
BenchmarkAbsURLSrcset 2376 2573 +8.29%
BenchmarkXMLAbsURLSrcset 2569 2763 +7.55%
BenchmarkXMLAbsURL 1888 1998 +5.83%
```
Fixes #1104
Fixes #622
Fixes #937
Fixes #157
Diffstat (limited to 'transform/chain.go')
-rw-r--r-- | transform/chain.go | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/transform/chain.go b/transform/chain.go index ab26a350e..4019dca25 100644 --- a/transform/chain.go +++ b/transform/chain.go @@ -23,6 +23,7 @@ func NewEmptyTransforms() []link { // contentTransformer is an interface that enables rotation of pooled buffers // in the transformer chain. type contentTransformer interface { + Path() []byte Content() []byte io.Writer } @@ -30,10 +31,15 @@ type contentTransformer interface { // Implements contentTransformer // Content is read from the from-buffer and rewritten to to the to-buffer. type fromToBuffer struct { + path []byte from *bytes.Buffer to *bytes.Buffer } +func (ft fromToBuffer) Path() []byte { + return ft.path +} + func (ft fromToBuffer) Write(p []byte) (n int, err error) { return ft.to.Write(p) } @@ -42,7 +48,7 @@ func (ft fromToBuffer) Content() []byte { return ft.from.Bytes() } -func (c *chain) Apply(w io.Writer, r io.Reader) error { +func (c *chain) Apply(w io.Writer, r io.Reader, p []byte) error { b1 := bp.GetBuffer() defer bp.PutBuffer(b1) @@ -57,7 +63,7 @@ func (c *chain) Apply(w io.Writer, r io.Reader) error { b2 := bp.GetBuffer() defer bp.PutBuffer(b2) - fb := &fromToBuffer{from: b1, to: b2} + fb := &fromToBuffer{path: p, from: b1, to: b2} for i, tr := range *c { if i > 0 { |