summaryrefslogtreecommitdiffstats
path: root/hugolib/hugo_sites_build_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-12-24 19:11:05 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2024-01-27 16:28:14 +0100
commit7285e74090852b5d52f25e577850fa75f4aa8573 (patch)
tree54d07cb4a7de2db5c89f2590266595f0aca6cbd6 /hugolib/hugo_sites_build_test.go
parent5fd1e7490305570872d3899f5edda950903c5213 (diff)
all: Rework page store, add a dynacache, improve partial rebuilds, and some general spring cleaningdevelop2024
There are some breaking changes in this commit, see #11455. Closes #11455 Closes #11549 This fixes a set of bugs (see issue list) and it is also paying some technical debt accumulated over the years. We now build with Staticcheck enabled in the CI build. The performance should be about the same as before for regular sized Hugo sites, but it should perform and scale much better to larger data sets, as objects that uses lots of memory (e.g. rendered Markdown, big JSON files read into maps with transform.Unmarshal etc.) will now get automatically garbage collected if needed. Performance on partial rebuilds when running the server in fast render mode should be the same, but the change detection should be much more accurate. A list of the notable new features: * A new dependency tracker that covers (almost) all of Hugo's API and is used to do fine grained partial rebuilds when running the server. * A new and simpler tree document store which allows fast lookups and prefix-walking in all dimensions (e.g. language) concurrently. * You can now configure an upper memory limit allowing for much larger data sets and/or running on lower specced PCs. We have lifted the "no resources in sub folders" restriction for branch bundles (e.g. sections). Memory Limit * Hugos will, by default, set aside a quarter of the total system memory, but you can set this via the OS environment variable HUGO_MEMORYLIMIT (in gigabytes). This is backed by a partitioned LRU cache used throughout Hugo. A cache that gets dynamically resized in low memory situations, allowing Go's Garbage Collector to free the memory. New Dependency Tracker: Hugo has had a rule based coarse grained approach to server rebuilds that has worked mostly pretty well, but there have been some surprises (e.g. stale content). This is now revamped with a new dependency tracker that can quickly calculate the delta given a changed resource (e.g. a content file, template, JS file etc.). This handles transitive relations, e.g. $page -> js.Build -> JS import, or $page1.Content -> render hook -> site.GetPage -> $page2.Title, or $page1.Content -> shortcode -> partial -> site.RegularPages -> $page2.Content -> shortcode ..., and should also handle changes to aggregated values (e.g. site.Lastmod) effectively. This covers all of Hugo's API with 2 known exceptions (a list that may not be fully exhaustive): Changes to files loaded with template func os.ReadFile may not be handled correctly. We recommend loading resources with resources.Get Changes to Hugo objects (e.g. Page) passed in the template context to lang.Translate may not be detected correctly. We recommend having simple i18n templates without too much data context passed in other than simple types such as strings and numbers. Note that the cachebuster configuration (when A changes then rebuild B) works well with the above, but we recommend that you revise that configuration, as it in most situations should not be needed. One example where it is still needed is with TailwindCSS and using changes to hugo_stats.json to trigger new CSS rebuilds. Document Store: Previously, a little simplified, we split the document store (where we store pages and resources) in a tree per language. This worked pretty well, but the structure made some operations harder than they needed to be. We have now restructured it into one Radix tree for all languages. Internally the language is considered to be a dimension of that tree, and the tree can be viewed in all dimensions concurrently. This makes some operations re. language simpler (e.g. finding translations is just a slice range), but the idea is that it should also be relatively inexpensive to add more dimensions if needed (e.g. role). Fixes #10169 Fixes #10364 Fixes #10482 Fixes #10630 Fixes #10656 Fixes #10694 Fixes #10918 Fixes #11262 Fixes #11439 Fixes #11453 Fixes #11457 Fixes #11466 Fixes #11540 Fixes #11551 Fixes #11556 Fixes #11654 Fixes #11661 Fixes #11663 Fixes #11664 Fixes #11669 Fixes #11671 Fixes #11807 Fixes #11808 Fixes #11809 Fixes #11815 Fixes #11840 Fixes #11853 Fixes #11860 Fixes #11883 Fixes #11904 Fixes #7388 Fixes #7425 Fixes #7436 Fixes #7544 Fixes #7882 Fixes #7960 Fixes #8255 Fixes #8307 Fixes #8863 Fixes #8927 Fixes #9192 Fixes #9324
Diffstat (limited to 'hugolib/hugo_sites_build_test.go')
-rw-r--r--hugolib/hugo_sites_build_test.go1093
1 files changed, 30 insertions, 1063 deletions
diff --git a/hugolib/hugo_sites_build_test.go b/hugolib/hugo_sites_build_test.go
index bdbf4270e..4c2bf452c 100644
--- a/hugolib/hugo_sites_build_test.go
+++ b/hugolib/hugo_sites_build_test.go
@@ -5,150 +5,44 @@ import (
"path/filepath"
"strings"
"testing"
- "time"
qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/htesting"
"github.com/gohugoio/hugo/resources/kinds"
- "github.com/fortytw2/leaktest"
- "github.com/fsnotify/fsnotify"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs"
"github.com/spf13/afero"
)
func TestMultiSitesMainLangInRoot(t *testing.T) {
- t.Parallel()
- for _, b := range []bool{false} {
- doTestMultiSitesMainLangInRoot(t, b)
- }
-}
-
-func doTestMultiSitesMainLangInRoot(t *testing.T, defaultInSubDir bool) {
- c := qt.New(t)
-
- siteConfig := map[string]any{
- "DefaultContentLanguage": "fr",
- "DefaultContentLanguageInSubdir": defaultInSubDir,
- }
-
- b := newMultiSiteTestBuilder(t, "toml", multiSiteTOMLConfigTemplate, siteConfig)
-
- pathMod := func(s string) string {
- return s
- }
-
- if !defaultInSubDir {
- pathMod = func(s string) string {
- return strings.Replace(s, "/fr/", "/", -1)
- }
- }
-
- b.CreateSites()
- b.Build(BuildCfg{})
-
- sites := b.H.Sites
- c.Assert(len(sites), qt.Equals, 4)
-
- enSite := sites[0]
- frSite := sites[1]
-
- c.Assert(enSite.LanguagePrefix(), qt.Equals, "/en")
-
- if defaultInSubDir {
- c.Assert(frSite.LanguagePrefix(), qt.Equals, "/fr")
- } else {
- c.Assert(frSite.LanguagePrefix(), qt.Equals, "")
- }
-
- c.Assert(enSite.PathSpec.RelURL("foo", true), qt.Equals, "/blog/en/foo")
-
- doc1en := enSite.RegularPages()[0]
- doc1fr := frSite.RegularPages()[0]
-
- enPerm := doc1en.Permalink()
- enRelPerm := doc1en.RelPermalink()
- c.Assert(enPerm, qt.Equals, "http://example.com/blog/en/sect/doc1-slug/")
- c.Assert(enRelPerm, qt.Equals, "/blog/en/sect/doc1-slug/")
-
- frPerm := doc1fr.Permalink()
- frRelPerm := doc1fr.RelPermalink()
-
- b.AssertFileContent(pathMod("public/fr/sect/doc1/index.html"), "Single", "Bonjour")
- b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Hello")
-
- if defaultInSubDir {
- c.Assert(frPerm, qt.Equals, "http://example.com/blog/fr/sect/doc1/")
- c.Assert(frRelPerm, qt.Equals, "/blog/fr/sect/doc1/")
-
- // should have a redirect on top level.
- b.AssertFileContent("public/index.html", `<meta http-equiv="refresh" content="0; url=http://example.com/blog/fr">`)
- } else {
- // Main language in root
- c.Assert(frPerm, qt.Equals, "http://example.com/blog/sect/doc1/")
- c.Assert(frRelPerm, qt.Equals, "/blog/sect/doc1/")
+ files := `
+-- hugo.toml --
+defaultContentLanguage = "fr"
+defaultContentLanguageInSubdir = false
+disableKinds = ["taxonomy", "term"]
+[languages]
+[languages.en]
+weight = 1
+[languages.fr]
+weight = 2
+-- content/sect/doc1.en.md --
+---
+title: doc1 en
+---
+-- content/sect/doc1.fr.md --
+---
+title: doc1 fr
+slug: doc1-fr
+---
+-- layouts/_default/single.html --
+Single: {{ .Title }}|{{ .Lang }}|{{ .RelPermalink }}|
- // should have redirect back to root
- b.AssertFileContent("public/fr/index.html", `<meta http-equiv="refresh" content="0; url=http://example.com/blog">`)
- }
- b.AssertFileContent(pathMod("public/fr/index.html"), "Home", "Bonjour")
- b.AssertFileContent("public/en/index.html", "Home", "Hello")
-
- // Check list pages
- b.AssertFileContent(pathMod("public/fr/sect/index.html"), "List", "Bonjour")
- b.AssertFileContent("public/en/sect/index.html", "List", "Hello")
- b.AssertFileContent(pathMod("public/fr/plaques/FRtag1/index.html"), "Taxonomy List", "Bonjour")
- b.AssertFileContent("public/en/tags/tag1/index.html", "Taxonomy List", "Hello")
-
- // Check sitemaps
- // Sitemaps behaves different: In a multilanguage setup there will always be a index file and
- // one sitemap in each lang folder.
- b.AssertFileContent("public/sitemap.xml",
- "<loc>http://example.com/blog/en/sitemap.xml</loc>",
- "<loc>http://example.com/blog/fr/sitemap.xml</loc>")
-
- if defaultInSubDir {
- b.AssertFileContent("public/fr/sitemap.xml", "<loc>http://example.com/blog/fr/</loc>")
- } else {
- b.AssertFileContent("public/fr/sitemap.xml", "<loc>http://example.com/blog/</loc>")
- }
- b.AssertFileContent("public/en/sitemap.xml", "<loc>http://example.com/blog/en/</loc>")
-
- // Check rss
- b.AssertFileContent(pathMod("public/fr/index.xml"), pathMod(`<atom:link href="http://example.com/blog/fr/index.xml"`),
- `rel="self" type="application/rss+xml"`)
- 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(
- pathMod("public/fr/plaques/FRtag1/index.xml"),
- pathMod(`<atom:link href="http://example.com/blog/fr/plaques/FRtag1/index.xml"`))
- b.AssertFileContent("public/en/tags/tag1/index.xml", `<atom:link href="http://example.com/blog/en/tags/tag1/index.xml"`)
-
- // Check paginators
- 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(
- pathMod("public/fr/plaques/FRtag1/page/1/index.html"),
- pathMod(`refresh" content="0; url=http://example.com/blog/fr/plaques/FRtag1/"`))
- b.AssertFileContent("public/en/tags/tag1/page/1/index.html", `refresh" content="0; url=http://example.com/blog/en/tags/tag1/"`)
- b.AssertFileContent(
- pathMod("public/fr/plaques/FRtag1/page/2/index.html"), "List Page 2", "Bonjour",
- pathMod("http://example.com/blog/fr/plaques/FRtag1/"))
- b.AssertFileContent("public/en/tags/tag1/page/2/index.html", "List Page 2", "Hello", "http://example.com/blog/en/tags/tag1/")
- // nn (Nynorsk) and nb (Bokmål) have custom pagePath: side ("page" in Norwegian)
- 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/"`)
+`
+ b := Test(t, files)
+ b.AssertFileContent("public/sect/doc1-fr/index.html", "Single: doc1 fr|fr|/sect/doc1-fr/|")
+ b.AssertFileContent("public/en/sect/doc1/index.html", "Single: doc1 en|en|/en/sect/doc1/|")
}
func TestMultiSitesWithTwoLanguages(t *testing.T) {
@@ -182,12 +76,12 @@ p1 = "p1en"
c.Assert(len(sites), qt.Equals, 2)
nnSite := sites[0]
- nnHome := nnSite.getPage(kinds.KindHome)
+ nnHome := nnSite.getPageOldVersion(kinds.KindHome)
c.Assert(len(nnHome.AllTranslations()), qt.Equals, 2)
c.Assert(len(nnHome.Translations()), qt.Equals, 1)
c.Assert(nnHome.IsTranslated(), qt.Equals, true)
- enHome := sites[1].getPage(kinds.KindHome)
+ enHome := sites[1].getPageOldVersion(kinds.KindHome)
p1, err := enHome.Param("p1")
c.Assert(err, qt.IsNil)
@@ -198,403 +92,6 @@ p1 = "p1en"
c.Assert(p1, qt.Equals, "p1nn")
}
-func TestMultiSitesBuild(t *testing.T) {
- for _, config := range []struct {
- content string
- suffix string
- }{
- {multiSiteTOMLConfigTemplate, "toml"},
- {multiSiteYAMLConfigTemplate, "yml"},
- {multiSiteJSONConfigTemplate, "json"},
- } {
- config := config
- t.Run(config.suffix, func(t *testing.T) {
- t.Parallel()
- doTestMultiSitesBuild(t, config.content, config.suffix)
- })
- }
-}
-
-func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
- c := qt.New(t)
-
- b := newMultiSiteTestBuilder(t, configSuffix, configTemplate, nil)
- b.CreateSites()
-
- sites := b.H.Sites
- c.Assert(len(sites), qt.Equals, 4)
-
- b.Build(BuildCfg{})
-
- // Check site config
- for _, s := range sites {
- c.Assert(s.conf.DefaultContentLanguageInSubdir, qt.Equals, true)
- c.Assert(s.conf.C.DisabledKinds, qt.Not(qt.IsNil))
- }
-
- gp1 := b.H.GetContentPage(filepath.FromSlash("content/sect/doc1.en.md"))
- c.Assert(gp1, qt.Not(qt.IsNil))
- c.Assert(gp1.Title(), qt.Equals, "doc1")
- gp2 := b.H.GetContentPage(filepath.FromSlash("content/dummysect/notfound.md"))
- c.Assert(gp2, qt.IsNil)
-
- enSite := sites[0]
- enSiteHome := enSite.getPage(kinds.KindHome)
- c.Assert(enSiteHome.IsTranslated(), qt.Equals, true)
-
- c.Assert(enSite.language.Lang, qt.Equals, "en")
-
- c.Assert(len(enSite.RegularPages()), qt.Equals, 5)
-
- //dumpPages(enSite.AllPages()...)
-
- //c.Assert(len(enSite.AllPages()), qt.Equals, 32)
-
- // 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")
-
- // Check robots.txt
- // the domain root is the public directory, so the robots.txt has to be created there and not in the language directories
- b.AssertFileContent("public/robots.txt", "robots")
- b.AssertFileDoesNotExist("public/en/robots.txt")
- b.AssertFileDoesNotExist("public/nn/robots.txt")
-
- 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/")
-
- doc2 := enSite.RegularPages()[1]
- doc3 := enSite.RegularPages()[2]
- c.Assert(doc3, qt.Equals, doc2.Prev())
- doc1en := enSite.RegularPages()[0]
- doc1fr := doc1en.Translations()[0]
- b.AssertFileContent("public/fr/sect/doc1/index.html", "Permalink: http://example.com/blog/fr/sect/doc1/")
-
- c.Assert(doc1fr, qt.Equals, doc1en.Translations()[0])
- c.Assert(doc1en, qt.Equals, doc1fr.Translations()[0])
- c.Assert(doc1fr.Language().Lang, qt.Equals, "fr")
-
- doc4 := enSite.AllPages()[4]
- c.Assert(len(doc4.Translations()), qt.Equals, 0)
-
- // Taxonomies and their URLs
- c.Assert(len(enSite.Taxonomies()), qt.Equals, 1)
- tags := enSite.Taxonomies()["tags"]
- c.Assert(len(tags), qt.Equals, 2)
- c.Assert(doc1en, qt.Equals, tags["tag1"][0].Page)
-
- frSite := sites[1]
- c.Assert(frSite.language.Lang, qt.Equals, "fr")
- c.Assert(len(frSite.RegularPages()), qt.Equals, 4)
- c.Assert(frSite.home.Title(), qt.Equals, "Le Français")
- c.Assert(len(frSite.AllPages()), qt.Equals, 32)
-
- for _, frenchPage := range frSite.RegularPages() {
- p := frenchPage
- c.Assert(p.Language().Lang, qt.Equals, "fr")
- }
-
- // 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:
- getPageDoc1En := enSite.getPage(kinds.KindPage, filepath.ToSlash(doc1en.File().Path()))
- getPageDoc1EnBase := enSite.getPage(kinds.KindPage, "sect/doc1")
- getPageDoc1Fr := frSite.getPage(kinds.KindPage, filepath.ToSlash(doc1fr.File().Path()))
- getPageDoc1FrBase := frSite.getPage(kinds.KindPage, "sect/doc1")
- c.Assert(getPageDoc1En, qt.Equals, doc1en)
- c.Assert(getPageDoc1Fr, qt.Equals, doc1fr)
- c.Assert(getPageDoc1EnBase, qt.Equals, doc1en)
- c.Assert(getPageDoc1FrBase, qt.Equals, doc1fr)
-
- // Check redirect to main language, French
- b.AssertFileContent("public/index.html", "0; url=http://example.com/blog/fr")
-
- // check home page content (including data files rendering)
- 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!")
-
- // check single page content
- 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")
-
- // Check node translations
- homeEn := enSite.getPage(kinds.KindHome)
- c.Assert(homeEn, qt.Not(qt.IsNil))
- c.Assert(len(homeEn.Translations()), qt.Equals, 3)
- c.Assert(homeEn.Translations()[0].Language().Lang, qt.Equals, "fr")
- c.Assert(homeEn.Translations()[1].Language().Lang, qt.Equals, "nn")
- c.Assert(homeEn.Translations()[1].Title(), qt.Equals, "På nynorsk")
- c.Assert(homeEn.Translations()[2].Language().Lang, qt.Equals, "nb")
- c.Assert(homeEn.Translations()[2].Title(), qt.Equals, "På bokmål")
- c.Assert(homeEn.Translations()[2].Language().LanguageName, qt.Equals, "Bokmål")
-
- sectFr := frSite.getPage(kinds.KindSection, "sect")
- c.Assert(sectFr, qt.Not(qt.IsNil))
-
- c.Assert(sectFr.Language().Lang, qt.Equals, "fr")
- c.Assert(len(sectFr.Translations()), qt.Equals, 1)
- c.Assert(sectFr.Translations()[0].Language().Lang, qt.Equals, "en")
- c.Assert(sectFr.Translations()[0].Title(), qt.Equals, "Sects")
-
- nnSite := sites[2]
- c.Assert(nnSite.language.Lang, qt.Equals, "nn")
- taxNn := nnSite.getPage(kinds.KindTaxonomy, "lag")
- c.Assert(taxNn, qt.Not(qt.IsNil))
- c.Assert(len(taxNn.Translations()), qt.Equals, 1)
- c.Assert(taxNn.Translations()[0].Language().Lang, qt.Equals, "nb")
-
- taxTermNn := nnSite.getPage(kinds.KindTerm, "lag", "sogndal")
- c.Assert(taxTermNn, qt.Not(qt.IsNil))
- c.Assert(nnSite.getPage(kinds.KindTerm, "LAG", "SOGNDAL"), qt.Equals, taxTermNn)
- c.Assert(len(taxTermNn.Translations()), qt.Equals, 1)
- c.Assert(taxTermNn.Translations()[0].Language().Lang, qt.Equals, "nb")
-
- // Check sitemap(s)
- 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/")
-
- // Check taxonomies
- enTags := enSite.Taxonomies()["tags"]
- frTags := frSite.Taxonomies()["plaques"]
- c.Assert(len(enTags), qt.Equals, 2, qt.Commentf("Tags in en: %v", enTags))
- c.Assert(len(frTags), qt.Equals, 2, qt.Commentf("Tags in fr: %v", frTags))
- c.Assert(enTags["tag1"], qt.Not(qt.IsNil))
- c.Assert(frTags["FRtag1"], qt.Not(qt.IsNil))
- b.AssertFileContent("public/fr/plaques/FRtag1/index.html", "FRtag1|Bonjour|http://example.com/blog/fr/plaques/FRtag1/")
-
- // en and nn have custom site menus
- c.Assert(len(frSite.Menus()), qt.Equals, 0)
- c.Assert(len(enSite.Menus()), qt.Equals, 1)
- c.Assert(len(nnSite.Menus()), qt.Equals, 1)
-
- c.Assert(enSite.Menus()["main"].ByName()[0].Name, qt.Equals, "Home")
- c.Assert(nnSite.Menus()["main"].ByName()[0].Name, qt.Equals, "Heim")
-
- // Issue #3108
- prevPage := enSite.RegularPages()[0].Prev()
- c.Assert(prevPage, qt.Not(qt.IsNil))
- c.Assert(prevPage.Kind(), qt.Equals, kinds.KindPage)
-
- for {
- if prevPage == nil {
- break
- }
- c.Assert(prevPage.Kind(), qt.Equals, kinds.KindPage)
- prevPage = prevPage.Prev()
- }
-
- // Check bundles
- b.AssertFileContent("public/fr/bundles/b1/index.html", "RelPermalink: /blog/fr/bundles/b1/|")
- bundleFr := frSite.getPage(kinds.KindPage, "bundles/b1/index.md")
- c.Assert(bundleFr, qt.Not(qt.IsNil))
- c.Assert(len(bundleFr.Resources()), qt.Equals, 1)
- logoFr := bundleFr.Resources().GetMatch("logo*")
- logoFrGet := bundleFr.Resources().Get("logo.png")
- c.Assert(logoFrGet, qt.Equals, logoFr)
- c.Assert(logoFr, qt.Not(qt.IsNil))
- b.AssertFileContent("public/fr/bundles/b1/index.html", "Resources: image/png: /blog/fr/bundles/b1/logo.png")
- b.AssertFileContent("public/fr/bundles/b1/logo.png", "PNG Data")
-
- bundleEn := enSite.getPage(kinds.KindPage, "bundles/b1/index.en.md")
- c.Assert(bundleEn, qt.Not(qt.IsNil))
- b.AssertFileContent("public/en/bundles/b1/index.html", "RelPermalink: /blog/en/bundles/b1/|")
- c.Assert(len(bundleEn.Resources()), qt.Equals, 1)
- logoEn := bundleEn.Resources().GetMatch("logo*")
- c.Assert(logoEn, qt.Not(qt.IsNil))
- b.AssertFileContent("public/en/bundles/b1/index.html", "Resources: image/png: /blog/en/bundles/b1/logo.png")
- b.AssertFileContent("public/en/bundles/b1/logo.png", "PNG Data")
-}
-
-func TestMultiSitesRebuild(t *testing.T) {
- // t.Parallel() not supported, see https://github.com/fortytw2/leaktest/issues/4
- // This leaktest seems to be a little bit shaky on Travis.
- if !htesting.IsCI() {
- defer leaktest.CheckTimeout(t, 10*time.Second)()
- }
-
- c := qt.New(t)
-
- b := newMultiSiteTestDefaultBuilder(t).Running().CreateSites().Build(BuildCfg{})
-
- sites := b.H.Sites
- fs := b.Fs
-
- 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>")
-
- enSite := sites[0]
- frSite := sites[1]
-
- c.Assert(len(enSite.RegularPages()), qt.Equals, 5)
- c.Assert(len(frSite.RegularPages()), qt.Equals, 4)
-
- // Verify translations
- b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Hello")
- b.AssertFileContent("public/fr/sect/doc1/index.html", "Bonjour")
-
- // check single page content
- b.AssertFileContent("public/fr/sect/doc1/index.html", "Single", "Shortcode: Bonjour")
- b.AssertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Shortcode: Hello")
-
- homeEn := enSite.getPage(kinds.KindHome)
- c.Assert(homeEn, qt.Not(qt.IsNil))
- c.Assert(len(homeEn.Translations()), qt.Equals, 3)
-
- contentFs := b.H.Fs.Source
-
- 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
- {
- 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}},
- func(t *testing.T) {
- c.Assert(len(enSite.RegularPages()), qt.Equals, 4, qt.Commentf("1 en removed"))
- },
- },
- {
- func(t *testing.T) {
- writeNewContentFile(t, contentFs, "new_en_1", "2016-07-31", "content/new1.en.md", -5)
- writeNewContentFile(t, contentFs, "new_en_2", "1989-07-30", "content/new2.en.md", -10)
- writeNewContentFile(t, contentFs, "new_fr_1", "2016-07-30", "content/new1.fr.md", 10)
- },
- []fsnotify.Event{
- {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},
- },
- func(t *testing.T) {
- c.Assert(len(enSite.RegularPages()), qt.Equals, 6)
- c.Assert(len(enSite.AllPages()), qt.Equals, 34)
- c.Assert(len(frSite.RegularPages()), qt.Equals, 5)
- c.Assert(frSite.RegularPages()[3].Title(), qt.Equals, "new_fr_1")
- c.Assert(enSite.RegularPages()[0].Title(), qt.Equals, "new_en_2")
- c.Assert(enSite.RegularPages()[1].Title(), qt.Equals, "new_en_1")
-
- rendered := readWorkingDir(t, fs, "public/en/new1/index.html")
- c.Assert(strings.Contains(rendered, "new_en_1"), qt.Equals, true)
- },
- },
- {
- func(t *testing.T) {
- p := "content/sect/doc1.en.md"
- doc1 := readFileFromFs(t, contentFs, p)
- doc1 += "CHANGED"
- writeToFs(t, contentFs, p, doc1)
- },
- []fsnotify.Event{{Name: filepath.FromSlash("content/sect/doc1.en.md"), Op: fsnotify.Write}},
- func(t *testing.T) {
- c.Assert(len(enSite.RegularPages()), qt.Equals, 6)
- doc1 := readWorkingDir(t, fs, "public/en/sect/doc1-slug/index.html")
- c.Assert(strings.Contains(doc1, "CHANGED"), qt.Equals, true)
- },
- },
- // Rename a file
- {
- func(t *testing.T) {
- if err := contentFs.Rename("content/new1.en.md", "content/new1renamed.en.md"); err != nil {
- t.Fatalf("Rename failed: %s", err)
- }
- },
- []fsnotify.Event{
- {Name: filepath.FromSlash("content/new1renamed.en.md"), Op: fsnotify.Rename},
- {Name: filepath.FromSlash("content/new1.en.md"), Op: fsnotify.Rename},
- },
- func(t *testing.T) {
- c.Assert(len(enSite.RegularPages()), qt.Equals, 6, qt.Commentf("Rename"))
- c.Assert(enSite.RegularPages()[1].Title(), qt.Equals, "new_en_1")
- rendered := readWorkingDir(t, fs, "public/en/new1renamed/index.html")
- c.Assert(rendered, qt.Contains, "new_en_1")
- },
- },
- {
- // Change a template
- func(t *testing.T) {
- template := "layouts/_default/single.html"
- templateContent := readSource(t, fs, template)
- templateContent += "{{ print \"Template Changed\"}}"
- writeSource(t, fs, template, templateContent)
- },
- []fsnotify.Event{{Name: filepath.FromSlash("layouts/_default/single.html"), Op: fsnotify.Write}},
- func(t *testing.T) {
- c.Assert(len(enSite.RegularPages()), qt.Equals, 6)
- c.Assert(len(enSite.AllPages()), qt.Equals, 34)
- c.Assert(len(frSite.RegularPages()), qt.Equals, 5)
- doc1 := readWorkingDir(t, fs, "public/en/sect/doc1-slug/index.html")
- c.Assert(strings.Contains(doc1, "Template Changed"), qt.Equals, true)
- },
- },
- {
- // Change a language file
- func(t *testing.T) {
- languageFile := "i18n/fr.yaml"
- langContent := readSource(t, fs, languageFile)
- langContent = strings.Replace(langContent, "Bonjour", "Salut", 1)
- writeSource(t, fs, languageFile, langContent)
- },
- []fsnotify.Event{{Name: filepath.FromSlash("i18n/fr.yaml"), Op: fsnotify.Write}},
- func(t *testing.T) {
- c.Assert(len(enSite.RegularPages()), qt.Equals, 6)
- c.Assert(len(enSite.AllPages()), qt.Equals, 34)
- c.Assert(len(frSite.RegularPages()), qt.Equals, 5)
- docEn := readWorkingDir(t, fs, "public/en/sect/doc1-slug/index.html")
- c.Assert(strings.Contains(docEn, "Hello"), qt.Equals, true)
- docFr := readWorkingDir(t, fs, "public/fr/sect/doc1/index.html")
- c.Assert(strings.Contains(docFr, "Salut"), qt.Equals, true)
-
- homeEn := enSite.getPage(kinds.KindHome)
- c.Assert(homeEn, qt.Not(qt.IsNil))
- c.Assert(len(homeEn.Translations()), qt.Equals, 3)
- c.Assert(homeEn.Translations()[0].Language().Lang, qt.Equals, "fr")
- },
- },
- // Change a shortcode
- {
- func(t *testing.T) {
- writeSource(t, fs, "layouts/shortcodes/shortcode.html", "Modified Shortcode: {{ i18n \"hello\" }}")
- },
- []fsnotify.Event{
- {Name: filepath.FromSlash("layouts/shortcodes/shortcode.html"), Op: fsnotify.Write},
- },
- func(t *testing.T) {
- c.Assert(len(enSite.RegularPages()), qt.Equals, 6)
- c.Assert(len(enSite.AllPages()), qt.Equals, 34)
- c.Assert(len(frSite.RegularPages()), qt.Equals, 5)
- 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")
- },
- },
- } {
-
- if this.preFunc != nil {
- this.preFunc(t)
- }
-
- err := b.H.Build(BuildCfg{}, this.events...)
- if err != nil {
- t.Fatalf("[%d] Failed to rebuild sites: %s", i, err)
- }
-
- this.assertFunc(t)
- }
-}
-
// https://github.com/gohugoio/hugo/issues/4706
func TestContentStressTest(t *testing.T) {
b := newTestSitesBuilder(t)
@@ -774,8 +271,8 @@ categories: ["mycat"]
t.Run(path, func(t *testing.T) {
c := qt.New(t)
- s1, _ := b.H.Sites[0].getPageNew(nil, path)
- s2, _ := b.H.Sites[1].getPageNew(nil, path)
+ s1, _ := b.H.Sites[0].getPage(nil, path)
+ s2, _ := b.H.Sites[1].getPage(nil, path)
c.Assert(s1, qt.Not(qt.IsNil))
c.Assert(s2, qt.Not(qt.IsNil))
@@ -794,310 +291,6 @@ categories: ["mycat"]
}
}
-var tocShortcode = `
-TOC1: {{ .Page.TableOfContents }}
-
-TOC2: {{ .Page.TableOfContents }}
-`
-
-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:")
-}
-
-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...
-`
-
-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 %}}
-
-`
-
-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>`
-
-var multiSiteTOMLConfigTemplate = `
-baseURL = "http://example.com/blog"
-
-paginate = 1
-disablePathToLower = true
-defaultContentLanguage = "{{ .DefaultContentLanguage }}"
-defaultContentLanguageInSubdir = {{ .DefaultContentLanguageInSubdir }}
-enableRobotsTXT = true
-
-[permalinks]
-other = "/somewhere/else/:filename"
-
-[Taxonomies]
-tag = "tags"
-
-[Languages]
-[Languages.en]
-weight = 10
-title = "In English"
-languageName = "English"
-[[Languages.en.menu.main]]</