Commit graph

30 commits

Author SHA1 Message Date
Phil Davis
04b89857e1
all: Fix minor typos 2020-12-16 12:11:32 +01:00
Bjørn Erik Pedersen
9e57182705
tests: Convert from testify to quicktest 2019-08-12 13:26:32 +02:00
Bjørn Erik Pedersen
b5f39d23b8 all: Apply staticcheck recommendations 2019-03-24 16:14:51 +01:00
Bjørn Erik Pedersen
789ef8c639
Add support for minification of final output
Hugo Pipes added minification support for resources fetched via ´resources.Get` and similar.

This also adds support for minification of the final output for supported output formats: HTML, XML, SVG, CSS, JavaScript, JSON.

To enable, run Hugo with the `--minify` flag:

```bash
hugo --minify
```

This commit is also a major spring cleaning of the `transform` package to allow the new minification step fit into that processing chain.

Fixes #1251
2018-08-06 19:58:41 +02:00
Bjørn Erik Pedersen
a6b1eb1e91
transform: Reduce allocation in the benchmark itself 2018-08-05 17:27:16 +02:00
Bjørn Erik Pedersen
d8717cd4c7 all: Update import paths to gohugoio/hugo 2017-06-13 18:42:45 +02:00
Cameron Moore
e2aea65170 helpers: Remove ToReader funcs
Remove StringToReader and BytesToReader in favor of using the stdlib directly.
2016-06-25 17:57:05 -05:00
Bjørn Erik Pedersen
944090722e transform: Group vars and consts in chain_test 2016-03-23 21:55:14 +01:00
Bjørn Erik Pedersen
c7869fd772 transform: Clean up the var naming mess in chain_test 2016-03-23 20:03:13 +01:00
Bjørn Erik Pedersen
b21d280c67 transform: Complete test statement coverage
"coverage: 100.0% of statements"
2016-02-06 20:50:26 +01:00
Bjørn Erik Pedersen
96e990456b transform: Add missing test case for NewEmptyTransforms 2016-02-06 18:17:48 +01:00
Anthony Fok
8509727fe8 Add copyright header to that source files that don’t have one.
See #1646
2015-12-10 15:19:38 -07:00
bep
beaa8b1bca 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
2015-05-16 00:11:44 +02:00
bep
be96aacb11 Add benchmark tests for srcset handling
See #1059
2015-05-03 20:57:39 +02:00
bep
beb601c7ff Fix testdata: srcset items should be comma separated, according to spec
See #1059
2015-05-03 20:09:42 +02:00
bep
bee6a69846 canonifyurls in srcset
Speed is about the same as before, uses slightly less memory:

```
benchmark              old ns/op     new ns/op     delta
BenchmarkAbsURL        17302         17713         +2.38%
BenchmarkXMLAbsURL     9463          9470          +0.07%

benchmark              old allocs     new allocs     delta
BenchmarkAbsURL        28             24             -14.29%
BenchmarkXMLAbsURL     14             12             -14.29%

benchmark              old bytes     new bytes     delta
BenchmarkAbsURL        3422          3144          -8.12%
BenchmarkXMLAbsURL     1985          1864          -6.10%
```

Fixes #1059
2015-05-03 19:54:23 +02:00
bep
66cf3bdc77 Rename interface contentRewriter to contentTransformer
Is is a much better name.
2015-03-19 02:07:57 +01:00
bep
658cfb287e Remove URL param from exported AbsURL methods
This is to make it clear that there is only one URL in play,
the BaseURL.
2015-03-18 20:03:34 +01:00
bep
e7099cfa26 Un-export ContentReWriter 2015-03-18 17:33:12 +01:00
bep
98ee69bce2 Write to rotating ContentReWriter in transformer chain
This commit adds the interface ContentReWriter in the tranformer chain.

This is backed by two pooled byte buffers, alternating between being the reader or the writer.

This keeps the performance characteristic of the old implementation, but in a thread safe way.

Fixes #911

Benchmark old vs new:

benchmark              old ns/op     new ns/op     delta
BenchmarkAbsURL        17614         17384         -1.31%
BenchmarkXMLAbsURL     9431          9248          -1.94%

benchmark              old allocs     new allocs     delta
BenchmarkAbsURL        24             28             +16.67%
BenchmarkXMLAbsURL     12             14             +16.67%

benchmark              old bytes     new bytes     delta
BenchmarkAbsURL        3295          3424          +3.92%
BenchmarkXMLAbsURL     1954          1987          +1.69%
2015-03-18 17:05:54 +01:00
Anthony Fok
67df33f500 Correct initialisms as suggested by golint
First step to use initialisms that golint suggests,
for example:

    Line 116: func GetHtmlRenderer should be GetHTMLRenderer

as see on http://goreportcard.com/report/spf13/hugo

Thanks to @bep for the idea!

Note that command-line flags (cobra and pflag)
as well as struct fields like .BaseUrl and .Url
that are used in Go HTML templates need more work
to maintain backward-compatibility, and thus
are NOT yet dealt with in this commit.

First step in fixing #959.
2015-03-11 21:55:00 +01:00
bep
c2e2913872 Fix canonifyurl vs schemaless links
And looks even faster:

Compared to previous attempt:

benchmark              old ns/op     new ns/op     delta
BenchmarkAbsUrl        30902         27206         -11.96%
BenchmarkXmlAbsUrl     15389         14216         -7.62%

benchmark              old allocs     new allocs     delta
BenchmarkAbsUrl        33             28             -15.15%
BenchmarkXmlAbsUrl     16             14             -12.50%

benchmark              old bytes     new bytes     delta
BenchmarkAbsUrl        4167          3504          -15.91%
BenchmarkXmlAbsUrl     2057          2048          -0.44%

Compared to before I started all of this:

benchmark              old ns/op     new ns/op     delta
BenchmarkAbsUrl        36219         27206         -24.88%
BenchmarkXmlAbsUrl     23903         14216         -40.53%

benchmark              old allocs     new allocs     delta
BenchmarkAbsUrl        60             28             -53.33%
BenchmarkXmlAbsUrl     30             14             -53.33%

benchmark              old bytes     new bytes     delta
BenchmarkAbsUrl        5842          3504          -40.02%
BenchmarkXmlAbsUrl     3754          2048          -45.44%

Fixes #816
2015-02-17 11:07:24 +01:00
bep
f1fec88c30 Improve abs url replacement speed
This commit replaces the multuple `bytes.Containts` and `bytes.Replace` with a custom replacer that does one pass through the document and exploits the fact that there are two common prefixes we search for, `src=` and `href=`.

This is both faster and consumes less memory. There may be even better algos to use here, but we must leave some room for improvements for future versions.

This should also make it possible to solve #816.

```
benchmark              old ns/op     new ns/op     delta
BenchmarkAbsUrl        25795         22597         -12.40%
BenchmarkXmlAbsUrl     17187         11166         -35.03%

benchmark              old allocs     new allocs     delta
BenchmarkAbsUrl        60             33             -45.00%
BenchmarkXmlAbsUrl     30             16             -46.67%

benchmark              old bytes     new bytes     delta
BenchmarkAbsUrl        5844          4167          -28.70%
BenchmarkXmlAbsUrl     3754          2069          -44.89%
```

Fixes #894
2015-02-16 08:24:42 -05:00
bep
27c03a6dd0 Add benchmark for AbsUrlInXml
And a general test cleanup in /transform.

See #894
2015-02-16 08:24:42 -05:00
Ryan Martinsen
7dacc999f8 Add ability to canonify URLs in rendered XML output. 2014-12-26 16:24:28 +01:00
Noah Campbell
86233c00a0 Remove the hugo-nav function
Remove the hugo-nav since it relied on a slow library.  The current
build reimplements the absurl functionality based on string replace.
Discovered that my prior implementation missed the requirement for
making absolute paths (/path) absolute with the host, whereas a relative
path is left untouched.  Updated the test cases to support this if this
is reimplemented.
2013-11-05 22:28:06 +00:00
Noah Campbell
9af47f07d3 Improve rendering time
50% speedup.  Fix #91

to run the benchmark:

		go test -test.run=NONE -bench=".*" -test.benchmem=true ./transform/ > new.txt

to compare the results:

		/usr/local/go/misc/benchcmp baseline.txt new.txt

Speedup and memory improvements

		benchmark             old ns/op    new ns/op    delta
		BenchmarkChain           101219        50453  -50.15%
		BenchmarkTransform        51625        45531  -11.80%

		benchmark            old allocs   new allocs    delta
		BenchmarkChain              222          103  -53.60%
		BenchmarkTransform          135          106  -21.48%

		benchmark             old bytes    new bytes    delta
		BenchmarkChain            23919        10998  -54.02%
		BenchmarkTransform        11858        10665  -10.06%
2013-11-01 09:59:57 -07:00
Noah Campbell
f4cb8e1688 Adding benchmark for transformation module. 2013-11-01 09:59:57 -07:00
Noah Campbell
689cda1740 Code cleanup 2013-10-08 18:40:41 +02:00
Noah Campbell
5a66fa3954 Chain transformers and test cases
Transformers can now be chained together, working on the output of the
previous run.
2013-10-08 18:37:50 +02:00