2016-07-28 03:30:58 -04:00
|
|
|
package hugolib
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"os"
|
2016-09-21 08:09:41 -04:00
|
|
|
"path/filepath"
|
2017-05-30 09:38:10 -04:00
|
|
|
"time"
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
"github.com/gohugoio/hugo/resources/page"
|
|
|
|
|
2017-02-22 03:39:57 -05:00
|
|
|
"github.com/fortytw2/leaktest"
|
2016-07-28 03:30:58 -04:00
|
|
|
"github.com/fsnotify/fsnotify"
|
2017-06-13 12:42:45 -04:00
|
|
|
"github.com/gohugoio/hugo/helpers"
|
|
|
|
"github.com/gohugoio/hugo/hugofs"
|
2017-06-13 13:07:35 -04:00
|
|
|
"github.com/spf13/afero"
|
2016-08-04 14:41:30 -04:00
|
|
|
"github.com/stretchr/testify/require"
|
2016-07-28 03:30:58 -04:00
|
|
|
)
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
func TestMultiSitesMainLangInRoot(t *testing.T) {
|
|
|
|
t.Parallel()
|
2018-03-16 13:27:44 -04:00
|
|
|
for _, b := range []bool{false} {
|
2016-08-08 07:55:18 -04:00
|
|
|
doTestMultiSitesMainLangInRoot(t, b)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func doTestMultiSitesMainLangInRoot(t *testing.T, defaultInSubDir bool) {
|
2018-03-16 13:27:44 -04:00
|
|
|
assert := require.New(t)
|
2017-02-04 22:20:06 -05:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
siteConfig := map[string]interface{}{
|
|
|
|
"DefaultContentLanguage": "fr",
|
|
|
|
"DefaultContentLanguageInSubdir": defaultInSubDir,
|
|
|
|
}
|
2016-08-08 07:55:18 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
b := newMultiSiteTestBuilder(t, "toml", multiSiteTOMLConfigTemplate, siteConfig)
|
2016-08-08 07:55:18 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
pathMod := func(s string) string {
|
|
|
|
return s
|
|
|
|
}
|
2016-08-08 07:55:18 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
if !defaultInSubDir {
|
|
|
|
pathMod = func(s string) string {
|
|
|
|
return strings.Replace(s, "/fr/", "/", -1)
|
|
|
|
}
|
2016-08-08 07:55:18 -04:00
|
|
|
}
|
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
b.CreateSites()
|
|
|
|
b.Build(BuildCfg{})
|
2016-08-08 07:55:18 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
sites := b.H.Sites
|
2016-08-08 07:55:18 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
require.Len(t, sites, 4)
|
|
|
|
|
|
|
|
enSite := sites[0]
|
|
|
|
frSite := sites[1]
|
|
|
|
|
|
|
|
assert.Equal("/en", enSite.Info.LanguagePrefix)
|
2016-08-08 07:55:18 -04:00
|
|
|
|
|
|
|
if defaultInSubDir {
|
2018-03-16 13:27:44 -04:00
|
|
|
assert.Equal("/fr", frSite.Info.LanguagePrefix)
|
2016-08-08 07:55:18 -04:00
|
|
|
} else {
|
2018-03-16 13:27:44 -04:00
|
|
|
assert.Equal("", frSite.Info.LanguagePrefix)
|
2016-08-08 07:55:18 -04:00
|
|
|
}
|
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
assert.Equal("/blog/en/foo", enSite.PathSpec.RelURL("foo", true))
|
2016-11-07 15:16:55 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
doc1en := enSite.RegularPages()[0]
|
|
|
|
doc1fr := frSite.RegularPages()[0]
|
2016-08-08 07:55:18 -04:00
|
|
|
|
2016-11-15 04:43:49 -05:00
|
|
|
enPerm := doc1en.Permalink()
|
|
|
|
enRelPerm := doc1en.RelPermalink()
|
2018-03-16 13:27:44 -04:00
|
|
|
assert.Equal("http://example.com/blog/en/sect/doc1-slug/", enPerm)
|
|
|
|
assert.Equal("/blog/en/sect/doc1-slug/", enRelPerm)
|
2016-08-08 07:55:18 -04:00
|
|
|
|
2016-11-15 04:43:49 -05:00
|
|
|
frPerm := doc1fr.Permalink()
|
|
|
|
frRelPerm := doc1fr.RelPermalink()
|
2016-08-08 07:55:18 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent(pathMod("public/fr/sect/doc1/index.html"), "Single", "Bonjour")
|
|
|
|
b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Hello")
|
2016-08-08 07:55:18 -04:00
|
|
|
|
|
|
|
if defaultInSubDir {
|
2018-03-16 13:27:44 -04:00
|
|
|
assert.Equal("http://example.com/blog/fr/sect/doc1/", frPerm)
|
|
|
|
assert.Equal("/blog/fr/sect/doc1/", frRelPerm)
|
|
|
|
|
2016-08-08 07:55:18 -04:00
|
|
|
// should have a redirect on top level.
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/index.html", `<meta http-equiv="refresh" content="0; url=http://example.com/blog/fr" />`)
|
2016-09-09 11:40:56 -04:00
|
|
|
} else {
|
2018-03-16 13:27:44 -04:00
|
|
|
// Main language in root
|
|
|
|
assert.Equal("http://example.com/blog/sect/doc1/", frPerm)
|
|
|
|
assert.Equal("/blog/sect/doc1/", frRelPerm)
|
|
|
|
|
2016-09-09 11:40:56 -04:00
|
|
|
// should have redirect back to root
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/fr/index.html", `<meta http-equiv="refresh" content="0; url=http://example.com/blog" />`)
|
2016-08-08 07:55:18 -04:00
|
|
|
}
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent(pathMod("public/fr/index.html"), "Home", "Bonjour")
|
|
|
|
b.AssertFileContent("public/en/index.html", "Home", "Hello")
|
2016-08-08 07:55:18 -04:00
|
|
|
|
|
|
|
// Check list pages
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent(pathMod("public/fr/sect/index.html"), "List", "Bonjour")
|
|
|
|
b.AssertFileContent("public/en/sect/index.html", "List", "Hello")
|
2019-01-02 06:33:26 -05:00
|
|
|
b.AssertFileContent(pathMod("public/fr/plaques/FRtag1/index.html"), "Taxonomy List", "Bonjour")
|
2018-12-29 04:35:46 -05:00
|
|
|
b.AssertFileContent("public/en/tags/tag1/index.html", "Taxonomy List", "Hello")
|
2016-08-08 07:55:18 -04:00
|
|
|
|
|
|
|
// Check sitemaps
|
|
|
|
// Sitemaps behaves different: In a multilanguage setup there will always be a index file and
|
|
|
|
// one sitemap in each lang folder.
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/sitemap.xml",
|
2016-09-30 10:24:09 -04:00
|
|
|
"<loc>http://example.com/blog/en/sitemap.xml</loc>",
|
|
|
|
"<loc>http://example.com/blog/fr/sitemap.xml</loc>")
|
2016-08-08 07:55:18 -04:00
|
|
|
|
|
|
|
if defaultInSubDir {
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/fr/sitemap.xml", "<loc>http://example.com/blog/fr/</loc>")
|
2016-08-08 07:55:18 -04:00
|
|
|
} else {
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/fr/sitemap.xml", "<loc>http://example.com/blog/</loc>")
|
2016-08-08 07:55:18 -04:00
|
|
|
}
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/en/sitemap.xml", "<loc>http://example.com/blog/en/</loc>")
|
2016-08-08 07:55:18 -04:00
|
|
|
|
|
|
|
// Check rss
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent(pathMod("public/fr/index.xml"), pathMod(`<atom:link href="http://example.com/blog/fr/index.xml"`),
|
2017-03-25 05:14:12 -04:00
|
|
|
`rel="self" type="application/rss+xml"`)
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/en/index.xml", `<atom:link href="http://example.com/blog/en/index.xml"`)
|
|
|
|
b.AssertFileContent(
|
|
|
|
pathMod("public/fr/sect/index.xml"),
|
|
|
|
pathMod(`<atom:link href="http://example.com/blog/fr/sect/index.xml"`))
|
|
|
|
b.AssertFileContent("public/en/sect/index.xml", `<atom:link href="http://example.com/blog/en/sect/index.xml"`)
|
|
|
|
b.AssertFileContent(
|
2019-01-02 06:33:26 -05:00
|
|
|
pathMod("public/fr/plaques/FRtag1/index.xml"),
|
|
|
|
pathMod(`<atom:link href="http://example.com/blog/fr/plaques/FRtag1/index.xml"`))
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/en/tags/tag1/index.xml", `<atom:link href="http://example.com/blog/en/tags/tag1/index.xml"`)
|
2016-08-08 07:55:18 -04:00
|
|
|
|
|
|
|
// Check paginators
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent(pathMod("public/fr/page/1/index.html"), pathMod(`refresh" content="0; url=http://example.com/blog/fr/"`))
|
|
|
|
b.AssertFileContent("public/en/page/1/index.html", `refresh" content="0; url=http://example.com/blog/en/"`)
|
|
|
|
b.AssertFileContent(pathMod("public/fr/page/2/index.html"), "Home Page 2", "Bonjour", pathMod("http://example.com/blog/fr/"))
|
|
|
|
b.AssertFileContent("public/en/page/2/index.html", "Home Page 2", "Hello", "http://example.com/blog/en/")
|
|
|
|
b.AssertFileContent(pathMod("public/fr/sect/page/1/index.html"), pathMod(`refresh" content="0; url=http://example.com/blog/fr/sect/"`))
|
|
|
|
b.AssertFileContent("public/en/sect/page/1/index.html", `refresh" content="0; url=http://example.com/blog/en/sect/"`)
|
|
|
|
b.AssertFileContent(pathMod("public/fr/sect/page/2/index.html"), "List Page 2", "Bonjour", pathMod("http://example.com/blog/fr/sect/"))
|
|
|
|
b.AssertFileContent("public/en/sect/page/2/index.html", "List Page 2", "Hello", "http://example.com/blog/en/sect/")
|
|
|
|
b.AssertFileContent(
|
2019-01-02 06:33:26 -05:00
|
|
|
pathMod("public/fr/plaques/FRtag1/page/1/index.html"),
|
|
|
|
pathMod(`refresh" content="0; url=http://example.com/blog/fr/plaques/FRtag1/"`))
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/en/tags/tag1/page/1/index.html", `refresh" content="0; url=http://example.com/blog/en/tags/tag1/"`)
|
|
|
|
b.AssertFileContent(
|
2019-01-02 06:33:26 -05:00
|
|
|
pathMod("public/fr/plaques/FRtag1/page/2/index.html"), "List Page 2", "Bonjour",
|
|
|
|
pathMod("http://example.com/blog/fr/plaques/FRtag1/"))
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/en/tags/tag1/page/2/index.html", "List Page 2", "Hello", "http://example.com/blog/en/tags/tag1/")
|
2016-09-15 03:32:52 -04:00
|
|
|
// nn (Nynorsk) and nb (Bokmål) have custom pagePath: side ("page" in Norwegian)
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/nn/side/1/index.html", `refresh" content="0; url=http://example.com/blog/nn/"`)
|
|
|
|
b.AssertFileContent("public/nb/side/1/index.html", `refresh" content="0; url=http://example.com/blog/nb/"`)
|
2016-08-08 07:55:18 -04:00
|
|
|
}
|
|
|
|
|
2016-12-23 03:52:05 -05:00
|
|
|
func TestMultiSitesWithTwoLanguages(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
t.Parallel()
|
2018-01-30 11:51:18 -05:00
|
|
|
|
|
|
|
assert := require.New(t)
|
2018-03-17 14:24:02 -04:00
|
|
|
b := newTestSitesBuilder(t).WithConfigFile("toml", `
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
defaultContentLanguage = "nn"
|
2017-01-10 04:55:03 -05:00
|
|
|
|
2016-12-23 03:52:05 -05:00
|
|
|
[languages]
|
|
|
|
[languages.nn]
|
|
|
|
languageName = "Nynorsk"
|
|
|
|
weight = 1
|
|
|
|
title = "Tittel på Nynorsk"
|
2018-01-30 11:51:18 -05:00
|
|
|
[languages.nn.params]
|
|
|
|
p1 = "p1nn"
|
2016-12-23 03:52:05 -05:00
|
|
|
|
|
|
|
[languages.en]
|
|
|
|
title = "Title in English"
|
|
|
|
languageName = "English"
|
|
|
|
weight = 2
|
2018-01-30 11:51:18 -05:00
|
|
|
[languages.en.params]
|
|
|
|
p1 = "p1en"
|
2018-03-16 13:27:44 -04:00
|
|
|
`)
|
2016-12-23 03:52:05 -05:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
b.CreateSites()
|
|
|
|
b.Build(BuildCfg{SkipRender: true})
|
|
|
|
sites := b.H.Sites
|
2017-02-04 22:20:06 -05:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
assert.Len(sites, 2)
|
2016-12-23 03:52:05 -05:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
nnSite := sites[0]
|
2019-01-02 06:33:26 -05:00
|
|
|
nnHome := nnSite.getPage(page.KindHome)
|
2018-01-30 11:51:18 -05:00
|
|
|
assert.Len(nnHome.AllTranslations(), 2)
|
|
|
|
assert.Len(nnHome.Translations(), 1)
|
|
|
|
assert.True(nnHome.IsTranslated())
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
enHome := sites[1].getPage(page.KindHome)
|
2018-01-30 11:51:18 -05:00
|
|
|
|
|
|
|
p1, err := enHome.Param("p1")
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal("p1en", p1)
|
2016-12-23 03:52:05 -05:00
|
|
|
|
2018-01-30 11:51:18 -05:00
|
|
|
p1, err = nnHome.Param("p1")
|
|
|
|
assert.NoError(err)
|
|
|
|
assert.Equal("p1nn", p1)
|
2016-12-23 03:52:05 -05:00
|
|
|
}
|
|
|
|
|
2016-08-05 07:10:58 -04:00
|
|
|
func TestMultiSitesBuild(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
|
2016-08-10 16:46:02 -04:00
|
|
|
for _, config := range []struct {
|
|
|
|
content string
|
|
|
|
suffix string
|
|
|
|
}{
|
2016-09-21 08:09:41 -04:00
|
|
|
{multiSiteTOMLConfigTemplate, "toml"},
|
2017-02-04 22:20:06 -05:00
|
|
|
{multiSiteYAMLConfigTemplate, "yml"},
|
|
|
|
{multiSiteJSONConfigTemplate, "json"},
|
2016-08-10 16:46:02 -04:00
|
|
|
} {
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
t.Run(config.suffix, func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
doTestMultiSitesBuild(t, config.content, config.suffix)
|
|
|
|
})
|
2016-08-10 16:46:02 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-21 08:09:41 -04:00
|
|
|
func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
|
2018-03-16 13:27:44 -04:00
|
|
|
assert := require.New(t)
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
b := newMultiSiteTestBuilder(t, configSuffix, configTemplate, nil)
|
|
|
|
b.CreateSites()
|
2017-02-04 22:20:06 -05:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
sites := b.H.Sites
|
|
|
|
assert.Equal(4, len(sites))
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
b.Build(BuildCfg{})
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
// Check site config
|
2018-03-16 13:27:44 -04:00
|
|
|
for _, s := range sites {
|
2019-01-02 06:33:26 -05:00
|
|
|
require.True(t, s.Info.defaultContentLanguageInSubdir, s.Info.title)
|
2017-02-18 04:02:12 -05:00
|
|
|
require.NotNil(t, s.disabledKinds)
|
2017-02-04 22:20:06 -05:00
|
|
|
}
|
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
gp1 := b.H.GetContentPage(filepath.FromSlash("content/sect/doc1.en.md"))
|
2017-06-26 15:34:16 -04:00
|
|
|
require.NotNil(t, gp1)
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, "doc1", gp1.Title())
|
2018-03-16 13:27:44 -04:00
|
|
|
gp2 := b.H.GetContentPage(filepath.FromSlash("content/dummysect/notfound.md"))
|
2017-06-26 15:34:16 -04:00
|
|
|
require.Nil(t, gp2)
|
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
enSite := sites[0]
|
2019-01-02 06:33:26 -05:00
|
|
|
enSiteHome := enSite.getPage(page.KindHome)
|
2016-12-21 04:17:05 -05:00
|
|
|
require.True(t, enSiteHome.IsTranslated())
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, "en", enSite.language.Lang)
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.Equal(5, len(enSite.RegularPages()))
|
|
|
|
assert.Equal(32, len(enSite.AllPages()))
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// Check 404s
|
|
|
|
b.AssertFileContent("public/en/404.html", "404|en|404 Page not found")
|
|
|
|
b.AssertFileContent("public/fr/404.html", "404|fr|404 Page not found")
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// Check robots.txt
|
|
|
|
b.AssertFileContent("public/en/robots.txt", "robots|en|")
|
|
|
|
b.AssertFileContent("public/nn/robots.txt", "robots|nn|")
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Permalink: http://example.com/blog/en/sect/doc1-slug/")
|
|
|
|
b.AssertFileContent("public/en/sect/doc2/index.html", "Permalink: http://example.com/blog/en/sect/doc2/")
|
|
|
|
b.AssertFileContent("public/superbob/index.html", "Permalink: http://example.com/blog/superbob/")
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
doc2 := enSite.RegularPages()[1]
|
|
|
|
doc3 := enSite.RegularPages()[2]
|
|
|
|
require.Equal(t, doc2.Prev(), doc3, "doc3 should follow doc2, in .PrevPage")
|
|
|
|
doc1en := enSite.RegularPages()[0]
|
2016-07-28 03:30:58 -04:00
|
|
|
doc1fr := doc1en.Translations()[0]
|
2019-01-02 06:33:26 -05:00
|
|
|
b.AssertFileContent("public/fr/sect/doc1/index.html", "Permalink: http://example.com/blog/fr/sect/doc1/")
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
require.Equal(t, doc1en.Translations()[0], doc1fr, "doc1-en should have doc1-fr as translation")
|
|
|
|
require.Equal(t, doc1fr.Translations()[0], doc1en, "doc1-fr should have doc1-en as translation")
|
|
|
|
require.Equal(t, "fr", doc1fr.Language().Lang)
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
doc4 := enSite.AllPages()[4]
|
2017-02-04 22:20:06 -05:00
|
|
|
require.Len(t, doc4.Translations(), 0, "found translations for doc4")
|
2016-07-28 03:30:58 -04:00
|
|
|
|
|
|
|
// Taxonomies and their URLs
|
2017-02-04 22:20:06 -05:00
|
|
|
require.Len(t, enSite.Taxonomies, 1, "should have 1 taxonomy")
|
2016-07-28 03:30:58 -04:00
|
|
|
tags := enSite.Taxonomies["tags"]
|
2017-02-04 22:20:06 -05:00
|
|
|
require.Len(t, tags, 2, "should have 2 different tags")
|
|
|
|
require.Equal(t, tags["tag1"][0].Page, doc1en, "first tag1 page should be doc1")
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
frSite := sites[1]
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, "fr", frSite.language.Lang)
|
|
|
|
require.Len(t, frSite.RegularPages(), 4, "should have 3 pages")
|
|
|
|
require.Len(t, frSite.AllPages(), 32, "should have 32 total pages (including translations and nodes)")
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
for _, frenchPage := range frSite.RegularPages() {
|
|
|
|
p := frenchPage
|
|
|
|
require.Equal(t, "fr", p.Language().Lang)
|
2016-07-28 03:30:58 -04:00
|
|
|
}
|
|
|
|
|
2018-01-17 13:26:34 -05:00
|
|
|
// See https://github.com/gohugoio/hugo/issues/4285
|
|
|
|
// Before Hugo 0.33 you had to be explicit with the content path to get the correct Page, which
|
|
|
|
// isn't ideal in a multilingual setup. You want a way to get the current language version if available.
|
|
|
|
// Now you can do lookups with translation base name to get that behaviour.
|
|
|
|
// Let us test all the regular page variants:
|
2019-01-02 06:33:26 -05:00
|
|
|
getPageDoc1En := enSite.getPage(page.KindPage, filepath.ToSlash(doc1en.File().Path()))
|
|
|
|
getPageDoc1EnBase := enSite.getPage(page.KindPage, "sect/doc1")
|
|
|
|
getPageDoc1Fr := frSite.getPage(page.KindPage, filepath.ToSlash(doc1fr.File().Path()))
|
|
|
|
getPageDoc1FrBase := frSite.getPage(page.KindPage, "sect/doc1")
|
2018-01-17 13:26:34 -05:00
|
|
|
require.Equal(t, doc1en, getPageDoc1En)
|
|
|
|
require.Equal(t, doc1fr, getPageDoc1Fr)
|
|
|
|
require.Equal(t, doc1en, getPageDoc1EnBase)
|
|
|
|
require.Equal(t, doc1fr, getPageDoc1FrBase)
|
|
|
|
|
2016-08-04 16:12:19 -04:00
|
|
|
// Check redirect to main language, French
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/index.html", "0; url=http://example.com/blog/fr")
|
2016-08-04 14:41:30 -04:00
|
|
|
|
2016-08-11 12:26:45 -04:00
|
|
|
// check home page content (including data files rendering)
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/en/index.html", "Default Home Page 1", "Hello", "Hugo Rocks!")
|
|
|
|
b.AssertFileContent("public/fr/index.html", "French Home Page 1", "Bonjour", "Hugo Rocks!")
|
2016-08-11 12:26:45 -04:00
|
|
|
|
2016-08-12 12:17:00 -04:00
|
|
|
// check single page content
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/fr/sect/doc1/index.html", "Single", "Shortcode: Bonjour", "LingoFrench")
|
|
|
|
b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Shortcode: Hello", "LingoDefault")
|
2016-08-12 12:17:00 -04:00
|
|
|
|
2016-08-09 14:06:15 -04:00
|
|
|
// Check node translations
|
2019-01-02 06:33:26 -05:00
|
|
|
homeEn := enSite.getPage(page.KindHome)
|
2016-08-09 14:06:15 -04:00
|
|
|
require.NotNil(t, homeEn)
|
|
|
|
require.Len(t, homeEn.Translations(), 3)
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, "fr", homeEn.Translations()[0].Language().Lang)
|
|
|
|
require.Equal(t, "nn", homeEn.Translations()[1].Language().Lang)
|
|
|
|
require.Equal(t, "På nynorsk", homeEn.Translations()[1].Title())
|
|
|
|
require.Equal(t, "nb", homeEn.Translations()[2].Language().Lang)
|
|
|
|
require.Equal(t, "På bokmål", homeEn.Translations()[2].Title(), configSuffix)
|
2016-09-12 14:57:52 -04:00
|
|
|
require.Equal(t, "Bokmål", homeEn.Translations()[2].Language().LanguageName, configSuffix)
|
2016-08-09 14:06:15 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
sectFr := frSite.getPage(page.KindSection, "sect")
|
2016-08-09 14:06:15 -04:00
|
|
|
require.NotNil(t, sectFr)
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, "fr", sectFr.Language().Lang)
|
2016-08-09 14:06:15 -04:00
|
|
|
require.Len(t, sectFr.Translations(), 1)
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, "en", sectFr.Translations()[0].Language().Lang)
|
|
|
|
require.Equal(t, "Sects", sectFr.Translations()[0].Title())
|
2016-08-09 14:06:15 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
nnSite := sites[2]
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, "nn", nnSite.language.Lang)
|
|
|
|
taxNn := nnSite.getPage(page.KindTaxonomyTerm, "lag")
|
2016-08-09 14:06:15 -04:00
|
|
|
require.NotNil(t, taxNn)
|
|
|
|
require.Len(t, taxNn.Translations(), 1)
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, "nb", taxNn.Translations()[0].Language().Lang)
|
2016-08-09 14:06:15 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
taxTermNn := nnSite.getPage(page.KindTaxonomy, "lag", "sogndal")
|
2016-08-09 14:06:15 -04:00
|
|
|
require.NotNil(t, taxTermNn)
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, taxTermNn, nnSite.getPage(page.KindTaxonomy, "LAG", "SOGNDAL"))
|
2016-08-09 14:06:15 -04:00
|
|
|
require.Len(t, taxTermNn.Translations(), 1)
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, "nb", taxTermNn.Translations()[0].Language().Lang)
|
2016-08-09 14:06:15 -04:00
|
|
|
|
2016-08-04 16:12:19 -04:00
|
|
|
// Check sitemap(s)
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/sitemap.xml",
|
|
|
|
"<loc>http://example.com/blog/en/sitemap.xml</loc>",
|
|
|
|
"<loc>http://example.com/blog/fr/sitemap.xml</loc>")
|
|
|
|
b.AssertFileContent("public/en/sitemap.xml", "http://example.com/blog/en/sect/doc2/")
|
|
|
|
b.AssertFileContent("public/fr/sitemap.xml", "http://example.com/blog/fr/sect/doc1/")
|
2016-08-05 07:10:58 -04:00
|
|
|
|
|
|
|
// Check taxonomies
|
|
|
|
enTags := enSite.Taxonomies["tags"]
|
|
|
|
frTags := frSite.Taxonomies["plaques"]
|
2016-08-05 10:11:03 -04:00
|
|
|
require.Len(t, enTags, 2, fmt.Sprintf("Tags in en: %v", enTags))
|
|
|
|
require.Len(t, frTags, 2, fmt.Sprintf("Tags in fr: %v", frTags))
|
2016-08-05 07:10:58 -04:00
|
|
|
require.NotNil(t, enTags["tag1"])
|
2019-01-02 06:33:26 -05:00
|
|
|
require.NotNil(t, frTags["FRtag1"])
|
|
|
|
b.AssertFileContent("public/fr/plaques/FRtag1/index.html", "FRtag1|Bonjour|http://example.com/blog/fr/plaques/FRtag1/")
|
|
|
|
b.AssertFileContent("public/en/tags/tag1/index.html", "tag1|Hello|http://example.com/blog/en/tags/tag1/")
|
2016-08-07 08:03:03 -04:00
|
|
|
|
|
|
|
// Check Blackfriday config
|
2019-01-02 06:33:26 -05:00
|
|
|
require.True(t, strings.Contains(content(doc1fr), "«"), content(doc1fr))
|
|
|
|
require.False(t, strings.Contains(content(doc1en), "«"), content(doc1en))
|
|
|
|
require.True(t, strings.Contains(content(doc1en), "“"), content(doc1en))
|
2016-08-08 03:05:16 -04:00
|
|
|
|
2016-09-12 14:41:52 -04:00
|
|
|
// en and nn have custom site menus
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Len(t, frSite.Menus(), 0, "fr: "+configSuffix)
|
|
|
|
require.Len(t, enSite.Menus(), 1, "en: "+configSuffix)
|
|
|
|
require.Len(t, nnSite.Menus(), 1, "nn: "+configSuffix)
|
2016-09-12 14:41:52 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, "Home", enSite.Menus()["main"].ByName()[0].Name)
|
|
|
|
require.Equal(t, "Heim", nnSite.Menus()["main"].ByName()[0].Name)
|
2017-03-01 06:30:41 -05:00
|
|
|
|
2017-02-28 03:06:33 -05:00
|
|
|
// Issue #3108
|
2019-01-02 06:33:26 -05:00
|
|
|
prevPage := enSite.RegularPages()[0].Prev()
|
2018-09-24 18:06:29 -04:00
|
|
|
require.NotNil(t, prevPage)
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, page.KindPage, prevPage.Kind())
|
2017-02-28 03:06:33 -05:00
|
|
|
|
|
|
|
for {
|
2018-09-24 18:06:29 -04:00
|
|
|
if prevPage == nil {
|
2017-02-28 03:06:33 -05:00
|
|
|
break
|
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, page.KindPage, prevPage.Kind())
|
|
|
|
prevPage = prevPage.Prev()
|
2017-02-28 03:06:33 -05:00
|
|
|
}
|
|
|
|
|
2018-01-05 05:07:50 -05:00
|
|
|
// Check bundles
|
2019-01-02 06:33:26 -05:00
|
|
|
b.AssertFileContent("public/fr/bundles/b1/index.html", "RelPermalink: /blog/fr/bundles/b1/|")
|
|
|
|
bundleFr := frSite.getPage(page.KindPage, "bundles/b1/index.md")
|
2018-01-05 05:07:50 -05:00
|
|
|
require.NotNil(t, bundleFr)
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, 1, len(bundleFr.Resources()))
|
|
|
|
logoFr := bundleFr.Resources().GetMatch("logo*")
|
2018-01-05 05:07:50 -05:00
|
|
|
require.NotNil(t, logoFr)
|
2019-01-02 06:33:26 -05:00
|
|
|
b.AssertFileContent("public/fr/bundles/b1/index.html", "Resources: image/png: /blog/fr/bundles/b1/logo.png")
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/fr/bundles/b1/logo.png", "PNG Data")
|
2018-01-05 05:07:50 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
bundleEn := enSite.getPage(page.KindPage, "bundles/b1/index.en.md")
|
2018-01-05 05:07:50 -05:00
|
|
|
require.NotNil(t, bundleEn)
|
2019-01-02 06:33:26 -05:00
|
|
|
b.AssertFileContent("public/en/bundles/b1/index.html", "RelPermalink: /blog/en/bundles/b1/|")
|
|
|
|
require.Equal(t, 1, len(bundleEn.Resources()))
|
|
|
|
logoEn := bundleEn.Resources().GetMatch("logo*")
|
2018-01-05 05:07:50 -05:00
|
|
|
require.NotNil(t, logoEn)
|
2019-01-02 06:33:26 -05:00
|
|
|
b.AssertFileContent("public/en/bundles/b1/index.html", "Resources: image/png: /blog/en/bundles/b1/logo.png")
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/en/bundles/b1/logo.png", "PNG Data")
|
2018-01-05 05:07:50 -05:00
|
|
|
|
2016-07-28 03:30:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMultiSitesRebuild(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
// t.Parallel() not supported, see https://github.com/fortytw2/leaktest/issues/4
|
2017-06-13 15:22:47 -04:00
|
|
|
// This leaktest seems to be a little bit shaky on Travis.
|
|
|
|
if !isCI() {
|
2018-03-21 12:21:46 -04:00
|
|
|
defer leaktest.CheckTimeout(t, 10*time.Second)()
|
2017-06-13 15:22:47 -04:00
|
|
|
}
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
assert := require.New(t)
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
b := newMultiSiteTestDefaultBuilder(t).Running().CreateSites().Build(BuildCfg{})
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
sites := b.H.Sites
|
|
|
|
fs := b.Fs
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
b.AssertFileContent("public/en/sect/doc2/index.html", "Single: doc2|Hello|en|", "\n\n<h1 id=\"doc2\">doc2</h1>\n\n<p><em>some content</em>")
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
enSite := sites[0]
|
|
|
|
frSite := sites[1]
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.Len(enSite.RegularPages(), 5)
|
|
|
|
assert.Len(frSite.RegularPages(), 4)
|
2016-07-28 03:30:58 -04:00
|
|
|
|
|
|
|
// Verify translations
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Hello")
|
|
|
|
b.AssertFileContent("public/fr/sect/doc1/index.html", "Bonjour")
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2016-08-12 18:33:17 -04:00
|
|
|
// check single page content
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/fr/sect/doc1/index.html", "Single", "Shortcode: Bonjour")
|
|
|
|
b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Shortcode: Hello")
|
2016-08-12 18:33:17 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
homeEn := enSite.getPage(page.KindHome)
|
|
|
|
require.NotNil(t, homeEn)
|
|
|
|
assert.Len(homeEn.Translations(), 3)
|
|
|
|
|
Add Hugo Piper with SCSS support and much more
Before this commit, you would have to use page bundles to do image processing etc. in Hugo.
This commit adds
* A new `/assets` top-level project or theme dir (configurable via `assetDir`)
* A new template func, `resources.Get` which can be used to "get a resource" that can be further processed.
This means that you can now do this in your templates (or shortcodes):
```bash
{{ $sunset := (resources.Get "images/sunset.jpg").Fill "300x200" }}
```
This also adds a new `extended` build tag that enables powerful SCSS/SASS support with source maps. To compile this from source, you will also need a C compiler installed:
```
HUGO_BUILD_TAGS=extended mage install
```
Note that you can use output of the SCSS processing later in a non-SCSSS-enabled Hugo.
The `SCSS` processor is a _Resource transformation step_ and it can be chained with the many others in a pipeline:
```bash
{{ $css := resources.Get "styles.scss" | resources.ToCSS | resources.PostCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
The transformation funcs above have aliases, so it can be shortened to:
```bash
{{ $css := resources.Get "styles.scss" | toCSS | postCSS | minify | fingerprint }}
<link rel="stylesheet" href="{{ $styles.RelPermalink }}" integrity="{{ $styles.Data.Digest }}" media="screen">
```
A quick tip would be to avoid the fingerprinting part, and possibly also the not-superfast `postCSS` when you're doing development, as it allows Hugo to be smarter about the rebuilding.
Documentation will follow, but have a look at the demo repo in https://github.com/bep/hugo-sass-test
New functions to create `Resource` objects:
* `resources.Get` (see above)
* `resources.FromString`: Create a Resource from a string.
New `Resource` transformation funcs:
* `resources.ToCSS`: Compile `SCSS` or `SASS` into `CSS`.
* `resources.PostCSS`: Process your CSS with PostCSS. Config file support (project or theme or passed as an option).
* `resources.Minify`: Currently supports `css`, `js`, `json`, `html`, `svg`, `xml`.
* `resources.Fingerprint`: Creates a fingerprinted version of the given Resource with Subresource Integrity..
* `resources.Concat`: Concatenates a list of Resource objects. Think of this as a poor man's bundler.
* `resources.ExecuteAsTemplate`: Parses and executes the given Resource and data context (e.g. .Site) as a Go template.
Fixes #4381
Fixes #4903
Fixes #4858
2018-02-20 04:02:14 -05:00
|
|
|
contentFs := b.H.BaseFs.Content.Fs
|
2018-03-21 12:21:46 -04:00
|
|
|
|
2016-07-28 03:30:58 -04:00
|
|
|
for i, this := range []struct {
|
|
|
|
preFunc func(t *testing.T)
|
|
|
|
events []fsnotify.Event
|
|
|
|
assertFunc func(t *testing.T)
|
|
|
|
}{
|
|
|
|
// * Remove doc
|
|
|
|
// * Add docs existing languages
|
|
|
|
// (Add doc new language: TODO(bep) we should load config.toml as part of these so we can add languages).
|
|
|
|
// * Rename file
|
|
|
|
// * Change doc
|
|
|
|
// * Change a template
|
|
|
|
// * Change language file
|
|
|
|
{
|
: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(t *testing.T) {
|
|
|
|
fs.Source.Remove("content/sect/doc2.en.md")
|
|
|
|
},
|
|
|
|
[]fsnotify.Event{{Name: filepath.FromSlash("content/sect/doc2.en.md"), Op: fsnotify.Remove}},
|
2016-07-28 03:30:58 -04:00
|
|
|
func(t *testing.T) {
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.Len(enSite.RegularPages(), 4, "1 en removed")
|
2016-07-28 03:30:58 -04:00
|
|
|
|
|
|
|
// Check build stats
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, 1, enSite.buildStats.draftCount, "Draft")
|
|
|
|
require.Equal(t, 1, enSite.buildStats.futureCount, "Future")
|
|
|
|
require.Equal(t, 1, enSite.buildStats.expiredCount, "Expired")
|
|
|
|
require.Equal(t, 0, frSite.buildStats.draftCount, "Draft")
|
|
|
|
require.Equal(t, 1, frSite.buildStats.futureCount, "Future")
|
|
|
|
require.Equal(t, 1, frSite.buildStats.expiredCount, "Expired")
|
2016-07-28 03:30:58 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
func(t *testing.T) {
|
2018-03-21 12:21:46 -04:00
|
|
|
writeNewContentFile(t, contentFs, "new_en_1", "2016-07-31", "new1.en.md", -5)
|
|
|
|
writeNewContentFile(t, contentFs, "new_en_2", "1989-07-30", "new2.en.md", -10)
|
|
|
|
writeNewContentFile(t, contentFs, "new_fr_1", "2016-07-30", "new1.fr.md", 10)
|
2016-07-28 03:30:58 -04:00
|
|
|
},
|
|
|
|
[]fsnotify.Event{
|
: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
|
|
|
{Name: filepath.FromSlash("content/new1.en.md"), Op: fsnotify.Create},
|
|
|
|
{Name: filepath.FromSlash("content/new2.en.md"), Op: fsnotify.Create},
|
|
|
|
{Name: filepath.FromSlash("content/new1.fr.md"), Op: fsnotify.Create},
|
2016-07-28 03:30:58 -04:00
|
|
|
},
|
|
|
|
func(t *testing.T) {
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.Len(enSite.RegularPages(), 6)
|
|
|
|
assert.Len(enSite.AllPages(), 34)
|
|
|
|
assert.Len(frSite.RegularPages(), 5)
|
|
|
|
require.Equal(t, "new_fr_1", frSite.RegularPages()[3].Title())
|
|
|
|
require.Equal(t, "new_en_2", enSite.RegularPages()[0].Title())
|
|
|
|
require.Equal(t, "new_en_1", enSite.RegularPages()[1].Title())
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2017-01-10 04:55:03 -05:00
|
|
|
rendered := readDestination(t, fs, "public/en/new1/index.html")
|
2016-11-09 03:58:18 -05:00
|
|
|
require.True(t, strings.Contains(rendered, "new_en_1"), rendered)
|
2016-07-28 03:30:58 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
func(t *testing.T) {
|
2018-03-21 12:21:46 -04:00
|
|
|
p := "sect/doc1.en.md"
|
|
|
|
doc1 := readFileFromFs(t, contentFs, p)
|
2016-07-28 03:30:58 -04:00
|
|
|
doc1 += "CHANGED"
|
2018-03-21 12:21:46 -04:00
|
|
|
writeToFs(t, contentFs, p, doc1)
|
2016-07-28 03:30:58 -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
|
|
|
[]fsnotify.Event{{Name: filepath.FromSlash("content/sect/doc1.en.md"), Op: fsnotify.Write}},
|
2016-07-28 03:30:58 -04:00
|
|
|
func(t *testing.T) {
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.Len(enSite.RegularPages(), 6)
|
2017-01-10 04:55:03 -05:00
|
|
|
doc1 := readDestination(t, fs, "public/en/sect/doc1-slug/index.html")
|
2016-11-09 03:58:18 -05:00
|
|
|
require.True(t, strings.Contains(doc1, "CHANGED"), doc1)
|
2016-07-28 03:30:58 -04:00
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// Rename a file
|
|
|
|
{
|
|
|
|
func(t *testing.T) {
|
2018-03-21 12:21:46 -04:00
|
|
|
if err := contentFs.Rename("new1.en.md", "new1renamed.en.md"); err != nil {
|
2016-07-28 03:30:58 -04:00
|
|
|
t.Fatalf("Rename failed: %s", err)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[]fsnotify.Event{
|
: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
|
|
|
{Name: filepath.FromSlash("content/new1renamed.en.md"), Op: fsnotify.Rename},
|
|
|
|
{Name: filepath.FromSlash("content/new1.en.md"), Op: fsnotify.Rename},
|
2016-07-28 03:30:58 -04:00
|
|
|
},
|
|
|
|
func(t *testing.T) {
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.Len(enSite.RegularPages(), 6, "Rename")
|
|
|
|
require.Equal(t, "new_en_1", enSite.RegularPages()[1].Title())
|
2017-01-10 04:55:03 -05:00
|
|
|
rendered := readDestination(t, fs, "public/en/new1renamed/index.html")
|
2016-11-09 03:58:18 -05:00
|
|
|
require.True(t, strings.Contains(rendered, "new_en_1"), rendered)
|
2016-07-28 03:30:58 -04:00
|
|
|
}},
|
|
|
|
{
|
|
|
|
// Change a template
|
|
|
|
func(t *testing.T) {
|
|
|
|
template := "layouts/_default/single.html"
|
2017-01-10 04:55:03 -05:00
|
|
|
templateContent := readSource(t, fs, template)
|
2016-07-28 03:30:58 -04:00
|
|
|
templateContent += "{{ print \"Template Changed\"}}"
|
2017-01-10 04:55:03 -05:00
|
|
|
writeSource(t, fs, template, templateContent)
|
2016-07-28 03:30:58 -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
|
|
|
[]fsnotify.Event{{Name: filepath.FromSlash("layouts/_default/single.html"), Op: fsnotify.Write}},
|
2016-07-28 03:30:58 -04:00
|
|
|
func(t *testing.T) {
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.Len(enSite.RegularPages(), 6)
|
|
|
|
assert.Len(enSite.AllPages(), 34)
|
|
|
|
assert.Len(frSite.RegularPages(), 5)
|
2017-01-10 04:55:03 -05:00
|
|
|
doc1 := readDestination(t, fs, "public/en/sect/doc1-slug/index.html")
|
2016-11-09 03:58:18 -05:00
|
|
|
require.True(t, strings.Contains(doc1, "Template Changed"), doc1)
|
2016-07-28 03:30:58 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
// Change a language file
|
|
|
|
func(t *testing.T) {
|
|
|
|
languageFile := "i18n/fr.yaml"
|
2017-01-10 04:55:03 -05:00
|
|
|
langContent := readSource(t, fs, languageFile)
|
2016-07-28 03:30:58 -04:00
|
|
|
langContent = strings.Replace(langContent, "Bonjour", "Salut", 1)
|
2017-01-10 04:55:03 -05:00
|
|
|
writeSource(t, fs, languageFile, langContent)
|
2016-07-28 03:30:58 -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
|
|
|
[]fsnotify.Event{{Name: filepath.FromSlash("i18n/fr.yaml"), Op: fsnotify.Write}},
|
2016-07-28 03:30:58 -04:00
|
|
|
func(t *testing.T) {
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.Len(enSite.RegularPages(), 6)
|
|
|
|
assert.Len(enSite.AllPages(), 34)
|
|
|
|
assert.Len(frSite.RegularPages(), 5)
|
2017-01-10 04:55:03 -05:00
|
|
|
docEn := readDestination(t, fs, "public/en/sect/doc1-slug/index.html")
|
2016-11-09 03:58:18 -05:00
|
|
|
require.True(t, strings.Contains(docEn, "Hello"), "No Hello")
|
2017-01-10 04:55:03 -05:00
|
|
|
docFr := readDestination(t, fs, "public/fr/sect/doc1/index.html")
|
2016-11-09 03:58:18 -05:00
|
|
|
require.True(t, strings.Contains(docFr, "Salut"), "No Salut")
|
2016-08-09 14:06:15 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
homeEn := enSite.getPage(page.KindHome)
|
2016-08-09 14:06:15 -04:00
|
|
|
require.NotNil(t, homeEn)
|
2018-03-16 13:27:44 -04:00
|
|
|
assert.Len(homeEn.Translations(), 3)
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, "fr", homeEn.Translations()[0].Language().Lang)
|
2016-08-09 14:06:15 -04:00
|
|
|
|
2016-07-28 03:30:58 -04:00
|
|
|
},
|
|
|
|
},
|
2016-08-12 18:33:17 -04:00
|
|
|
// Change a shortcode
|
|
|
|
{
|
|
|
|
func(t *testing.T) {
|
2017-01-10 04:55:03 -05:00
|
|
|
writeSource(t, fs, "layouts/shortcodes/shortcode.html", "Modified Shortcode: {{ i18n \"hello\" }}")
|
2016-08-12 18:33:17 -04:00
|
|
|
},
|
|
|
|
[]fsnotify.Event{
|
: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
|
|
|
{Name: filepath.FromSlash("layouts/shortcodes/shortcode.html"), Op: fsnotify.Write},
|
2016-08-12 18:33:17 -04:00
|
|
|
},
|
|
|
|
func(t *testing.T) {
|
2019-01-02 06:33:26 -05:00
|
|
|
assert.Len(enSite.RegularPages(), 6)
|
|
|
|
assert.Len(enSite.AllPages(), 34)
|
|
|
|
assert.Len(frSite.RegularPages(), 5)
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/fr/sect/doc1/index.html", "Single", "Modified Shortcode: Salut")
|
|
|
|
b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Modified Shortcode: Hello")
|
2016-08-12 18:33:17 -04:00
|
|
|
},
|
|
|
|
},
|
2016-07-28 03:30:58 -04:00
|
|
|
} {
|
|
|
|
|
|
|
|
if this.preFunc != nil {
|
|
|
|
this.preFunc(t)
|
|
|
|
}
|
2016-11-10 14:55:52 -05:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
err := b.H.Build(BuildCfg{}, this.events...)
|
2016-07-28 03:30:58 -04:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("[%d] Failed to rebuild sites: %s", i, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
this.assertFunc(t)
|
|
|
|
}
|
2016-08-08 03:05:16 -04:00
|
|
|
|
2016-08-06 08:51:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestAddNewLanguage(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
t.Parallel()
|
2018-03-16 13:27:44 -04:00
|
|
|
assert := require.New(t)
|
2016-08-06 08:51:50 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
b := newMultiSiteTestDefaultBuilder(t)
|
|
|
|
b.CreateSites().Build(BuildCfg{})
|
2016-08-06 08:51:50 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
fs := b.Fs
|
2017-02-04 22:20:06 -05:00
|
|
|
|
2016-09-21 08:09:41 -04:00
|
|
|
newConfig := multiSiteTOMLConfigTemplate + `
|
2016-08-06 08:51:50 -04:00
|
|
|
|
2016-08-09 14:06:15 -04:00
|
|
|
[Languages.sv]
|
2016-08-06 08:51:50 -04:00
|
|
|
weight = 15
|
2016-08-09 14:06:15 -04:00
|
|
|
title = "Svenska"
|
2016-08-06 08:51:50 -04:00
|
|
|
`
|
|
|
|
|
2018-03-21 12:21:46 -04:00
|
|
|
writeNewContentFile(t, fs.Source, "Swedish Contentfile", "2016-01-01", "content/sect/doc1.sv.md", 10)
|
2016-08-06 08:51:50 -04:00
|
|
|
// replace the config
|
2018-03-16 13:27:44 -04:00
|
|
|
b.WithNewConfig(newConfig)
|
|
|
|
|
|
|
|
sites := b.H
|
2016-08-06 08:51:50 -04:00
|
|
|
|
2018-11-15 03:28:02 -05:00
|
|
|
assert.NoError(b.LoadConfig())
|
|
|
|
err := b.H.Build(BuildCfg{NewConfig: b.Cfg})
|
2016-08-06 08:51:50 -04:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to rebuild sites: %s", err)
|
|
|
|
}
|
|
|
|
|
2016-08-09 14:06:15 -04:00
|
|
|
require.Len(t, sites.Sites, 5, fmt.Sprintf("Len %d", len(sites.Sites)))
|
2016-08-06 08:51:50 -04:00
|
|
|
|
2016-08-09 14:06:15 -04:00
|
|
|
// The Swedish site should be put in the middle (language weight=15)
|
2016-08-06 08:51:50 -04:00
|
|
|
enSite := sites.Sites[0]
|
2016-08-09 14:06:15 -04:00
|
|
|
svSite := sites.Sites[1]
|
2016-08-06 08:51:50 -04:00
|
|
|
frSite := sites.Sites[2]
|
2019-01-02 06:33:26 -05:00
|
|
|
require.True(t, enSite.language.Lang == "en", enSite.language.Lang)
|
|
|
|
require.True(t, svSite.language.Lang == "sv", svSite.language.Lang)
|
|
|
|
require.True(t, frSite.language.Lang == "fr", frSite.language.Lang)
|
2016-08-06 08:51:50 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
homeEn := enSite.getPage(page.KindHome)
|
2016-08-09 14:06:15 -04:00
|
|
|
require.NotNil(t, homeEn)
|
|
|
|
require.Len(t, homeEn.Translations(), 4)
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, "sv", homeEn.Translations()[0].Language().Lang)
|
|
|
|
|
|
|
|
require.Len(t, enSite.RegularPages(), 5)
|
|
|
|
require.Len(t, frSite.RegularPages(), 4)
|
2016-08-06 08:51:50 -04:00
|
|
|
|
2016-08-09 14:06:15 -04:00
|
|
|
// Veriy Swedish site
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Len(t, svSite.RegularPages(), 1)
|
|
|
|
svPage := svSite.RegularPages()[0]
|
2018-01-17 13:26:34 -05:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, "Swedish Contentfile", svPage.Title())
|
|
|
|
require.Equal(t, "sv", svPage.Language().Lang)
|
2016-08-09 14:06:15 -04:00
|
|
|
require.Len(t, svPage.Translations(), 2)
|
|
|
|
require.Len(t, svPage.AllTranslations(), 3)
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Equal(t, "en", svPage.Translations()[0].Language().Lang)
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2017-02-17 11:26:09 -05:00
|
|
|
// Regular pages have no children
|
2019-01-02 06:33:26 -05:00
|
|
|
require.Len(t, svPage.Pages(), 0)
|
|
|
|
require.Len(t, svPage.Data().(page.Data).Pages(), 0)
|
2017-02-17 11:26:09 -05:00
|
|
|
|
2016-07-28 03:30:58 -04:00
|
|
|
}
|
|
|
|
|
2016-09-21 08:09:41 -04:00
|
|
|
func TestChangeDefaultLanguage(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
t.Parallel()
|
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
assert := require.New(t)
|
2016-09-21 08:09:41 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
b := newMultiSiteTestBuilder(t, "", "", map[string]interface{}{
|
|
|
|
"DefaultContentLanguage": "fr",
|
|
|
|
"DefaultContentLanguageInSubdir": false,
|
|
|
|
})
|
|
|
|
b.CreateSites().Build(BuildCfg{})
|
2017-02-04 22:20:06 -05:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/sect/doc1/index.html", "Single", "Bonjour")
|
|
|
|
b.AssertFileContent("public/en/sect/doc2/index.html", "Single", "Hello")
|
2016-09-21 08:09:41 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
// Switch language
|
|
|
|
b.WithNewConfigData(map[string]interface{}{
|
|
|
|
"DefaultContentLanguage": "en",
|
|
|
|
"DefaultContentLanguageInSubdir": false,
|
|
|
|
})
|
2016-09-21 08:09:41 -04:00
|
|
|
|
2018-11-15 03:28:02 -05:00
|
|
|
assert.NoError(b.LoadConfig())
|
|
|
|
err := b.H.Build(BuildCfg{NewConfig: b.Cfg})
|
|
|
|
|
2016-09-21 08:09:41 -04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to rebuild sites: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Default language is now en, so that should now be the "root" language
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/fr/sect/doc1/index.html", "Single", "Bonjour")
|
|
|
|
b.AssertFileContent("public/sect/doc2/index.html", "Single", "Hello")
|
2016-09-21 08:09:41 -04:00
|
|
|
}
|
|
|
|
|
2018-05-08 04:10:13 -04:00
|
|
|
// https://github.com/gohugoio/hugo/issues/4706
|
|
|
|
func TestContentStressTest(t *testing.T) {
|
|
|
|
b := newTestSitesBuilder(t)
|
|
|
|
|
|
|
|
numPages := 500
|
|
|
|
|
|
|
|
contentTempl := `
|
|
|
|
---
|
|
|
|
%s
|
|
|
|
title: %q
|
|
|
|
weight: %d
|
|
|
|
multioutput: %t
|
|
|
|
---
|
|
|
|
|
|
|
|
# Header
|
|
|
|
|
|
|
|
CONTENT
|
|
|
|
|
|
|
|
The End.
|
|
|
|
`
|
|
|
|
|
|
|
|
contentTempl = strings.Replace(contentTempl, "CONTENT", strings.Repeat(`
|
|
|
|
|
|
|
|
## Another header
|
|
|
|
|
|
|
|
Some text. Some more text.
|
|
|
|
|
|
|
|
`, 100), -1)
|
|
|
|
|
|
|
|
var content []string
|
|
|
|
defaultOutputs := `outputs: ["html", "json", "rss" ]`
|
|
|
|
|
|
|
|
for i := 1; i <= numPages; i++ {
|
|
|
|
outputs := defaultOutputs
|
|
|
|
multioutput := true
|
|
|
|
if i%3 == 0 {
|
|
|
|
outputs = `outputs: ["json"]`
|
|
|
|
multioutput = false
|
|
|
|
}
|
|
|
|
section := "s1"
|
|
|
|
if i%10 == 0 {
|
|
|
|
section = "s2"
|
|
|
|
}
|
|
|
|
content = append(content, []string{fmt.Sprintf("%s/page%d.md", section, i), fmt.Sprintf(contentTempl, outputs, fmt.Sprintf("Title %d", i), i, multioutput)}...)
|
|
|
|
}
|
|
|
|
|
|
|
|
content = append(content, []string{"_index.md", fmt.Sprintf(contentTempl, defaultOutputs, fmt.Sprintf("Home %d", 0), 0, true)}...)
|
|
|
|
content = append(content, []string{"s1/_index.md", fmt.Sprintf(contentTempl, defaultOutputs, fmt.Sprintf("S %d", 1), 1, true)}...)
|
|
|
|
content = append(content, []string{"s2/_index.md", fmt.Sprintf(contentTempl, defaultOutputs, fmt.Sprintf("S %d", 2), 2, true)}...)
|
|
|
|
|
|
|
|
b.WithSimpleConfigFile()
|
2019-01-02 06:33:26 -05:00
|
|
|
b.WithTemplates("layouts/_default/single.html", `Single: {{ .Content }}|RelPermalink: {{ .RelPermalink }}|Permalink: {{ .Permalink }}`)
|
2018-05-08 04:10:13 -04:00
|
|
|
b.WithTemplates("layouts/_default/myview.html", `View: {{ len .Content }}`)
|
2019-01-02 06:33:26 -05:00
|
|
|
b.WithTemplates("layouts/_default/single.json", `Single JSON: {{ .Content }}|RelPermalink: {{ .RelPermalink }}|Permalink: {{ .Permalink }}`)
|
2018-05-08 04:10:13 -04:00
|
|
|
b.WithTemplates("layouts/_default/list.html", `
|
|
|
|
Page: {{ .Paginator.PageNumber }}
|
2019-01-02 06:33:26 -05:00
|
|
|
P: {{ with .File }}{{ path.Join .Path }}{{ end }}
|
2018-05-08 04:10:13 -04:00
|
|
|
List: {{ len .Paginator.Pages }}|List Content: {{ len .Content }}
|
|
|
|
{{ $shuffled := where .Site.RegularPages "Params.multioutput" true | shuffle }}
|
|
|
|
{{ $first5 := $shuffled | first 5 }}
|
|
|
|
L1: {{ len .Site.RegularPages }} L2: {{ len $first5 }}
|
|
|
|
{{ range $i, $e := $first5 }}
|
|
|
|
Render {{ $i }}: {{ .Render "myview" }}
|
|
|
|
{{ end }}
|
|
|
|
END
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent(content...)
|
|
|
|
|
|
|
|
b.CreateSites().Build(BuildCfg{})
|
|
|
|
|
|
|
|
contentMatchers := []string{"<h2 id=\"another-header\">Another header</h2>", "<h2 id=\"another-header-99\">Another header</h2>", "<p>The End.</p>"}
|
|
|
|
|
|
|
|
for i := 1; i <= numPages; i++ {
|
|
|
|
if i%3 != 0 {
|
|
|
|
section := "s1"
|
|
|
|
if i%10 == 0 {
|
|
|
|
section = "s2"
|
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
checkContent(b, fmt.Sprintf("public/%s/page%d/index.html", section, i), contentMatchers...)
|
2018-05-08 04:10:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 1; i <= numPages; i++ {
|
|
|
|
section := "s1"
|
|
|
|
if i%10 == 0 {
|
|
|
|
section = "s2"
|
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
checkContent(b, fmt.Sprintf("public/%s/page%d/index.json", section, i), contentMatchers...)
|
2018-05-08 04:10:13 -04:00
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
checkContent(b, "public/s1/index.html", "P: s1/_index.md\nList: 10|List Content: 8335\n\n\nL1: 500 L2: 5\n\nRender 0: View: 8335\n\nRender 1: View: 8335\n\nRender 2: View: 8335\n\nRender 3: View: 8335\n\nRender 4: View: 8335\n\nEND\n")
|
|
|
|
checkContent(b, "public/s2/index.html", "P: s2/_index.md\nList: 10|List Content: 8335", "Render 4: View: 8335\n\nEND")
|
|
|
|
checkContent(b, "public/index.html", "P: _index.md\nList: 10|List Content: 8335", "4: View: 8335\n\nEND")
|
2018-05-08 04:10:13 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// Check paginated pages
|
2018-05-08 04:10:13 -04:00
|
|
|
for i := 2; i <= 9; i++ {
|
2019-01-02 06:33:26 -05:00
|
|
|
checkContent(b, fmt.Sprintf("public/page/%d/index.html", i), fmt.Sprintf("Page: %d", i), "Content: 8335\n\n\nL1: 500 L2: 5\n\nRender 0: View: 8335", "Render 4: View: 8335\n\nEND")
|
2018-05-08 04:10:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
func checkContent(s *sitesBuilder, filename string, matches ...string) {
|
2018-05-08 04:10:13 -04:00
|
|
|
content := readDestination(s.T, s.Fs, filename)
|
|
|
|
for _, match := range matches {
|
|
|
|
if !strings.Contains(content, match) {
|
|
|
|
s.Fatalf("No match for %q in content for %s\n%q", match, filename, content)
|
|
|
|
}
|
|
|
|
}
|
2019-01-02 06:33:26 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTranslationsFromContentToNonContent(t *testing.T) {
|
|
|
|
b := newTestSitesBuilder(t)
|
|
|
|
b.WithConfigFile("toml", `
|
|
|
|
|
|
|
|
baseURL = "http://example.com/"
|
|
|
|
|
|
|
|
defaultContentLanguage = "en"
|
|
|
|
|
|
|
|
[languages]
|
|
|
|
[languages.en]
|
|
|
|
weight = 10
|
|
|
|
contentDir = "content/en"
|
|
|
|
[languages.nn]
|
|
|
|
weight = 20
|
|
|
|
contentDir = "content/nn"
|
|
|
|
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("en/mysection/_index.md", `
|
|
|
|
---
|
|
|
|
Title: My Section
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("en/_index.md", `
|
|
|
|
---
|
|
|
|
Title: My Home
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("en/categories/mycat/_index.md", `
|
|
|
|
---
|
|
|
|
Title: My MyCat
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
b.WithContent("en/categories/_index.md", `
|
|
|
|
---
|
|
|
|
Title: My categories
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
for _, lang := range []string{"en", "nn"} {
|
|
|
|
|
|
|
|
b.WithContent(lang+"/mysection/page.md", `
|
|
|
|
---
|
|
|
|
Title: My Page
|
|
|
|
categories: ["mycat"]
|
|
|
|
---
|
|
|
|
|
|
|
|
`)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
b.Build(BuildCfg{})
|
|
|
|
|
|
|
|
for _, path := range []string{
|
|
|
|
"/",
|
|
|
|
"/mysection",
|
|
|
|
"/categories",
|
|
|
|
"/categories/mycat",
|
|
|
|
} {
|
|
|
|
|
|
|
|
t.Run(path, func(t *testing.T) {
|
|
|
|
assert := require.New(t)
|
|
|
|
|
|
|
|
s1, _ := b.H.Sites[0].getPageNew(nil, path)
|
|
|
|
s2, _ := b.H.Sites[1].getPageNew(nil, path)
|
|
|
|
|
|
|
|
assert.NotNil(s1)
|
|
|
|
assert.NotNil(s2)
|
|
|
|
|
|
|
|
assert.Equal(1, len(s1.Translations()))
|
|
|
|
assert.Equal(1, len(s2.Translations()))
|
|
|
|
assert.Equal(s2, s1.Translations()[0])
|
|
|
|
assert.Equal(s1, s2.Translations()[0])
|
|
|
|
|
|
|
|
m1 := s1.Translations().MergeByLanguage(s2.Translations())
|
|
|
|
m2 := s2.Translations().MergeByLanguage(s1.Translations())
|
|
|
|
|
|
|
|
assert.Equal(1, len(m1))
|
|
|
|
assert.Equal(1, len(m2))
|
|
|
|
})
|
|
|
|
|
2018-05-08 04:10:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
// https://github.com/gohugoio/hugo/issues/5777
|
2016-10-24 08:40:57 -04:00
|
|
|
func TestTableOfContentsInShortcodes(t *testing.T) {
|
2017-02-04 22:20:06 -05:00
|
|
|
t.Parallel()
|
2016-10-24 08:40:57 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
b := newMultiSiteTestDefaultBuilder(t)
|
2016-10-24 08:40:57 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
b.WithTemplatesAdded("layouts/shortcodes/toc.html", tocShortcode)
|
2019-01-02 06:33:26 -05:00
|
|
|
b.WithTemplatesAdded("layouts/shortcodes/wrapper.html", "{{ .Inner }}")
|
2018-03-16 13:27:44 -04:00
|
|
|
b.WithContent("post/simple.en.md", tocPageSimple)
|
2019-01-02 06:33:26 -05:00
|
|
|
b.WithContent("post/variants1.en.md", tocPageVariants1)
|
|
|
|
b.WithContent("post/variants2.en.md", tocPageVariants2)
|
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
b.WithContent("post/withSCInHeading.en.md", tocPageWithShortcodesInHeadings)
|
2016-10-24 08:40:57 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
b.CreateSites().Build(BuildCfg{})
|
2016-10-24 08:40:57 -04:00
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
b.AssertFileContent("public/en/post/simple/index.html",
|
|
|
|
tocPageSimpleExpected,
|
|
|
|
// Make sure it is inserted twice
|
|
|
|
`TOC1: <nav id="TableOfContents">`,
|
|
|
|
`TOC2: <nav id="TableOfContents">`,
|
|
|
|
)
|
|
|
|
|
|
|
|
b.AssertFileContentFn("public/en/post/variants1/index.html", func(s string) bool {
|
|
|
|
return strings.Count(s, "TableOfContents") == 4
|
|
|
|
})
|
|
|
|
b.AssertFileContentFn("public/en/post/variants2/index.html", func(s string) bool {
|
|
|
|
return strings.Count(s, "TableOfContents") == 6
|
|
|
|
})
|
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
b.AssertFileContent("public/en/post/withSCInHeading/index.html", tocPageWithShortcodesInHeadingsExpected)
|
2016-10-24 08:40:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var tocShortcode = `
|
2019-01-02 06:33:26 -05:00
|
|
|
TOC1: {{ .Page.TableOfContents }}
|
|
|
|
|
|
|
|
TOC2: {{ .Page.TableOfContents }}
|
2016-10-24 08:40:57 -04:00
|
|
|
`
|
|
|
|
|
2018-04-19 12:06:40 -04:00
|
|
|
func TestSelfReferencedContentInShortcode(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
b := newMultiSiteTestDefaultBuilder(t)
|
|
|
|
|
|
|
|
var (
|
|
|
|
shortcode = `{{- .Page.Content -}}{{- .Page.Summary -}}{{- .Page.Plain -}}{{- .Page.PlainWords -}}{{- .Page.WordCount -}}{{- .Page.ReadingTime -}}`
|
|
|
|
|
|
|
|
page = `---
|
|
|
|
title: sctest
|
|
|
|
---
|
|
|
|
Empty:{{< mycontent >}}:
|
|
|
|
`
|
|
|
|
)
|
|
|
|
|
|
|
|
b.WithTemplatesAdded("layouts/shortcodes/mycontent.html", shortcode)
|
|
|
|
b.WithContent("post/simple.en.md", page)
|
|
|
|
|
|
|
|
b.CreateSites().Build(BuildCfg{})
|
|
|
|
|
|
|
|
b.AssertFileContent("public/en/post/simple/index.html", "Empty:[]00:")
|
|
|
|
}
|
|
|
|
|
2016-10-24 08:40:57 -04:00
|
|
|
var tocPageSimple = `---
|
|
|
|
title: tocTest
|
|
|
|
publishdate: "2000-01-01"
|
|
|
|
---
|
|
|
|
{{< toc >}}
|
|
|
|
# Heading 1 {#1}
|
|
|
|
Some text.
|
|
|
|
## Subheading 1.1 {#1-1}
|
|
|
|
Some more text.
|
|
|
|
# Heading 2 {#2}
|
|
|
|
Even more text.
|
|
|
|
## Subheading 2.1 {#2-1}
|
|
|
|
Lorem ipsum...
|
|
|
|
`
|
|
|
|
|
2019-01-02 06:33:26 -05:00
|
|
|
var tocPageVariants1 = `---
|
|
|
|
title: tocTest
|
|
|
|
publishdate: "2000-01-01"
|
|
|
|
---
|
|
|
|
Variant 1:
|
|
|
|
{{% wrapper %}}
|
|
|
|
{{< toc >}}
|
|
|
|
{{% /wrapper %}}
|
|
|
|
# Heading 1
|
|
|
|
|
|
|
|
Variant 3:
|
|
|
|
{{% toc %}}
|
|
|
|
|
|
|
|
`
|
|
|
|
|
|
|
|
var tocPageVariants2 = `---
|
|
|
|
title: tocTest
|
|
|
|
publishdate: "2000-01-01"
|
|
|
|
---
|
|
|
|
Variant 1:
|
|
|
|
{{% wrapper %}}
|
|
|
|
{{< toc >}}
|
|
|
|
{{% /wrapper %}}
|
|
|
|
# Heading 1
|
|
|
|
|
|
|
|
Variant 2:
|
|
|
|
{{< wrapper >}}
|
|
|
|
{{< toc >}}
|
|
|
|
{{< /wrapper >}}
|
|
|
|
|
|
|
|
Variant 3:
|
|
|
|
{{% toc %}}
|
|
|
|
|
|
|
|
`
|
|
|
|
|
2016-10-24 08:40:57 -04:00
|
|
|
var tocPageSimpleExpected = `<nav id="TableOfContents">
|
|
|
|
<ul>
|
|
|
|
<li><a href="#1">Heading 1</a>
|
|
|
|
<ul>
|
|
|
|
<li><a href="#1-1">Subheading 1.1</a></li>
|
|
|
|
</ul></li>
|
|
|
|
<li><a href="#2">Heading 2</a>
|
|
|
|
<ul>
|
|
|
|
<li><a href="#2-1">Subheading 2.1</a></li>
|
|
|
|
</ul></li>
|
|
|
|
</ul>
|
|
|
|
</nav>`
|
|
|
|
|
|
|
|
var tocPageWithShortcodesInHeadings = `---
|
|
|
|
title: tocTest
|
|
|
|
publishdate: "2000-01-01"
|
|
|
|
---
|
|
|
|
|
|
|
|
{{< toc >}}
|
|
|
|
|
|
|
|
# Heading 1 {#1}
|
|
|
|
|
|
|
|
Some text.
|
|
|
|
|
|
|
|
## Subheading 1.1 {{< shortcode >}} {#1-1}
|
|
|
|
|
|
|
|
Some more text.
|
|
|
|
|
|
|
|
# Heading 2 {{% shortcode %}} {#2}
|
|
|
|
|
|
|
|
Even more text.
|
|
|
|
|
|
|
|
## Subheading 2.1 {#2-1}
|
|
|
|
|
|
|
|
Lorem ipsum...
|
|
|
|
`
|
|
|
|
|
|
|
|
var tocPageWithShortcodesInHeadingsExpected = `<nav id="TableOfContents">
|
|
|
|
<ul>
|
|
|
|
<li><a href="#1">Heading 1</a>
|
|
|
|
<ul>
|
|
|
|
<li><a href="#1-1">Subheading 1.1 Shortcode: Hello</a></li>
|
|
|
|
</ul></li>
|
|
|
|
<li><a href="#2">Heading 2 Shortcode: Hello</a>
|
|
|
|
<ul>
|
|
|
|
<li><a href="#2-1">Subheading 2.1</a></li>
|
|
|
|
</ul></li>
|
|
|
|
</ul>
|
|
|
|
</nav>`
|
|
|
|
|
2016-09-21 08:09:41 -04:00
|
|
|
var multiSiteTOMLConfigTemplate = `
|
2016-10-24 14:56:00 -04:00
|
|
|
baseURL = "http://example.com/blog"
|
2016-08-06 08:51:50 -04:00
|
|
|
|
2016-08-08 07:55:18 -04:00
|
|
|
paginate = 1
|
2017-03-09 13:19:29 -05:00
|
|
|
disablePathToLower = true
|
2016-10-24 14:56:00 -04:00
|
|
|
defaultContentLanguage = "{{ .DefaultContentLanguage }}"
|
2017-02-04 22:20:06 -05:00
|
|
|
defaultContentLanguageInSubdir = {{ .DefaultContentLanguageInSubdir }}
|
2019-01-02 06:33:26 -05:00
|
|
|
enableRobotsTXT = true
|
2016-08-06 08:51:50 -04:00
|
|
|
|
|
|
|
[permalinks]
|
2016-08-07 08:03:03 -04:00
|
|
|
other = "/somewhere/else/:filename"
|
|
|
|
|
|
|
|
[blackfriday]
|
|
|
|
angledQuotes = true
|
2016-08-06 08:51:50 -04:00
|
|
|
|
|
|
|
[Taxonomies]
|
|
|
|
tag = "tags"
|
|
|
|
|
|
|
|
[Languages]
|
|
|
|
[Languages.en]
|
|
|
|
weight = 10
|
2016-09-12 14:57:52 -04:00
|
|
|
title = "In English"
|
|
|
|
languageName = "English"
|
2016-08-07 08:03:03 -04:00
|
|
|
[Languages.en.blackfriday]
|
|
|
|
angledQuotes = false
|
2016-09-12 14:41:52 -04:00
|
|
|
[[Languages.en.menu.main]]
|
|
|
|
url = "/"
|
|
|
|
name = "Home"
|
|
|
|
weight = 0
|
2016-08-06 08:51:50 -04:00
|
|
|
|
|
|
|
[Languages.fr]
|
|
|
|
weight = 20
|
2016-09-12 14:57:52 -04:00
|
|
|
title = "Le Français"
|
|
|
|
languageName = "Français"
|
2016-08-06 08:51:50 -04:00
|
|
|
[Languages.fr.Taxonomies]
|
|
|
|
plaque = "plaques"
|
2016-08-09 14:06:15 -04:00
|
|
|
|
|
|
|
[Languages.nn]
|
|
|
|
weight = 30
|
2016-09-12 14:57:52 -04:00
|
|
|
title = "På nynorsk"
|
|
|
|
languageName = "Nynorsk"
|
2016-09-15 03:32:52 -04:00
|
|
|
paginatePath = "side"
|
2016-08-09 14:06:15 -04:00
|
|
|
[Languages.nn.Taxonomies]
|
|
|
|
lag = "lag"
|
2016-09-12 14:41:52 -04:00
|
|
|
[[Languages.nn.menu.main]]
|
|
|
|
url = "/"
|
|
|
|
name = "Heim"
|
|
|
|
weight = 1
|
2016-08-09 14:06:15 -04:00
|
|
|
|
|
|
|
[Languages.nb]
|
|
|
|
weight = 40
|
2016-09-12 14:57:52 -04:00
|
|
|
title = "På bokmål"
|
|
|
|
languageName = "Bokmål"
|
2016-09-15 03:32:52 -04:00
|
|
|
paginatePath = "side"
|
2016-08-09 14:06:15 -04:00
|
|
|
[Languages.nb.Taxonomies]
|
|
|
|
lag = "lag"
|
2016-08-06 08:51:50 -04:00
|
|
|
`
|
|
|
|
|
2017-02-04 22:20:06 -05:00
|
|
|
var multiSiteYAMLConfigTemplate = `
|
2016-10-24 14:56:00 -04:00
|
|
|
baseURL: "http://example.com/blog"
|
2016-08-10 16:46:02 -04:00
|
|
|
|
2017-03-09 13:19:29 -05:00
|
|
|
disablePathToLower: true
|
2016-08-10 16:46:02 -04:00
|
|
|
paginate: 1
|
2017-02-04 22:20:06 -05:00
|
|
|
defaultContentLanguage: "{{ .DefaultContentLanguage }}"
|
|
|
|
defaultContentLanguageInSubdir: {{ .DefaultContentLanguageInSubdir }}
|
2019-01-02 06:33:26 -05:00
|
|
|
enableRobotsTXT: true
|
2016-08-10 16:46:02 -04:00
|
|
|
|
|
|
|
permalinks:
|
|
|
|
other: "/somewhere/else/:filename"
|
|
|
|
|
|
|
|
blackfriday:
|
|
|
|
angledQuotes: true
|
|
|
|
|
|
|
|
Taxonomies:
|
|
|
|
tag: "tags"
|
|
|
|
|
|
|
|
Languages:
|
|
|
|
en:
|
|
|
|
weight: 10
|
2016-09-12 14:57:52 -04:00
|
|
|
title: "In English"
|
|
|
|
languageName: "English"
|
2016-08-10 16:46:02 -04:00
|
|
|
blackfriday:
|
|
|
|
angledQuotes: false
|
2016-09-12 14:41:52 -04:00
|
|
|
menu:
|
|
|
|
main:
|
|
|
|
- url: "/"
|
|
|
|
name: "Home"
|
|
|
|
weight: 0
|
2016-08-10 16:46:02 -04:00
|
|
|
fr:
|
|
|
|
weight: 20
|
2016-09-12 14:57:52 -04:00
|
|
|
title: "Le Français"
|
|
|
|
languageName: "Français"
|
2016-08-10 16:46:02 -04:00
|
|
|
Taxonomies:
|
|
|
|
plaque: "plaques"
|
|
|
|
nn:
|
|
|
|
weight: 30
|
2016-09-12 14:57:52 -04:00
|
|
|
title: "På nynorsk"
|
|
|
|
languageName: "Nynorsk"
|
2016-09-15 03:32:52 -04:00
|
|
|
paginatePath: "side"
|
2016-08-10 16:46:02 -04:00
|
|
|
Taxonomies:
|
|
|
|
lag: "lag"
|
2016-09-12 14:41:52 -04:00
|
|
|
menu:
|
|
|
|
main:
|
|
|
|
- url: "/"
|
|
|
|
name: "Heim"
|
|
|
|
weight: 1
|
2016-08-10 16:46:02 -04:00
|
|
|
nb:
|
|
|
|
weight: 40
|
2016-09-12 14:57:52 -04:00
|
|
|
title: "På bokmål"
|
|
|
|
languageName: "Bokmål"
|
2016-09-15 03:32:52 -04:00
|
|
|
paginatePath: "side"
|
2016-08-10 16:46:02 -04:00
|
|
|
Taxonomies:
|
|
|
|
lag: "lag"
|
|
|
|
|
|
|
|
`
|
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
// TODO(bep) clean move
|
2017-02-04 22:20:06 -05:00
|
|
|
var multiSiteJSONConfigTemplate = `
|
2016-08-10 17:57:10 -04:00
|
|
|
{
|
2016-10-24 14:56:00 -04:00
|
|
|
"baseURL": "http://example.com/blog",
|
2016-08-10 17:57:10 -04:00
|
|
|
"paginate": 1,
|
2017-03-09 13:19:29 -05:00
|
|
|
"disablePathToLower": true,
|
2017-02-04 22:20:06 -05:00
|
|
|
"defaultContentLanguage": "{{ .DefaultContentLanguage }}",
|
|
|
|
"defaultContentLanguageInSubdir": true,
|
2019-01-02 06:33:26 -05:00
|
|
|
"enableRobotsTXT": true,
|
2016-08-10 17:57:10 -04:00
|
|
|
"permalinks": {
|
|
|
|
"other": "/somewhere/else/:filename"
|
|
|
|
},
|
|
|
|
"blackfriday": {
|
|
|
|
"angledQuotes": true
|
|
|
|
},
|
|
|
|
"Taxonomies": {
|
|
|
|
"tag": "tags"
|
|
|
|
},
|
|
|
|
"Languages": {
|
|
|
|
"en": {
|
|
|
|
"weight": 10,
|
2016-09-12 14:57:52 -04:00
|
|
|
"title": "In English",
|
|
|
|
"languageName": "English",
|
2016-08-10 17:57:10 -04:00
|
|
|
"blackfriday": {
|
|
|
|
"angledQuotes": false
|
2016-09-12 14:41:52 -04:00
|
|
|
},
|
|
|
|
"menu": {
|
|
|
|
"main": [
|
|
|
|
{
|
|
|
|
"url": "/",
|
|
|
|
"name": "Home",
|
|
|
|
"weight": 0
|
|
|
|
}
|
|
|
|
]
|
2016-08-10 17:57:10 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"fr": {
|
|
|
|
"weight": 20,
|
2016-09-12 14:57:52 -04:00
|
|
|
"title": "Le Français",
|
|
|
|
"languageName": "Français",
|
2016-08-10 17:57:10 -04:00
|
|
|
"Taxonomies": {
|
|
|
|
"plaque": "plaques"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"nn": {
|
|
|
|
"weight": 30,
|
2016-09-12 14:57:52 -04:00
|
|
|
"title": "På nynorsk",
|
2016-09-15 03:32:52 -04:00
|
|
|
"paginatePath": "side",
|
2016-09-12 14:57:52 -04:00
|
|
|
"languageName": "Nynorsk",
|
2016-08-10 17:57:10 -04:00
|
|
|
"Taxonomies": {
|
|
|
|
"lag": "lag"
|
2016-09-12 14:41:52 -04:00
|
|
|
},
|
|
|
|
"menu": {
|
|
|
|
"main": [
|
|
|
|
{
|
|
|
|
"url": "/",
|
|
|
|
"name": "Heim",
|
|
|
|
"weight": 1
|
|
|
|
}
|
|
|
|
]
|
2016-08-10 17:57:10 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"nb": {
|
|
|
|
"weight": 40,
|
2016-09-12 14:57:52 -04:00
|
|
|
"title": "På bokmål",
|
2016-09-15 03:32:52 -04:00
|
|
|
"paginatePath": "side",
|
2016-09-12 14:57:52 -04:00
|
|
|
"languageName": "Bokmål",
|
2016-08-10 17:57:10 -04:00
|
|
|
"Taxonomies": {
|
|
|
|
"lag": "lag"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
func writeSource(t testing.TB, fs *hugofs.Fs, filename, content string) {
|
|
|
|
writeToFs(t, fs.Source, filename, content)
|
2016-08-10 16:46:02 -04:00
|
|
|
}
|
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
func writeToFs(t testing.TB, fs afero.Fs, filename, content string) {
|
|
|
|
if err := afero.WriteFile(fs, filepath.FromSlash(filename), []byte(content), 0755); err != nil {
|
|
|
|
t.Fatalf("Failed to write file: %s", err)
|
|
|
|
}
|
|
|
|
}
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
func readDestination(t testing.TB, fs *hugofs.Fs, filename string) string {
|
|
|
|
return readFileFromFs(t, fs.Destination, filename)
|
|
|
|
}
|
2017-02-04 22:20:06 -05:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
func destinationExists(fs *hugofs.Fs, filename string) bool {
|
|
|
|
b, err := helpers.Exists(filename, fs.Destination)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
2016-07-28 03:30:58 -04:00
|
|
|
}
|
2018-03-16 13:27:44 -04:00
|
|
|
return b
|
|
|
|
}
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
func readSource(t *testing.T, fs *hugofs.Fs, filename string) string {
|
|
|
|
return readFileFromFs(t, fs.Source, filename)
|
|
|
|
}
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
func readFileFromFs(t testing.TB, fs afero.Fs, filename string) string {
|
|
|
|
filename = filepath.Clean(filename)
|
|
|
|
b, err := afero.ReadFile(fs, filename)
|
|
|
|
if err != nil {
|
|
|
|
// Print some debug info
|
2019-01-02 06:33:26 -05:00
|
|
|
hadSlash := strings.HasPrefix(filename, helpers.FilePathSeparator)
|
|
|
|
start := 0
|
|
|
|
if hadSlash {
|
|
|
|
start = 1
|
|
|
|
}
|
|
|
|
end := start + 1
|
|
|
|
|
|
|
|
parts := strings.Split(filename, helpers.FilePathSeparator)
|
|
|
|
if parts[start] == "work" {
|
|
|
|
end++
|
|
|
|
}
|
|
|
|
|
|
|
|
root := filepath.Join(parts[start:end]...)
|
|
|
|
if hadSlash {
|
|
|
|
root = helpers.FilePathSeparator + root
|
|
|
|
}
|
|
|
|
|
Add support for theme composition and inheritance
This commit adds support for theme composition and inheritance in Hugo.
With this, it helps thinking about a theme as a set of ordered components:
```toml
theme = ["my-shortcodes", "base-theme", "hyde"]
```
The theme definition example above in `config.toml` creates a theme with the 3 components with presedence from left to right.
So, Hugo will, for any given file, data entry etc., look first in the project, and then in `my-shortcode`, `base-theme` and lastly `hyde`.
Hugo uses two different algorithms to merge the filesystems, depending on the file type:
* For `i18n` and `data` files, Hugo merges deeply using the translation id and data key inside the files.
* For `static`, `layouts` (templates) and `archetypes` files, these are merged on file level. So the left-most file will be chosen.
The name used in the `theme` definition above must match a folder in `/your-site/themes`, e.g. `/your-site/themes/my-shortcodes`. There are plans to improve on this and get a URL scheme so this can be resolved automatically.
Also note that a component that is part of a theme can have its own configuration file, e.g. `config.toml`. There are currently some restrictions to what a theme component can configure:
* `params` (global and per language)
* `menu` (global and per language)
* `outputformats` and `mediatypes`
The same rules apply here: The left-most param/menu etc. with the same ID will win. There are some hidden and experimental namespace support in the above, which we will work to improve in the future, but theme authors are encouraged to create their own namespaces to avoid naming conflicts.
A final note: Themes/components can also have a `theme` definition in their `config.toml` and similar, which is the "inheritance" part of this commit's title. This is currently not supported by the Hugo theme site. We will have to wait for some "auto dependency" feature to be implemented for that to happen, but this can be a powerful feature if you want to create your own theme-variant based on others.
Fixes #4460
Fixes #4450
2018-03-01 09:01:25 -05:00
|
|
|
helpers.PrintFs(fs, root, os.Stdout)
|
2018-03-16 13:27:44 -04:00
|
|
|
Fatalf(t, "Failed to read file: %s", err)
|
2016-07-28 03:30:58 -04:00
|
|
|
}
|
2018-03-16 13:27:44 -04:00
|
|
|
return string(b)
|
|
|
|
}
|
2016-07-28 03:30:58 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
const testPageTemplate = `---
|
|
|
|
title: "%s"
|
|
|
|
publishdate: "%s"
|
|
|
|
weight: %d
|
|
|
|
---
|
|
|
|
# Doc %s
|
|
|
|
`
|
2016-08-12 12:17:00 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
func newTestPage(title, date string, weight int) string {
|
|
|
|
return fmt.Sprintf(testPageTemplate, title, date, weight, title)
|
|
|
|
}
|
|
|
|
|
2018-03-21 12:21:46 -04:00
|
|
|
func writeNewContentFile(t *testing.T, fs afero.Fs, title, date, filename string, weight int) {
|
2018-03-16 13:27:44 -04:00
|
|
|
content := newTestPage(title, date, weight)
|
2018-03-21 12:21:46 -04:00
|
|
|
writeToFs(t, fs, filename, content)
|
2018-03-16 13:27:44 -04:00
|
|
|
}
|
2017-07-02 04:46:28 -04:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
type multiSiteTestBuilder struct {
|
|
|
|
configData interface{}
|
|
|
|
config string
|
|
|
|
configFormat string
|
|
|
|
|
|
|
|
*sitesBuilder
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMultiSiteTestDefaultBuilder(t testing.TB) *multiSiteTestBuilder {
|
|
|
|
return newMultiSiteTestBuilder(t, "", "", nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *multiSiteTestBuilder) WithNewConfig(config string) *multiSiteTestBuilder {
|
|
|
|
b.WithConfigTemplate(b.configData, b.configFormat, config)
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b *multiSiteTestBuilder) WithNewConfigData(data interface{}) *multiSiteTestBuilder {
|
|
|
|
b.WithConfigTemplate(data, b.configFormat, b.config)
|
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func newMultiSiteTestBuilder(t testing.TB, configFormat, config string, configData interface{}) *multiSiteTestBuilder {
|
|
|
|
if configData == nil {
|
|
|
|
configData = map[string]interface{}{
|
|
|
|
"DefaultContentLanguage": "fr",
|
|
|
|
"DefaultContentLanguageInSubdir": true,
|
|
|
|
}
|
2017-07-02 04:46:28 -04:00
|
|
|
}
|
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
if config == "" {
|
|
|
|
config = multiSiteTOMLConfigTemplate
|
2016-07-28 03:30:58 -04:00
|
|
|
}
|
2018-03-16 13:27:44 -04:00
|
|
|
|
|
|
|
if configFormat == "" {
|
|
|
|
configFormat = "toml"
|
2016-07-28 03:30:58 -04:00
|
|
|
}
|
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
b := newTestSitesBuilder(t).WithConfigTemplate(configData, configFormat, config)
|
|
|
|
b.WithContent("root.en.md", `---
|
2016-11-09 05:09:16 -05:00
|
|
|
title: root
|
|
|
|
weight: 10000
|
|
|
|
slug: root
|
|
|
|
publishdate: "2000-01-01"
|
|
|
|
---
|
|
|
|
# root
|
2018-03-16 13:27:44 -04:00
|
|
|
`,
|
|
|
|
"sect/doc1.en.md", `---
|
2016-07-28 03:30:58 -04:00
|
|
|
title: doc1
|
2016-11-06 09:38:52 -05:00
|
|
|
weight: 1
|
2016-07-28 03:30:58 -04:00
|
|
|
slug: doc1-slug
|
|
|
|
tags:
|
|
|
|
- tag1
|
|
|
|
publishdate: "2000-01-01"
|
|
|
|
---
|
|
|
|
# doc1
|
2016-08-07 08:03:03 -04:00
|
|
|
*some "content"*
|
2016-08-12 12:17:00 -04:00
|
|
|
|
|
|
|
{{< shortcode >}}
|
|
|
|
|
2017-07-02 04:46:28 -04:00
|
|
|
{{< lingo >}}
|
|
|
|
|
2016-07-28 03:30:58 -04:00
|
|
|
NOTE: slug should be used as URL
|
2018-03-16 13:27:44 -04:00
|
|
|
`,
|
|
|
|
"sect/doc1.fr.md", `---
|
2016-07-28 03:30:58 -04:00
|
|
|
title: doc1
|
2016-11-06 09:38:52 -05:00
|
|
|
weight: 1
|
2016-08-05 07:10:58 -04:00
|
|
|
plaques:
|
2019-01-02 06:33:26 -05:00
|
|
|
- FRtag1
|
|
|
|
- FRtag2
|
2016-07-28 03:30:58 -04:00
|
|
|
publishdate: "2000-01-04"
|
|
|
|
---
|
|
|
|
# doc1
|
2016-08-07 08:03:03 -04:00
|
|
|
*quelque "contenu"*
|
2016-08-12 12:17:00 -04:00
|
|
|
|
|
|
|
{{< shortcode >}}
|
|
|
|
|
2017-07-02 04:46:28 -04:00
|
|
|
{{< lingo >}}
|
|
|
|
|
2016-07-28 03:30:58 -04:00
|
|
|
NOTE: should be in the 'en' Page's 'Translations' field.
|
|
|
|
NOTE: date is after "doc3"
|
2018-03-16 13:27:44 -04:00
|
|
|
`,
|
|
|
|
"sect/doc2.en.md", `---
|
2016-07-28 03:30:58 -04:00
|
|
|
title: doc2
|
2016-11-06 09:38:52 -05:00
|
|
|
weight: 2
|
2016-07-28 03:30:58 -04:00
|
|
|
publishdate: "2000-01-02"
|
|
|
|
---
|
|
|
|
# doc2
|
|
|
|
*some content*
|
|
|
|
NOTE: without slug, "doc2" should be used, without ".en" as URL
|
2018-03-16 13:27:44 -04:00
|
|
|
`,
|
|
|
|
"sect/doc3.en.md", `---
|
2016-07-28 03:30:58 -04:00
|
|
|
title: doc3
|
2016-11-06 09:38:52 -05:00
|
|
|
weight: 3
|
2016-07-28 03:30:58 -04:00
|
|
|
publishdate: "2000-01-03"
|
2017-11-20 04:34:30 -05:00
|
|
|
aliases: [/en/al/alias1,/al/alias2/]
|
2016-07-28 03:30:58 -04:00
|
|
|
tags:
|
|
|
|
- tag2
|
2016-08-08 07:55:18 -04:00
|
|
|
- tag1
|
2019-01-02 06:33:26 -05:00
|
|
|
url: /superbob/
|
2016-07-28 03:30:58 -04:00
|
|
|
---
|
|
|
|
# doc3
|
|
|
|
*some content*
|
|
|
|
NOTE: third 'en' doc, should trigger pagination on home page.
|
2018-03-16 13:27:44 -04:00
|
|
|
`,
|
|
|
|
"sect/doc4.md", `---
|
2016-07-28 03:30:58 -04:00
|
|
|
title: doc4
|
2016-11-06 09:38:52 -05:00
|
|
|
weight: 4
|
2016-08-05 07:10:58 -04:00
|
|
|
plaques:
|
2019-01-02 06:33:26 -05:00
|
|
|
- FRtag1
|
2016-07-28 03:30:58 -04:00
|
|
|
publishdate: "2000-01-05"
|
|
|
|
---
|
|
|
|
# doc4
|
|
|
|
*du contenu francophone*
|
2016-10-24 14:56:00 -04:00
|
|
|
NOTE: should use the defaultContentLanguage and mark this doc as 'fr'.
|
2016-07-28 03:30:58 -04:00
|
|
|
NOTE: doesn't have any corresponding translation in 'en'
|
2018-03-16 13:27:44 -04:00
|
|
|
`,
|
|
|
|
"other/doc5.fr.md", `---
|
2016-07-28 03:30:58 -04:00
|
|
|
title: doc5
|
2016-11-06 09:38:52 -05:00
|
|
|
weight: 5
|
2016-07-28 03:30:58 -04:00
|
|
|
publishdate: "2000-01-06"
|
|
|
|
---
|
|
|
|
# doc5
|
|
|
|
*autre contenu francophone*
|
|
|
|
NOTE: should use the "permalinks" configuration with :filename
|
2018-03-16 13:27:44 -04:00
|
|
|
`,
|
2016-07-28 03:30:58 -04:00
|
|
|
// Add some for the stats
|
2018-03-16 13:27:44 -04:00
|
|
|
"stats/expired.fr.md", `---
|
2016-07-28 03:30:58 -04:00
|
|
|
title: expired
|
|
|
|
publishdate: "2000-01-06"
|
|
|
|
expiryDate: "2001-01-06"
|
|
|
|
---
|
|
|
|
# Expired
|
2018-03-16 13:27:44 -04:00
|
|
|
`,
|
|
|
|
"stats/future.fr.md", `---
|
2016-07-28 03:30:58 -04:00
|
|
|
title: future
|
2016-11-06 09:38:52 -05:00
|
|
|
weight: 6
|
2016-07-28 03:30:58 -04:00
|
|
|
publishdate: "2100-01-06"
|
|
|
|
---
|
|
|
|
# Future
|
2018-03-16 13:27:44 -04:00
|
|
|
`,
|
|
|
|
"stats/expired.en.md", `---
|
2016-07-28 03:30:58 -04:00
|
|
|
title: expired
|
2016-11-06 09:38:52 -05:00
|
|
|
weight: 7
|
2016-07-28 03:30:58 -04:00
|
|
|
publishdate: "2000-01-06"
|
|
|
|
expiryDate: "2001-01-06"
|
|
|
|
---
|
|
|
|
# Expired
|
2018-03-16 13:27:44 -04:00
|
|
|
`,
|
|
|
|
"stats/future.en.md", `---
|
2016-07-28 03:30:58 -04:00
|
|
|
title: future
|
2016-11-06 09:38:52 -05:00
|
|
|
weight: 6
|
2016-07-28 03:30:58 -04:00
|
|
|
publishdate: "2100-01-06"
|
|
|
|
---
|
|
|
|
# Future
|
2018-03-16 13:27:44 -04:00
|
|
|
`,
|
|
|
|
"stats/draft.en.md", `---
|
2016-07-28 03:30:58 -04:00
|
|
|
title: expired
|
|
|
|
publishdate: "2000-01-06"
|
|
|
|
draft: true
|
|
|
|
---
|
|
|
|
# Draft
|
2018-03-16 13:27:44 -04:00
|
|
|
`,
|
|
|
|
"stats/tax.nn.md", `---
|
2016-08-09 14:06:15 -04:00
|
|
|
title: Tax NN
|
2016-11-06 09:38:52 -05:00
|
|
|
weight: 8
|
2016-08-09 14:06:15 -04:00
|
|
|
publishdate: "2000-01-06"
|
|
|
|
weight: 1001
|
|
|
|
lag:
|
|
|
|
- Sogndal
|
|
|
|
---
|
|
|
|
# Tax NN
|
2018-03-16 13:27:44 -04:00
|
|
|
`,
|
|
|
|
"stats/tax.nb.md", `---
|
2016-08-09 14:06:15 -04:00
|
|
|
title: Tax NB
|
2016-11-06 09:38:52 -05:00
|
|
|
weight: 8
|
2016-08-09 14:06:15 -04:00
|
|
|
publishdate: "2000-01-06"
|
|
|
|
weight: 1002
|
|
|
|
lag:
|
|
|
|
- Sogndal
|
|
|
|
---
|
|
|
|
# Tax NB
|
2018-03-16 13:27:44 -04:00
|
|
|
`,
|
2018-01-05 05:07:50 -05:00
|
|
|
// Bundle
|
2018-03-16 13:27:44 -04:00
|
|
|
"bundles/b1/index.en.md", `---
|
2018-01-05 05:07:50 -05:00
|
|
|
title: Bundle EN
|
|
|
|
publishdate: "2000-01-06"
|
|
|
|
weight: 2001
|
|
|
|
---
|
|
|
|
# Bundle Content EN
|
2018-03-16 13:27:44 -04:00
|
|
|
`,
|
|
|
|
"bundles/b1/index.md", `---
|
2018-01-05 05:07:50 -05:00
|
|
|
title: Bundle Default
|
|
|
|
publishdate: "2000-01-06"
|
|
|
|
weight: 2002
|
|
|
|
---
|
|
|
|
# Bundle Content Default
|
2018-03-16 13:27:44 -04:00
|
|
|
`,
|
|
|
|
"bundles/b1/logo.png", `
|
2018-01-05 05:07:50 -05:00
|
|
|
PNG Data
|
2018-03-16 13:27:44 -04:00
|
|
|
`)
|
2017-02-04 22:20:06 -05:00
|
|
|
|
2018-03-16 13:27:44 -04:00
|
|
|
return &multiSiteTestBuilder{sitesBuilder: b, configFormat: configFormat, config: config, configData: configData}
|
2016-09-21 08:09:41 -04:00
|
|
|
}
|