2015-12-10 17:19:38 -05:00
|
|
|
// Copyright 2015 The Hugo Authors. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2015-03-19 12:23:14 -04:00
|
|
|
package hugolib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
"reflect"
|
2016-08-10 02:51:57 -04:00
|
|
|
"strings"
|
2015-03-19 12:23:14 -04:00
|
|
|
"testing"
|
2016-08-19 07:22:19 -04:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/deps"
|
2017-02-04 22:20:06 -05:00
|
|
|
jww "github.com/spf13/jwalterweatherman"
|
|
|
|
|
2018-02-02 01:28:24 -05:00
|
|
|
"fmt"
|
|
|
|
"runtime"
|
2018-02-09 06:32:45 -05:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2015-03-19 12:23:14 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDataDirJSON(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
t.Parallel()
|
|
|
|
|
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
|
|
|
sources := [][2]string{
|
|
|
|
{filepath.FromSlash("data/test/foo.json"), `{ "bar": "foofoo" }`},
|
|
|
|
{filepath.FromSlash("data/test.json"), `{ "hello": [ { "world": "foo" } ] }`},
|
2015-03-19 12:23:14 -04:00
|
|
|
}
|
|
|
|
|
2018-02-02 01:28:24 -05:00
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"test": map[string]interface{}{
|
|
|
|
"hello": []interface{}{
|
|
|
|
map[string]interface{}{"world": "foo"},
|
|
|
|
},
|
|
|
|
"foo": map[string]interface{}{
|
|
|
|
"bar": "foofoo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2015-03-19 12:23:14 -04:00
|
|
|
|
2018-02-02 01:28:24 -05:00
|
|
|
doTestDataDir(t, expected, sources)
|
|
|
|
}
|
|
|
|
|
2018-02-09 06:32:45 -05:00
|
|
|
// Enable / adjust in https://github.com/gohugoio/hugo/issues/4393
|
|
|
|
func _TestDataDirYAML(t *testing.T) {
|
2018-02-02 01:28:24 -05:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
sources := [][2]string{
|
|
|
|
{"data/test/a.yaml", "b:\n c1: 1\n c2: 2"},
|
2015-03-19 12:23:14 -04:00
|
|
|
}
|
|
|
|
|
2018-02-02 01:28:24 -05:00
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"test": map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b": map[interface{}]interface{}{
|
|
|
|
"c1": 1,
|
|
|
|
"c2": 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
doTestDataDir(t, expected, sources)
|
2015-03-19 12:23:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDataDirToml(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
t.Parallel()
|
|
|
|
|
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
|
|
|
sources := [][2]string{
|
|
|
|
{"data/test/kung.toml", "[foo]\nbar = 1"},
|
2015-03-19 12:23:14 -04:00
|
|
|
}
|
|
|
|
|
2018-02-02 01:28:24 -05:00
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"test": map[string]interface{}{
|
|
|
|
"kung": map[string]interface{}{
|
|
|
|
"foo": map[string]interface{}{
|
|
|
|
"bar": 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
doTestDataDir(t, expected, sources)
|
|
|
|
}
|
|
|
|
|
2018-02-09 06:32:45 -05:00
|
|
|
// Enable / adjust in https://github.com/gohugoio/hugo/issues/4393
|
|
|
|
func _TestDataDirYAML2(t *testing.T) {
|
2018-02-02 01:28:24 -05:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
sources := [][2]string{
|
|
|
|
{filepath.FromSlash("data/test/foo.yaml"), "bar: foofoo"},
|
|
|
|
{filepath.FromSlash("data/test.yaml"), "hello:\n- world: foo"},
|
|
|
|
}
|
|
|
|
|
|
|
|
//This is what we want: consistent use of map[string]interface{} for nested YAML maps
|
|
|
|
// the same as TestDataDirJSON
|
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"test": map[string]interface{}{
|
|
|
|
"hello": []interface{}{
|
|
|
|
map[string]interface{}{"world": "foo"},
|
|
|
|
},
|
|
|
|
"foo": map[string]interface{}{
|
|
|
|
"bar": "foofoo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// what we are actually getting as of v0.34
|
|
|
|
expectedV0_34 :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"test": map[string]interface{}{
|
|
|
|
"hello": []interface{}{
|
|
|
|
map[interface{}]interface{}{"world": "foo"},
|
|
|
|
},
|
|
|
|
"foo": map[string]interface{}{
|
|
|
|
"bar": "foofoo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
_ = expected
|
|
|
|
|
|
|
|
doTestDataDir(t, expectedV0_34, sources)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDataDirToml2(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
sources := [][2]string{
|
|
|
|
{filepath.FromSlash("data/test/foo.toml"), "bar = \"foofoo\""},
|
|
|
|
{filepath.FromSlash("data/test.toml"), "[[hello]]\nworld = \"foo\""},
|
|
|
|
}
|
|
|
|
|
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"test": map[string]interface{}{
|
|
|
|
"hello": []map[string]interface{}{
|
|
|
|
map[string]interface{}{"world": "foo"},
|
|
|
|
},
|
|
|
|
"foo": map[string]interface{}{
|
|
|
|
"bar": "foofoo",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
doTestDataDir(t, expected, sources)
|
|
|
|
}
|
2015-03-19 12:23:14 -04:00
|
|
|
|
2018-02-02 01:28:24 -05:00
|
|
|
func TestDataDirJSONWithOverriddenValue(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
sources := [][2]string{
|
|
|
|
// filepath.Walk walks the files in lexical order, '/' comes before '.'. Simulate this:
|
|
|
|
{filepath.FromSlash("data/a.json"), `{"a": "1"}`},
|
|
|
|
{filepath.FromSlash("data/test/v1.json"), `{"v1-2": "2"}`},
|
|
|
|
{filepath.FromSlash("data/test/v2.json"), `{"v2": ["2", "3"]}`},
|
|
|
|
{filepath.FromSlash("data/test.json"), `{"v1": "1"}`},
|
2015-03-19 12:23:14 -04:00
|
|
|
}
|
|
|
|
|
2018-02-02 01:28:24 -05:00
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{"a": "1"},
|
|
|
|
"test": map[string]interface{}{
|
|
|
|
"v1": map[string]interface{}{"v1-2": "2"},
|
|
|
|
"v2": map[string]interface{}{"v2": []interface{}{"2", "3"}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
doTestDataDir(t, expected, sources)
|
2015-03-19 12:23:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDataDirYAMLWithOverridenValue(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
t.Parallel()
|
|
|
|
|
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
|
|
|
sources := [][2]string{
|
2015-03-19 12:23:14 -04:00
|
|
|
// filepath.Walk walks the files in lexical order, '/' comes before '.'. Simulate this:
|
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
|
|
|
{filepath.FromSlash("data/a.yaml"), "a: 1"},
|
|
|
|
{filepath.FromSlash("data/test/v1.yaml"), "v1-2: 2"},
|
|
|
|
{filepath.FromSlash("data/test/v2.yaml"), "v2:\n- 2\n- 3"},
|
|
|
|
{filepath.FromSlash("data/test.yaml"), "v1: 1"},
|
2015-03-19 12:23:14 -04:00
|
|
|
}
|
|
|
|
|
2018-02-02 01:28:24 -05:00
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{"a": 1},
|
|
|
|
"test": map[string]interface{}{
|
|
|
|
"v1": map[string]interface{}{"v1-2": 2},
|
|
|
|
"v2": map[string]interface{}{"v2": []interface{}{2, 3}},
|
|
|
|
},
|
|
|
|
}
|
2015-03-19 12:23:14 -04:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
doTestDataDir(t, expected, sources)
|
2015-03-19 12:23:14 -04:00
|
|
|
}
|
|
|
|
|
2018-02-02 01:28:24 -05:00
|
|
|
// Issue #4361
|
|
|
|
func TestDataDirJSONArrayAtTopLevelOfFile(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
sources := [][2]string{
|
|
|
|
{filepath.FromSlash("data/test.json"), `[ { "hello": "world" }, { "what": "time" }, { "is": "lunch?" } ]`},
|
|
|
|
}
|
|
|
|
|
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"test": []interface{}{
|
|
|
|
map[string]interface{}{"hello": "world"},
|
|
|
|
map[string]interface{}{"what": "time"},
|
|
|
|
map[string]interface{}{"is": "lunch?"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
doTestDataDir(t, expected, sources)
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Issue #3890 unresolved
|
|
|
|
func TestDataDirYAMLArrayAtTopLevelOfFile(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
sources := [][2]string{
|
|
|
|
{filepath.FromSlash("data/test.yaml"), `
|
|
|
|
- hello: world
|
|
|
|
- what: time
|
|
|
|
- is: lunch?
|
|
|
|
`},
|
|
|
|
}
|
|
|
|
|
|
|
|
//TODO decide whether desired structure map[interface {}]interface{} as shown
|
|
|
|
// and as the YAML parser produces, or should it be map[string]interface{}
|
|
|
|
// all the way down per Issue #4138
|
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"test": []interface{}{
|
|
|
|
map[interface{}]interface{}{"hello": "world"},
|
|
|
|
map[interface{}]interface{}{"what": "time"},
|
|
|
|
map[interface{}]interface{}{"is": "lunch?"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// what we are actually getting as of v0.34
|
|
|
|
expectedV0_34 :=
|
|
|
|
map[string]interface{}{}
|
|
|
|
_ = expected
|
|
|
|
|
|
|
|
doTestDataDir(t, expectedV0_34, sources)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Issue #892
|
2015-03-19 12:23:14 -04:00
|
|
|
func TestDataDirMultipleSources(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
t.Parallel()
|
2015-03-19 12:23:14 -04:00
|
|
|
|
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
|
|
|
sources := [][2]string{
|
2018-02-02 01:28:24 -05:00
|
|
|
{filepath.FromSlash("data/test/first.yaml"), "bar: 1"},
|
|
|
|
{filepath.FromSlash("themes/mytheme/data/test/first.yaml"), "bar: 2"},
|
|
|
|
{filepath.FromSlash("data/test/second.yaml"), "tender: 2"},
|
2015-03-19 12:23:14 -04:00
|
|
|
}
|
|
|
|
|
2018-02-02 01:28:24 -05:00
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"test": map[string]interface{}{
|
|
|
|
"first": map[string]interface{}{
|
|
|
|
"bar": 1,
|
|
|
|
},
|
|
|
|
"second": map[string]interface{}{
|
|
|
|
"tender": 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2015-03-19 12:23:14 -04:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
doTestDataDir(t, expected, sources,
|
|
|
|
"theme", "mytheme")
|
2015-03-19 12:23:14 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-02 01:28:24 -05:00
|
|
|
// test (and show) the way values from four different sources commingle and override
|
|
|
|
func TestDataDirMultipleSourcesCommingled(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
sources := [][2]string{
|
|
|
|
{filepath.FromSlash("data/a.json"), `{ "b1" : { "c1": "data/a" }, "b2": "data/a", "b3": ["x", "y", "z"] }`},
|
|
|
|
{filepath.FromSlash("themes/mytheme/data/a.json"), `{ "b1": "mytheme/data/a", "b2": "mytheme/data/a", "b3": "mytheme/data/a" }`},
|
|
|
|
{filepath.FromSlash("themes/mytheme/data/a/b1.json"), `{ "c1": "mytheme/data/a/b1", "c2": "mytheme/data/a/b1" }`},
|
|
|
|
{filepath.FromSlash("data/a/b1.json"), `{ "c1": "data/a/b1" }`},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Per handleDataFile() comment:
|
|
|
|
// 1. A theme uses the same key; the main data folder wins
|
|
|
|
// 2. A sub folder uses the same key: the sub folder wins
|
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b1": map[string]interface{}{
|
|
|
|
"c1": "data/a/b1",
|
|
|
|
"c2": "mytheme/data/a/b1",
|
|
|
|
},
|
|
|
|
"b2": "data/a",
|
|
|
|
"b3": []interface{}{"x", "y", "z"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
doTestDataDir(t, expected, sources,
|
|
|
|
"theme", "mytheme")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDataDirMultipleSourcesCollidingChildArrays(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
sources := [][2]string{
|
|
|
|
{filepath.FromSlash("data/a.json"), `{ "b1" : "data/a", "b2" : ["x", "y", "z"] }`},
|
|
|
|
{filepath.FromSlash("data/a/b2.json"), `["1", "2", "3"]`},
|
|
|
|
}
|
|
|
|
|
|
|
|
// Per handleDataFile() comment:
|
|
|
|
// 1. A theme uses the same key; the main data folder wins
|
|
|
|
// 2. A sub folder uses the same key: the sub folder wins
|
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b1": "data/a",
|
|
|
|
"b2": []interface{}{"1", "2", "3"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
doTestDataDir(t, expected, sources,
|
|
|
|
"theme", "mytheme")
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO Issue #4366 unresolved
|
|
|
|
func TestDataDirMultipleSourcesCollidingTopLevelArrays(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
sources := [][2]string{
|
|
|
|
{filepath.FromSlash("themes/mytheme/data/a/b1.json"), `["x", "y", "z"]`},
|
|
|
|
{filepath.FromSlash("data/a/b1.json"), `["1", "2", "3"]`},
|
|
|
|
}
|
|
|
|
|
|
|
|
expected :=
|
|
|
|
map[string]interface{}{
|
|
|
|
"a": map[string]interface{}{
|
|
|
|
"b1": []interface{}{"1", "2", "3"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// as of v0.34 this test results in a go Panic
|
|
|
|
_ = sources
|
|
|
|
_ = expected
|
|
|
|
/*
|
|
|
|
doTestDataDir(t, expectedV0_35, sources,
|
|
|
|
"theme", "mytheme")
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
:sparkles: Implement Page bundling and image handling
This commit is not the smallest in Hugo's history.
Some hightlights include:
* Page bundles (for complete articles, keeping images and content together etc.).
* Bundled images can be processed in as many versions/sizes as you need with the three methods `Resize`, `Fill` and `Fit`.
* Processed images are cached inside `resources/_gen/images` (default) in your project.
* Symbolic links (both files and dirs) are now allowed anywhere inside /content
* A new table based build summary
* The "Total in nn ms" now reports the total including the handling of the files inside /static. So if it now reports more than you're used to, it is just **more real** and probably faster than before (see below).
A site building benchmark run compared to `v0.31.1` shows that this should be slightly faster and use less memory:
```bash
▶ ./benchSite.sh "TOML,num_langs=.*,num_root_sections=5,num_pages=(500|1000),tags_per_page=5,shortcodes,render"
benchmark old ns/op new ns/op delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 101785785 78067944 -23.30%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 185481057 149159919 -19.58%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 103149918 85679409 -16.94%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 203515478 169208775 -16.86%
benchmark old allocs new allocs delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 532464 391539 -26.47%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1056549 772702 -26.87%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 555974 406630 -26.86%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 1086545 789922 -27.30%
benchmark old bytes new bytes delta
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 53243246 43598155 -18.12%
BenchmarkSiteBuilding/TOML,num_langs=1,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 105811617 86087116 -18.64%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=500,tags_per_page=5,shortcodes,render-4 54558852 44545097 -18.35%
BenchmarkSiteBuilding/TOML,num_langs=3,num_root_sections=5,num_pages=1000,tags_per_page=5,shortcodes,render-4 106903858 86978413 -18.64%
```
Fixes #3651
Closes #3158
Fixes #1014
Closes #2021
Fixes #1240
Updates #3757
2017-07-24 03:00:23 -04:00
|
|
|
func doTestDataDir(t *testing.T, expected interface{}, sources [][2]string, configKeyValues ...interface{}) {
|
2017-02-04 22:20:06 -05:00
|
|
|
var (
|
|
|
|
cfg, fs = newTestCfg()
|
|
|
|
)
|
|
|
|
|
|
|
|
for i := 0; i < len(configKeyValues); i += 2 {
|
|
|
|
cfg.Set(configKeyValues[i].(string), configKeyValues[i+1])
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2018-02-02 01:28:24 -05:00
|
|
|
logger = jww.NewNotepad(jww.LevelWarn, jww.LevelWarn, os.Stdout, ioutil.Discard, t.Name(), log.Ldate|log.Ltime)
|
2017-02-04 22:20:06 -05:00
|
|
|
depsCfg = deps.DepsCfg{Fs: fs, Cfg: cfg, Logger: logger}
|
|
|
|
)
|
|
|
|
|
|
|
|
writeSource(t, fs, filepath.Join("content", "dummy.md"), "content")
|
|
|
|
writeSourcesToSource(t, "", fs, sources...)
|
|
|
|
|
|
|
|
expectBuildError := false
|
|
|
|
|
|
|
|
if ok, shouldFail := expected.(bool); ok && shouldFail {
|
|
|
|
expectBuildError = true
|
|
|
|
}
|
|
|
|
|
2018-02-02 01:28:24 -05:00
|
|
|
// trap and report panics as unmarshaling errors so that test suit can complete
|
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
// Capture the stack trace
|
|
|
|
buf := make([]byte, 10000)
|
|
|
|
runtime.Stack(buf, false)
|
|
|
|
t.Errorf("PANIC: %s\n\nStack Trace : %s", r, string(buf))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
s := buildSingleSiteExpected(t, expectBuildError, depsCfg, BuildCfg{SkipRender: true})
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
if !expectBuildError && !reflect.DeepEqual(expected, s.Data) {
|
2018-02-02 01:28:24 -05:00
|
|
|
exp := fmt.Sprintf("%#v", expected)
|
|
|
|
got := fmt.Sprintf("%#v", s.Data)
|
|
|
|
if exp == got { //TODO: This workaround seems to be triggered only by the TOML tests
|
|
|
|
t.Logf("WARNING: reflect.DeepEqual returned FALSE for values that appear equal.\n"+
|
|
|
|
"Treating as equal for the purpose of the test, but this maybe should be investigated.\n"+
|
|
|
|
"Expected data:\n%v got\n%v\n\nExpected type structure:\n%#[1]v got\n%#[2]v", expected, s.Data)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Errorf("Expected data:\n%v got\n%v\n\nExpected type structure:\n%#[1]v got\n%#[2]v", expected, s.Data)
|
2015-03-19 12:23:14 -04:00
|
|
|
}
|
|
|
|
}
|
2016-08-10 02:51:57 -04:00
|
|
|
|
|
|
|
func TestDataFromShortcode(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
t.Parallel()
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
var (
|
|
|
|
cfg, fs = newTestCfg()
|
|
|
|
)
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
writeSource(t, fs, "data/hugo.toml", "slogan = \"Hugo Rocks!\"")
|
|
|
|
writeSource(t, fs, "layouts/_default/single.html", `
|
2016-08-10 02:51:57 -04:00
|
|
|
* Slogan from template: {{ .Site.Data.hugo.slogan }}
|
|
|
|
* {{ .Content }}`)
|
2017-02-04 22:20:06 -05:00
|
|
|
writeSource(t, fs, "layouts/shortcodes/d.html", `{{ .Page.Site.Data.hugo.slogan }}`)
|
|
|
|
writeSource(t, fs, "content/c.md", `---
|
2016-08-10 02:51:57 -04:00
|
|
|
---
|
|
|
|
Slogan from shortcode: {{< d >}}
|
|
|
|
`)
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
|
2016-08-10 02:51:57 -04:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
content := readSource(t, fs, "public/c/index.html")
|
2016-08-10 02:51:57 -04:00
|
|
|
require.True(t, strings.Contains(content, "Slogan from template: Hugo Rocks!"), content)
|
|
|
|
require.True(t, strings.Contains(content, "Slogan from shortcode: Hugo Rocks!"), content)
|
|
|
|
|
|
|
|
}
|