2019-01-02 06:33:26 -05:00
|
|
|
// Copyright 2019 The Hugo Authors. All rights reserved.
|
2017-04-09 04:33:04 -04:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
package hugolib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/deps"
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/resources/page"
|
2017-04-09 04:33:04 -04:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNestedSections(t *testing.T) {
|
|
|
|
|
|
|
|
var (
|
|
|
|
assert = require.New(t)
|
|
|
|
cfg, fs = newTestCfg()
|
|
|
|
th = testHelper{cfg, fs, t}
|
|
|
|
)
|
|
|
|
|
2017-06-12 13:14:29 -04:00
|
|
|
cfg.Set("permalinks", map[string]string{
|
|
|
|
"perm a": ":sections/:title",
|
|
|
|
})
|
|
|
|
|
2017-04-09 04:33:04 -04:00
|
|
|
pageTemplate := `---
|
|
|
|
title: T%d_%d
|
|
|
|
---
|
|
|
|
Content
|
|
|
|
`
|
|
|
|
|
|
|
|
// Home page
|
|
|
|
writeSource(t, fs, filepath.Join("content", "_index.md"), fmt.Sprintf(pageTemplate, -1, -1))
|
|
|
|
|
|
|
|
// Top level content page
|
|
|
|
writeSource(t, fs, filepath.Join("content", "mypage.md"), fmt.Sprintf(pageTemplate, 1234, 5))
|
|
|
|
|
|
|
|
// Top level section without index content page
|
|
|
|
writeSource(t, fs, filepath.Join("content", "top", "mypage2.md"), fmt.Sprintf(pageTemplate, 12345, 6))
|
|
|
|
// Just a page in a subfolder, i.e. not a section.
|
|
|
|
writeSource(t, fs, filepath.Join("content", "top", "folder", "mypage3.md"), fmt.Sprintf(pageTemplate, 12345, 67))
|
|
|
|
|
|
|
|
for level1 := 1; level1 < 3; level1++ {
|
|
|
|
writeSource(t, fs, filepath.Join("content", "l1", fmt.Sprintf("page_1_%d.md", level1)),
|
|
|
|
fmt.Sprintf(pageTemplate, 1, level1))
|
|
|
|
}
|
|
|
|
|
2017-06-13 05:26:17 -04:00
|
|
|
// Issue #3586
|
|
|
|
writeSource(t, fs, filepath.Join("content", "post", "0000.md"), fmt.Sprintf(pageTemplate, 1, 2))
|
|
|
|
writeSource(t, fs, filepath.Join("content", "post", "0000", "0001.md"), fmt.Sprintf(pageTemplate, 1, 3))
|
|
|
|
writeSource(t, fs, filepath.Join("content", "elsewhere", "0003.md"), fmt.Sprintf(pageTemplate, 1, 4))
|
|
|
|
|
2017-04-09 04:33:04 -04:00
|
|
|
// Empty nested section, i.e. no regular content pages.
|
|
|
|
writeSource(t, fs, filepath.Join("content", "empty1", "b", "c", "_index.md"), fmt.Sprintf(pageTemplate, 33, -1))
|
|
|
|
// Index content file a the end and in the middle.
|
|
|
|
writeSource(t, fs, filepath.Join("content", "empty2", "b", "_index.md"), fmt.Sprintf(pageTemplate, 40, -1))
|
|
|
|
writeSource(t, fs, filepath.Join("content", "empty2", "b", "c", "d", "_index.md"), fmt.Sprintf(pageTemplate, 41, -1))
|
|
|
|
|
|
|
|
// Empty with content file in the middle.
|
|
|
|
writeSource(t, fs, filepath.Join("content", "empty3", "b", "c", "d", "_index.md"), fmt.Sprintf(pageTemplate, 41, -1))
|
|
|
|
writeSource(t, fs, filepath.Join("content", "empty3", "b", "empty3.md"), fmt.Sprintf(pageTemplate, 3, -1))
|
|
|
|
|
2017-06-12 13:14:29 -04:00
|
|
|
// Section with permalink config
|
|
|
|
writeSource(t, fs, filepath.Join("content", "perm a", "link", "_index.md"), fmt.Sprintf(pageTemplate, 9, -1))
|
|
|
|
for i := 1; i < 4; i++ {
|
|
|
|
writeSource(t, fs, filepath.Join("content", "perm a", "link", fmt.Sprintf("page_%d.md", i)),
|
|
|
|
fmt.Sprintf(pageTemplate, 1, i))
|
|
|
|
}
|
|
|
|
writeSource(t, fs, filepath.Join("content", "perm a", "link", "regular", fmt.Sprintf("page_%d.md", 5)),
|
|
|
|
fmt.Sprintf(pageTemplate, 1, 5))
|
|
|
|
|
2017-04-09 04:33:04 -04:00
|
|
|
writeSource(t, fs, filepath.Join("content", "l1", "l2", "_index.md"), fmt.Sprintf(pageTemplate, 2, -1))
|
|
|
|
writeSource(t, fs, filepath.Join("content", "l1", "l2_2", "_index.md"), fmt.Sprintf(pageTemplate, 22, -1))
|
|
|
|
writeSource(t, fs, filepath.Join("content", "l1", "l2", "l3", "_index.md"), fmt.Sprintf(pageTemplate, 3, -1))
|
|
|
|
|
|
|
|
for level2 := 1; level2 < 4; level2++ {
|
|
|
|
writeSource(t, fs, filepath.Join("content", "l1", "l2", fmt.Sprintf("page_2_%d.md", level2)),
|
|
|
|
fmt.Sprintf(pageTemplate, 2, level2))
|
|
|
|
}
|
|
|
|
for level2 := 1; level2 < 3; level2++ {
|
|
|
|
writeSource(t, fs, filepath.Join("content", "l1", "l2_2", fmt.Sprintf("page_2_2_%d.md", level2)),
|
|
|
|
fmt.Sprintf(pageTemplate, 2, level2))
|
|
|
|
}
|
|
|
|
for level3 := 1; level3 < 3; level3++ {
|
|
|
|
writeSource(t, fs, filepath.Join("content", "l1", "l2", "l3", fmt.Sprintf("page_3_%d.md", level3)),
|
|
|
|
fmt.Sprintf(pageTemplate, 3, level3))
|
|
|
|
}
|
|
|
|
|
|
|
|
writeSource(t, fs, filepath.Join("content", "Spaces in Section", "page100.md"), fmt.Sprintf(pageTemplate, 10, 0))
|
|
|
|
|
|
|
|
writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), "<html>Single|{{ .Title }}</html>")
|
|
|
|
writeSource(t, fs, filepath.Join("layouts", "_default", "list.html"),
|
|
|
|
`
|
2018-07-17 05:18:29 -04:00
|
|
|
{{ $sect := (.Site.GetPage "l1/l2") }}
|
2017-04-09 04:33:04 -04:00
|
|
|
<html>List|{{ .Title }}|L1/l2-IsActive: {{ .InSection $sect }}
|
|
|
|
{{ range .Paginator.Pages }}
|
|
|
|
PAG|{{ .Title }}|{{ $sect.InSection . }}
|
|
|
|
{{ end }}
|
2018-07-24 04:10:51 -04:00
|
|
|
{{/* https://github.com/gohugoio/hugo/issues/4989 */}}
|
|
|
|
{{ $sections := (.Site.GetPage "section" .Section).Sections.ByWeight }}
|
2017-04-09 04:33:04 -04:00
|
|
|
</html>`)
|
|
|
|
|
|
|
|
cfg.Set("paginate", 2)
|
|
|
|
|
|
|
|
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
|
: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
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Len(t, s.RegularPages(), 21)
|
2017-04-09 04:33:04 -04:00
|
|
|
|
|
|
|
tests := []struct {
|
|
|
|
sections string
|
2019-01-02 06:33:26 -05:00
|
|
|
verify func(assert *require.Assertions, p page.Page)
|
2017-04-09 04:33:04 -04:00
|
|
|
}{
|
2019-01-02 06:33:26 -05:00
|
|
|
{"elsewhere", func(assert *require.Assertions, p page.Page) {
|
|
|
|
assert.Len(p.Pages(), 1)
|
|
|
|
for _, p := range p.Pages() {
|
|
|
|
assert.Equal("elsewhere", p.SectionsPath())
|
2017-06-13 05:26:17 -04:00
|
|
|
}
|
|
|
|
}},
|
2019-01-02 06:33:26 -05:00
|
|
|
{"post", func(assert *require.Assertions, p page.Page) {
|
|
|
|
assert.Len(p.Pages(), 2)
|
|
|
|
for _, p := range p.Pages() {
|
2017-06-13 05:26:17 -04:00
|
|
|
assert.Equal("post", p.Section())
|
|
|
|
}
|
|
|
|
}},
|
2019-01-02 06:33:26 -05:00
|
|
|
{"empty1", func(assert *require.Assertions, p page.Page) {
|
2017-04-09 04:33:04 -04:00
|
|
|
// > b,c
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.NotNil(getPage(p, "/empty1/b"))
|
|
|
|
assert.NotNil(getPage(p, "/empty1/b/c"))
|
2017-04-09 04:33:04 -04:00
|
|
|
|
|
|
|
}},
|
2019-01-02 06:33:26 -05:00
|
|
|
{"empty2", func(assert *require.Assertions, p page.Page) {
|
2017-04-09 04:33:04 -04:00
|
|
|
// > b,c,d where b and d have content files.
|
2019-01-02 06:33:26 -05:00
|
|
|
b := getPage(p, "/empty2/b")
|
2017-04-09 04:33:04 -04:00
|
|
|
assert.NotNil(b)
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.Equal("T40_-1", b.Title())
|
|
|
|
c := getPage(p, "/empty2/b/c")
|
|
|
|
|
2017-04-09 04:33:04 -04:00
|
|
|
assert.NotNil(c)
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.Equal("Cs", c.Title())
|
|
|
|
d := getPage(p, "/empty2/b/c/d")
|
|
|
|
|
2017-04-09 04:33:04 -04:00
|
|
|
assert.NotNil(d)
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.Equal("T41_-1", d.Title())
|
2017-08-16 03:59:42 -04:00
|
|
|
|
2017-08-17 03:43:39 -04:00
|
|
|
assert.False(c.Eq(d))
|
|
|
|
assert.True(c.Eq(c))
|
|
|
|
assert.False(c.Eq("asdf"))
|
2017-08-16 03:59:42 -04:00
|
|
|
|
2017-04-09 04:33:04 -04:00
|
|
|
}},
|
2019-01-02 06:33:26 -05:00
|
|
|
{"empty3", func(assert *require.Assertions, p page.Page) {
|
2017-04-09 04:33:04 -04:00
|
|
|
// b,c,d with regular page in b
|
2019-01-02 06:33:26 -05:00
|
|
|
b := getPage(p, "/empty3/b")
|
2017-04-09 04:33:04 -04:00
|
|
|
assert.NotNil(b)
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.Len(b.Pages(), 1)
|
|
|
|
assert.Equal("empty3.md", b.Pages()[0].File().LogicalName())
|
2017-04-09 04:33:04 -04:00
|
|
|
|
|
|
|
}},
|
2019-01-02 06:33:26 -05:00
|
|
|
{"empty3", func(assert *require.Assertions, p page.Page) {
|
|
|
|
xxx := getPage(p, "/empty3/nil")
|
2018-10-02 22:46:32 -04:00
|
|
|
assert.Nil(xxx)
|
|
|
|
}},
|
2019-01-02 06:33:26 -05:00
|
|
|
{"top", func(assert *require.Assertions, p page.Page) {
|
|
|
|
assert.Equal("Tops", p.Title())
|
|
|
|
assert.Len(p.Pages(), 2)
|
|
|
|
assert.Equal("mypage2.md", p.Pages()[0].File().LogicalName())
|
|
|
|
assert.Equal("mypage3.md", p.Pages()[1].File().LogicalName())
|
2017-04-09 04:33:04 -04:00
|
|
|
home := p.Parent()
|
|
|
|
assert.True(home.IsHome())
|
|
|
|
assert.Len(p.Sections(), 0)
|
2017-07-02 14:14:06 -04:00
|
|
|
assert.Equal(home, home.CurrentSection())
|
2017-04-09 04:33:04 -04:00
|
|
|
active, err := home.InSection(home)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.True(active)
|
2018-07-23 14:19:32 -04:00
|
|
|
assert.Equal(p, p.FirstSection())
|
2017-04-09 04:33:04 -04:00
|
|
|
}},
|
2019-01-02 06:33:26 -05:00
|
|
|
{"l1", func(assert *require.Assertions, p page.Page) {
|
|
|
|
assert.Equal("L1s", p.Title())
|
|
|
|
assert.Len(p.Pages(), 2)
|
2017-04-09 04:33:04 -04:00
|
|
|
assert.True(p.Parent().IsHome())
|
|
|
|
assert.Len(p.Sections(), 2)
|
|
|
|
}},
|
2019-01-02 06:33:26 -05:00
|
|
|
{"l1,l2", func(assert *require.Assertions, p page.Page) {
|
|
|
|
assert.Equal("T2_-1", p.Title())
|
|
|
|
assert.Len(p.Pages(), 3)
|
|
|
|
assert.Equal(p, p.Pages()[0].Parent())
|
|
|
|
assert.Equal("L1s", p.Parent().Title())
|
2017-04-09 04:33:04 -04:00
|
|
|
assert.Equal("/l1/l2/", p.RelPermalink())
|
|
|
|
assert.Len(p.Sections(), 1)
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
for _, child := range p.Pages() {
|
|
|
|
|
2017-07-02 14:14:06 -04:00
|
|
|
assert.Equal(p, child.CurrentSection())
|
2017-04-09 04:33:04 -04:00
|
|
|
active, err := child.InSection(p)
|
|
|
|
assert.NoError(err)
|
2019-01-02 06:33:26 -05:00
|
|
|
|
2017-04-09 04:33:04 -04:00
|
|
|
assert.True(active)
|
|
|
|
active, err = p.InSection(child)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.True(active)
|
2019-01-02 06:33:26 -05:00
|
|
|
active, err = p.InSection(getPage(p, "/"))
|
2017-04-09 04:33:04 -04:00
|
|
|
assert.NoError(err)
|
|
|
|
assert.False(active)
|
2017-07-02 14:14:06 -04:00
|
|
|
|
|
|
|
isAncestor, err := p.IsAncestor(child)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.True(isAncestor)
|
|
|
|
isAncestor, err = child.IsAncestor(p)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.False(isAncestor)
|
|
|
|
|
|
|
|
isDescendant, err := p.IsDescendant(child)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.False(isDescendant)
|
|
|
|
isDescendant, err = child.IsDescendant(p)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.True(isDescendant)
|
2017-04-09 04:33:04 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.True(p.Eq(p.CurrentSection()))
|
2017-04-09 04:33:04 -04:00
|
|
|
|
|
|
|
}},
|
2019-01-02 06:33:26 -05:00
|
|
|
{"l1,l2_2", func(assert *require.Assertions, p page.Page) {
|
|
|
|
assert.Equal("T22_-1", p.Title())
|
|
|
|
assert.Len(p.Pages(), 2)
|
|
|
|
assert.Equal(filepath.FromSlash("l1/l2_2/page_2_2_1.md"), p.Pages()[0].File().Path())
|
|
|
|
assert.Equal("L1s", p.Parent().Title())
|
2017-04-09 04:33:04 -04:00
|
|
|
assert.Len(p.Sections(), 0)
|
|
|
|
}},
|
2019-01-02 06:33:26 -05:00
|
|
|
{"l1,l2,l3", func(assert *require.Assertions, p page.Page) {
|
|
|
|
nilp, _ := p.GetPage("this/does/not/exist")
|
2018-11-28 06:36:59 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.Equal("T3_-1", p.Title())
|
|
|
|
assert.Len(p.Pages(), 2)
|
|
|
|
assert.Equal("T2_-1", p.Parent().Title())
|
2017-04-09 04:33:04 -04:00
|
|
|
assert.Len(p.Sections(), 0)
|
2017-07-02 14:14:06 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
l1 := getPage(p, "/l1")
|
2017-07-02 14:14:06 -04:00
|
|
|
isDescendant, err := l1.IsDescendant(p)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.False(isDescendant)
|
2018-11-28 06:36:59 -05:00
|
|
|
isDescendant, err = l1.IsDescendant(nil)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.False(isDescendant)
|
|
|
|
isDescendant, err = nilp.IsDescendant(p)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.False(isDescendant)
|
2017-07-02 14:14:06 -04:00
|
|
|
isDescendant, err = p.IsDescendant(l1)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.True(isDescendant)
|
|
|
|
|
|
|
|
isAncestor, err := l1.IsAncestor(p)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.True(isAncestor)
|
|
|
|
isAncestor, err = p.IsAncestor(l1)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.False(isAncestor)
|
2018-07-23 14:19:32 -04:00
|
|
|
assert.Equal(l1, p.FirstSection())
|
2018-11-28 06:36:59 -05:00
|
|
|
isAncestor, err = p.IsAncestor(nil)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.False(isAncestor)
|
|
|
|
isAncestor, err = nilp.IsAncestor(l1)
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.False(isAncestor)
|
2017-07-02 14:14:06 -04:00
|
|
|
|
2017-04-09 04:33:04 -04:00
|
|
|
}},
|
2019-01-02 06:33:26 -05:00
|
|
|
{"perm a,link", func(assert *require.Assertions, p page.Page) {
|
|
|
|
assert.Equal("T9_-1", p.Title())
|
2017-06-12 13:14:29 -04:00
|
|
|
assert.Equal("/perm-a/link/", p.RelPermalink())
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.Len(p.Pages(), 4)
|
|
|
|
first := p.Pages()[0]
|
2017-06-12 13:14:29 -04:00
|
|
|
assert.Equal("/perm-a/link/t1_1/", first.RelPermalink())
|
|
|
|
th.assertFileContent("public/perm-a/link/t1_1/index.html", "Single|T1_1")
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
last := p.Pages()[3]
|
2017-06-12 13:14:29 -04:00
|
|
|
assert.Equal("/perm-a/link/t1_5/", last.RelPermalink())
|
|
|
|
|
|
|
|
}},
|
2017-04-09 04:33:04 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
home := s.getPage(page.KindHome)
|
: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
|
|
|
|
2017-04-09 04:33:04 -04:00
|
|
|
for _, test := range tests {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
test := test
|
2019-01-02 06:33:26 -05:00
|
|
|
t.Run(fmt.Sprintf("sections %s", test.sections), func(t *testing.T) {
|
Add Hugo Modules
This commit implements Hugo Modules.
This is a broad subject, but some keywords include:
* A new `module` configuration section where you can import almost anything. You can configure both your own file mounts nd the file mounts of the modules you import. This is the new recommended way of configuring what you earlier put in `configDir`, `staticDir` etc. And it also allows you to mount folders in non-Hugo-projects, e.g. the `SCSS` folder in the Bootstrap GitHub project.
* A module consists of a set of mounts to the standard 7 component types in Hugo: `static`, `content`, `layouts`, `data`, `assets`, `i18n`, and `archetypes`. Yes, Theme Components can now include content, which should be very useful, especially in bigger multilingual projects.
* Modules not in your local file cache will be downloaded automatically and even "hot replaced" while the server is running.
* Hugo Modules supports and encourages semver versioned modules, and uses the minimal version selection algorithm to resolve versions.
* A new set of CLI commands are provided to manage all of this: `hugo mod init`, `hugo mod get`, `hugo mod graph`, `hugo mod tidy`, and `hugo mod vendor`.
All of the above is backed by Go Modules.
Fixes #5973
Fixes #5996
Fixes #6010
Fixes #5911
Fixes #5940
Fixes #6074
Fixes #6082
Fixes #6092
2019-05-03 03:16:58 -04:00
|
|
|
t.Parallel()
|
2019-01-02 06:33:26 -05:00
|
|
|
assert := require.New(t)
|
|
|
|
sections := strings.Split(test.sections, ",")
|
|
|
|
p := s.getPage(page.KindSection, sections...)
|
|
|
|
assert.NotNil(p, fmt.Sprint(sections))
|
|
|
|
|
|
|
|
if p.Pages() != nil {
|
|
|
|
assert.Equal(p.Pages(), p.Data().(page.Data).Pages())
|
|
|
|
}
|
|
|
|
assert.NotNil(p.Parent(), fmt.Sprintf("Parent nil: %q", test.sections))
|
|
|
|
test.verify(assert, p)
|
|
|
|
})
|
2017-04-09 04:33:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
assert.NotNil(home)
|
|
|
|
|
2017-06-13 05:26:17 -04:00
|
|
|
assert.Len(home.Sections(), 9)
|
2017-07-02 12:20:14 -04:00
|
|
|
assert.Equal(home.Sections(), s.Info.Sections())
|
2017-04-09 04:33:04 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
rootPage := s.getPage(page.KindPage, "mypage.md")
|
2017-04-09 04:33:04 -04:00
|
|
|
assert.NotNil(rootPage)
|
|
|
|
assert.True(rootPage.Parent().IsHome())
|
|
|
|
|
|
|
|
// Add a odd test for this as this looks a little bit off, but I'm not in the mood
|
|
|
|
// to think too hard a out this right now. It works, but people will have to spell
|
|
|
|
// out the directory name as is.
|
|
|
|
// If we later decide to do something about this, we will have to do some normalization in
|
|
|
|
// getPage.
|
|
|
|
// TODO(bep)
|
2019-01-02 06:33:26 -05:00
|
|
|
sectionWithSpace := s.getPage(page.KindSection, "Spaces in Section")
|
2017-04-09 04:33:04 -04:00
|
|
|
require.NotNil(t, sectionWithSpace)
|
|
|
|
require.Equal(t, "/spaces-in-section/", sectionWithSpace.RelPermalink())
|
|
|
|
|
|
|
|
th.assertFileContent("public/l1/l2/page/2/index.html", "L1/l2-IsActive: true", "PAG|T2_3|true")
|
|
|
|
|
|
|
|
}
|
2019-05-01 11:51:03 -04:00
|
|
|
|
|
|
|
func TestNextInSectionNested(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
pageContent := `---
|
|
|
|
title: "The Page"
|
|
|
|
weight: %d
|
|
|
|
---
|
|
|
|
Some content.
|
|
|
|
`
|
|
|
|
createPageContent := func(weight int) string {
|
|
|
|
return fmt.Sprintf(pageContent, weight)
|
|
|
|
}
|
|
|
|
|
|
|
|
b := newTestSitesBuilder(t)
|
|
|
|
b.WithSimpleConfigFile()
|
|
|
|
b.WithTemplates("_default/single.html", `
|
|
|
|
Prev: {{ with .PrevInSection }}{{ .RelPermalink }}{{ end }}|
|
|
|
|
Next: {{ with .NextInSection }}{{ .RelPermalink }}{{ end }}|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("blog/page1.md", createPageContent(1))
|
|
|
|
b.WithContent("blog/page2.md", createPageContent(2))
|
|
|
|
b.WithContent("blog/cool/_index.md", createPageContent(1))
|
|
|
|
b.WithContent("blog/cool/cool1.md", createPageContent(1))
|
|
|
|
b.WithContent("blog/cool/cool2.md", createPageContent(2))
|
|
|
|
b.WithContent("root1.md", createPageContent(1))
|
|
|
|
b.WithContent("root2.md", createPageContent(2))
|
|
|
|
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
|
|
|
b.AssertFileContent("public/root1/index.html",
|
|
|
|
"Prev: /root2/|", "Next: |")
|
|
|
|
b.AssertFileContent("public/root2/index.html",
|
|
|
|
"Prev: |", "Next: /root1/|")
|
|
|
|
b.AssertFileContent("public/blog/page1/index.html",
|
|
|
|
"Prev: /blog/page2/|", "Next: |")
|
|
|
|
b.AssertFileContent("public/blog/page2/index.html",
|
|
|
|
"Prev: |", "Next: /blog/page1/|")
|
|
|
|
b.AssertFileContent("public/blog/cool/cool1/index.html",
|
|
|
|
"Prev: /blog/cool/cool2/|", "Next: |")
|
|
|
|
b.AssertFileContent("public/blog/cool/cool2/index.html",
|
|
|
|
"Prev: |", "Next: /blog/cool/cool1/|")
|
|
|
|
|
|
|
|
}
|