require.Equal(t, "en", enSite.Language.Lang)
- if len(enSite.RegularPages) != 4 {
- t.Fatal("Expected 4 english pages")
+ if len(enSite.RegularPages) != 5 {
+ t.Fatal("Expected 5 english pages")
}
- require.Len(t, enSite.AllPages, 28, "should have 28 total pages (including translations and index types)")
+
+ require.Len(t, enSite.AllPages, 32, "should have 32 total pages (including translations and index types)")
doc1en := enSite.RegularPages[0]
permalink := doc1en.Permalink()
frSite := sites.Sites[1]
require.Equal(t, "fr", frSite.Language.Lang)
- require.Len(t, frSite.RegularPages, 3, "should have 3 pages")
- require.Len(t, frSite.AllPages, 28, "should have 28 total pages (including translations and nodes)")
+ 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)")
for _, frenchPage := range frSite.RegularPages {
require.Equal(t, "fr", frenchPage.Lang())
next = next.Next
}
+ // Check bundles
+ bundleFr := enSite.getPage(KindPage, "bundles/b1/index.md")
+ require.NotNil(t, bundleFr)
+ require.Equal(t, "/blog/fr/bundles/b1/", bundleFr.RelPermalink())
+ require.Equal(t, 1, len(bundleFr.Resources))
+ logoFr := bundleFr.Resources.GetByPrefix("logo")
+ require.NotNil(t, logoFr)
+ require.Equal(t, "/blog/fr/bundles/b1/logo.png", logoFr.RelPermalink())
+ require.Contains(t, readFileFromFs(t, fs.Destination, filepath.FromSlash("public/fr/bundles/b1/logo.png")), "PNG Data")
+
+ bundleEn := enSite.getPage(KindPage, "bundles/b1/index.en.md")
+ require.NotNil(t, bundleEn)
+ require.Equal(t, "/blog/en/bundles/b1/", bundleEn.RelPermalink())
+ require.Equal(t, 1, len(bundleEn.Resources))
+ logoEn := bundleEn.Resources.GetByPrefix("logo")
+ require.NotNil(t, logoEn)
+ require.Equal(t, "/blog/en/bundles/b1/logo.png", logoEn.RelPermalink())
+ require.Contains(t, readFileFromFs(t, fs.Destination, filepath.FromSlash("public/en/bundles/b1/logo.png")), "PNG Data")
+
}
func TestMultiSitesRebuild(t *testing.T) {
enSite := sites.Sites[0]
frSite := sites.Sites[1]
- require.Len(t, enSite.RegularPages, 4)
- require.Len(t, frSite.RegularPages, 3)
+ require.Len(t, enSite.RegularPages, 5)
+ require.Len(t, frSite.RegularPages, 4)
// Verify translations
th.assertFileContent("public/en/sect/doc1-slug/index.html", "Hello")
},
[]fsnotify.Event{{Name: filepath.FromSlash("content/sect/doc2.en.md"), Op: fsnotify.Remove}},
func(t *testing.T) {
- require.Len(t, enSite.RegularPages, 3, "1 en removed")
+ require.Len(t, enSite.RegularPages, 4, "1 en removed")
// Check build stats
require.Equal(t, 1, enSite.draftCount, "Draft")
{Name: filepath.FromSlash("content/new1.fr.md"), Op: fsnotify.Create},
},
func(t *testing.T) {
- require.Len(t, enSite.RegularPages, 5)
- require.Len(t, enSite.AllPages, 30)
- require.Len(t, frSite.RegularPages, 4)
+ require.Len(t, enSite.RegularPages, 6)
+ require.Len(t, enSite.AllPages, 34)
+ require.Len(t, 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)
},
[]fsnotify.Event{{Name: filepath.FromSlash("content/sect/doc1.en.md"), Op: fsnotify.Write}},
func(t *testing.T) {
- require.Len(t, enSite.RegularPages, 5)
+ require.Len(t, enSite.RegularPages, 6)
doc1 := readDestination(t, fs, "public/en/sect/doc1-slug/index.html")
require.True(t, strings.Contains(doc1, "CHANGED"), doc1)
{Name: filepath.FromSlash("content/new1.en.md"), Op: fsnotify.Rename},
},
func(t *testing.T) {
- require.Len(t, enSite.RegularPages, 5, "Rename")
+ require.Len(t, enSite.RegularPages, 6, "Rename")
require.Equal(t, "new_en_1", enSite.RegularPages[1].Title)
rendered := readDestination(t, fs, "public/en/new1renamed/index.html")
require.True(t, strings.Contains(rendered, "new_en_1"), rendered)
},
[]fsnotify.Event{{Name: filepath.FromSlash("layouts/_default/single.html"), Op: fsnotify.Write}},
func(t *testing.T) {
- require.Len(t, enSite.RegularPages, 5)
- require.Len(t, enSite.AllPages, 30)
- require.Len(t, frSite.RegularPages, 4)
+ require.Len(t, enSite.RegularPages, 6)
+ require.Len(t, enSite.AllPages, 34)
+ require.Len(t, frSite.RegularPages, 5)
doc1 := readDestination(t, fs, "public/en/sect/doc1-slug/index.html")
require.True(t, strings.Contains(doc1, "Template Changed"), doc1)
},
},
[]fsnotify.Event{{Name: filepath.FromSlash("i18n/fr.yaml"), Op: fsnotify.Write}},
func(t *testing.T) {
- require.Len(t, enSite.RegularPages, 5)
- require.Len(t, enSite.AllPages, 30)
- require.Len(t, frSite.RegularPages, 4)
+ require.Len(t, enSite.RegularPages, 6)
+ require.Len(t, enSite.AllPages, 34)
+ require.Len(t, frSite.RegularPages, 5)
docEn := readDestination(t, fs, "public/en/sect/doc1-slug/index.html")
require.True(t, strings.Contains(docEn, "Hello"), "No Hello")
docFr := readDestination(t, fs, "public/fr/sect/doc1/index.html")
{Name: filepath.FromSlash("layouts/shortcodes/shortcode.html"), Op: fsnotify.Write},
},
func(t *testing.T) {
- require.Len(t, enSite.RegularPages, 5)
- require.Len(t, enSite.AllPages, 30)
- require.Len(t, frSite.RegularPages, 4)
+ require.Len(t, enSite.RegularPages, 6)
+ require.Len(t, enSite.AllPages, 34)
+ require.Len(t, frSite.RegularPages, 5)
th.assertFileContent("public/fr/sect/doc1/index.html", "Single", "Modified Shortcode: Salut")
th.assertFileContent("public/en/sect/doc1-slug/index.html", "Single", "Modified Shortcode: Hello")
},
require.Len(t, homeEn.Translations(), 4)
require.Equal(t, "sv", homeEn.Translations()[0].Lang())
- require.Len(t, enSite.RegularPages, 4)
- require.Len(t, frSite.RegularPages, 3)
+ require.Len(t, enSite.RegularPages, 5)
+ require.Len(t, frSite.RegularPages, 4)
// Veriy Swedish site
require.Len(t, svSite.RegularPages, 1)
- Sogndal
---
# Tax NB
+`},
+ // Bundle
+ {filepath.FromSlash("bundles/b1/index.en.md"), `---
+title: Bundle EN
+publishdate: "2000-01-06"
+weight: 2001
+---
+# Bundle Content EN
+`},
+ {filepath.FromSlash("bundles/b1/index.md"), `---
+title: Bundle Default
+publishdate: "2000-01-06"
+weight: 2002
+---
+# Bundle Content Default
+`},
+ {filepath.FromSlash("bundles/b1/logo.png"), `
+PNG Data
`},
}
b, err := afero.ReadFile(fs, filename)
if err != nil {
// Print some debug info
- root := "/" //strings.Split(filename, helpers.FilePathSeparator)[0]
+ root := "" //strings.Split(filename, helpers.FilePathSeparator)[0]
afero.Walk(fs, root, func(path string, info os.FileInfo, err error) error {
if info != nil && !info.IsDir() {
fmt.Println(" ", path)
r := spec.newGenericResource(nil, nil, "/public", "/a/foo.css", "foo.css", "css")
assert.Equal("https://example.com/foo.css", r.Permalink())
- assert.Equal("foo.css", r.RelPermalink())
+ assert.Equal("/foo.css", r.RelPermalink())
assert.Equal("css", r.ResourceType())
}
assert.NoError(err)
assert.NotNil(r)
assert.Equal("image", r.ResourceType())
- assert.Equal("a/b/logo.png", r.RelPermalink())
+ assert.Equal("/a/b/logo.png", r.RelPermalink())
assert.Equal("https://example.com/a/b/logo.png", r.Permalink())
r, err = spec.NewResourceFromFilename(nil, "/public", "/root/a/b/data.json", "a/b/data.json")
assert.Equal("/aceof/a/b/data.json", cloned.RelPermalink())
}
+func TestNewResourceFromFilenameSubPathInBaseURL(t *testing.T) {
+ assert := require.New(t)
+ spec := newTestResourceSpecForBaseURL(assert, "https://example.com/docs")
+
+ writeSource(t, spec.Fs, "/project/a/b/logo.png", "image")
+
+ r, err := spec.NewResourceFromFilename(nil, "/public",
+ filepath.FromSlash("/project/a/b/logo.png"), filepath.FromSlash("a/b/logo.png"))
+
+ assert.NoError(err)
+ assert.NotNil(r)
+ assert.Equal("image", r.ResourceType())
+ assert.Equal("/docs/a/b/logo.png", r.RelPermalink())
+ assert.Equal("https://example.com/docs/a/b/logo.png", r.Permalink())
+ img := r.(*Image)
+ assert.Equal("/a/b/logo.png", img.target())
+
+}
+
func TestResourcesByType(t *testing.T) {
assert := require.New(t)
spec := newTestResourceSpec(assert)
spec.newGenericResource(nil, nil, "/public", "/b/foo3.css", "foo3.css", "css")}
assert.Nil(resources.GetByPrefix("asdf"))
- assert.Equal("logo1.png", resources.GetByPrefix("logo").RelPermalink())
- assert.Equal("foo2.css", resources.GetByPrefix("foo2").RelPermalink())
- assert.Equal("foo1.css", resources.GetByPrefix("foo1").RelPermalink())
- assert.Equal("foo1.css", resources.GetByPrefix("foo1").RelPermalink())
+ assert.Equal("/logo1.png", resources.GetByPrefix("logo").RelPermalink())
+ assert.Equal("/foo2.css", resources.GetByPrefix("foo2").RelPermalink())
+ assert.Equal("/foo1.css", resources.GetByPrefix("foo1").RelPermalink())
+ assert.Equal("/foo1.css", resources.GetByPrefix("foo1").RelPermalink())
assert.Nil(resources.GetByPrefix("asdfasdf"))
}