Rework the Destination filesystem to make --renderStaticToDisk work

See #9626
This commit is contained in:
Bjørn Erik Pedersen
2022-03-21 09:35:15 +01:00
parent b08193971a
commit d070bdf10f
75 changed files with 651 additions and 566 deletions

View File

@@ -35,7 +35,6 @@ import (
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/hugolib/paths"
"github.com/gohugoio/hugo/langs"
"github.com/gohugoio/hugo/modules"
"github.com/pkg/errors"
@@ -359,7 +358,7 @@ func (l configLoader) collectModules(modConfig modules.Config, v1 config.Provide
workingDir = v1.GetString("workingDir")
}
themesDir := paths.AbsPathify(l.WorkingDir, v1.GetString("themesDir"))
themesDir := cpaths.AbsPathify(l.WorkingDir, v1.GetString("themesDir"))
var ignoreVendor glob.Glob
if s := v1.GetString("ignoreVendorPaths"); s != "" {

View File

@@ -38,8 +38,8 @@ import (
"github.com/gohugoio/hugo/modules"
hpaths "github.com/gohugoio/hugo/common/paths"
"github.com/gohugoio/hugo/hugofs"
"github.com/gohugoio/hugo/hugolib/paths"
"github.com/spf13/afero"
)
@@ -68,12 +68,12 @@ type BaseFs struct {
// This usually maps to /my-project/public.
PublishFs afero.Fs
// A read-only filesystem starting from the project workDir.
WorkDir afero.Fs
// The filesystem used for renderStaticToDisk.
PublishFsStatic afero.Fs
// A read-only filesystem starting from the project workDir.
WorkDir afero.Fs
theBigFs *filesystemsCollector
// Locks.
@@ -434,21 +434,13 @@ func NewBase(p *paths.Paths, logger loggers.Logger, options ...func(*BaseFs) err
logger = loggers.NewWarningLogger()
}
// Make sure we always have the /public folder ready to use.
if err := fs.Destination.MkdirAll(p.AbsPublishDir, 0777); err != nil && !os.IsExist(err) {
return nil, err
}
publishFs := hugofs.NewBaseFileDecorator(afero.NewBasePathFs(fs.Destination, p.AbsPublishDir))
publishFs := hugofs.NewBaseFileDecorator(fs.PublishDir)
sourceFs := hugofs.NewBaseFileDecorator(afero.NewBasePathFs(fs.Source, p.WorkingDir))
publishFsStatic := afero.NewBasePathFs(fs.Source, p.AbsPublishDir)
// Same as sourceFs, but no decoration. This is what's used by os.ReadDir etc.
workDir := afero.NewBasePathFs(afero.NewReadOnlyFs(fs.Source), p.WorkingDir)
publishFsStatic := fs.PublishDirStatic
b := &BaseFs{
SourceFs: sourceFs,
WorkDir: workDir,
WorkDir: fs.WorkingDirReadOnly,
PublishFs: publishFs,
PublishFsStatic: publishFsStatic,
buildMu: lockedfile.MutexAt(filepath.Join(p.WorkingDir, lockFileBuild)),
@@ -638,7 +630,7 @@ func (b *sourceFilesystemsBuilder) createModFs(
if filepath.IsAbs(path) {
return "", path
}
return md.dir, paths.AbsPathify(md.dir, path)
return md.dir, hpaths.AbsPathify(md.dir, path)
}
for i, mount := range md.Mounts() {

View File

@@ -75,7 +75,7 @@ func initConfig(fs afero.Fs, cfg config.Provider) error {
func TestNewBaseFs(t *testing.T) {
c := qt.New(t)
v := config.New()
v := config.NewWithTestDefaults()
fs := hugofs.NewMem(v)
@@ -181,7 +181,7 @@ theme = ["atheme"]
}
func createConfig() config.Provider {
v := config.New()
v := config.NewWithTestDefaults()
v.Set("contentDir", "mycontent")
v.Set("i18nDir", "myi18n")
v.Set("staticDir", "mystatic")
@@ -219,22 +219,19 @@ func TestNewBaseFsEmpty(t *testing.T) {
func TestRealDirs(t *testing.T) {
c := qt.New(t)
v := createConfig()
root, themesDir := t.TempDir(), t.TempDir()
v.Set("workingDir", root)
v.Set("themesDir", themesDir)
v.Set("theme", "mytheme")
fs := hugofs.NewDefault(v)
sfs := fs.Source
root, err := afero.TempDir(sfs, "", "realdir")
c.Assert(err, qt.IsNil)
themesDir, err := afero.TempDir(sfs, "", "themesDir")
c.Assert(err, qt.IsNil)
defer func() {
os.RemoveAll(root)
os.RemoveAll(themesDir)
}()
v.Set("workingDir", root)
v.Set("themesDir", themesDir)
v.Set("theme", "mytheme")
c.Assert(sfs.MkdirAll(filepath.Join(root, "myassets", "scss", "sf1"), 0755), qt.IsNil)
c.Assert(sfs.MkdirAll(filepath.Join(root, "myassets", "scss", "sf2"), 0755), qt.IsNil)
c.Assert(sfs.MkdirAll(filepath.Join(themesDir, "mytheme", "assets", "scss", "sf2"), 0755), qt.IsNil)

View File

@@ -59,13 +59,14 @@ path="github.com/gohugoio/hugoTestModule2"
return fmt.Sprintf(tomlConfig, workingDir, moduleOpts)
}
newTestBuilder := func(t testing.TB, moduleOpts string) (*sitesBuilder, func()) {
newTestBuilder := func(t testing.TB, moduleOpts string) *sitesBuilder {
b := newTestSitesBuilder(t)
tempDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-modules-variants")
b.Assert(err, qt.IsNil)
tempDir := t.TempDir()
workingDir := filepath.Join(tempDir, "myhugosite")
b.Assert(os.MkdirAll(workingDir, 0777), qt.IsNil)
b.Fs = hugofs.NewDefault(config.New())
cfg := config.NewWithTestDefaults()
cfg.Set("workingDir", workingDir)
b.Fs = hugofs.NewDefault(cfg)
b.WithWorkingDir(workingDir).WithConfigFile("toml", createConfig(workingDir, moduleOpts))
b.WithTemplates(
"index.html", `
@@ -92,22 +93,18 @@ github.com/gohugoio/hugoTestModule2 v0.0.0-20200131160637-9657d7697877 h1:WLM2bQ
github.com/gohugoio/hugoTestModule2 v0.0.0-20200131160637-9657d7697877/go.mod h1:CBFZS3khIAXKxReMwq0le8sEl/D8hcXmixlOHVv+Gd0=
`)
return b, clean
return b
}
t.Run("Target in subfolder", func(t *testing.T) {
b, clean := newTestBuilder(t, "ignoreImports=true")
defer clean()
b := newTestBuilder(t, "ignoreImports=true")
b.Build(BuildCfg{})
b.AssertFileContent("public/p1/index.html", `<p>Page|https://bep.is|Title: |Text: A link|END</p>`)
})
t.Run("Ignore config", func(t *testing.T) {
b, clean := newTestBuilder(t, "ignoreConfig=true")
defer clean()
b := newTestBuilder(t, "ignoreConfig=true")
b.Build(BuildCfg{})
b.AssertFileContent("public/index.html", `
@@ -117,9 +114,7 @@ JS imported in module: |
})
t.Run("Ignore imports", func(t *testing.T) {
b, clean := newTestBuilder(t, "ignoreImports=true")
defer clean()
b := newTestBuilder(t, "ignoreImports=true")
b.Build(BuildCfg{})
b.AssertFileContent("public/index.html", `
@@ -129,8 +124,7 @@ JS imported in module: |
})
t.Run("Create package.json", func(t *testing.T) {
b, clean := newTestBuilder(t, "")
defer clean()
b := newTestBuilder(t, "")
b.WithSourceFile("package.json", `{
"name": "mypack",
@@ -205,8 +199,7 @@ JS imported in module: |
})
t.Run("Create package.json, no default", func(t *testing.T) {
b, clean := newTestBuilder(t, "")
defer clean()
b := newTestBuilder(t, "")
const origPackageJSON = `{
"name": "mypack",
@@ -268,8 +261,7 @@ JS imported in module: |
})
t.Run("Create package.json, no default, no package.json", func(t *testing.T) {
b, clean := newTestBuilder(t, "")
defer clean()
b := newTestBuilder(t, "")
b.Build(BuildCfg{})
b.Assert(npm.Pack(b.H.BaseFs.SourceFs, b.H.BaseFs.Assets.Dirs), qt.IsNil)
@@ -333,12 +325,13 @@ func TestHugoModulesMatrix(t *testing.T) {
for _, m := range testmods[:2] {
c := qt.New(t)
v := config.New()
workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-modules-test")
c.Assert(err, qt.IsNil)
defer clean()
v := config.NewWithTestDefaults()
v.Set("workingDir", workingDir)
configTemplate := `
baseURL = "https://example.com"
title = "My Modular Site"
@@ -670,13 +663,14 @@ func TestModulesSymlinks(t *testing.T) {
}()
c := qt.New(t)
// We need to use the OS fs for this.
cfg := config.New()
fs := hugofs.NewFrom(hugofs.Os, cfg)
workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-mod-sym")
workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-mod-sym")
c.Assert(err, qt.IsNil)
// We need to use the OS fs for this.
cfg := config.NewWithTestDefaults()
cfg.Set("workingDir", workingDir)
fs := hugofs.NewFrom(hugofs.Os, cfg)
defer clean()
const homeTemplate = `
@@ -694,9 +688,9 @@ Data: {{ .Site.Data }}
}
// Create project dirs and files.
createDirsAndFiles(workDir)
createDirsAndFiles(workingDir)
// Create one module inside the default themes folder.
themeDir := filepath.Join(workDir, "themes", "mymod")
themeDir := filepath.Join(workingDir, "themes", "mymod")
createDirsAndFiles(themeDir)
createSymlinks := func(baseDir, id string) {
@@ -711,7 +705,7 @@ Data: {{ .Site.Data }}
}
}
createSymlinks(workDir, "project")
createSymlinks(workingDir, "project")
createSymlinks(themeDir, "mod")
config := `
@@ -729,12 +723,12 @@ weight = 2
`
b := newTestSitesBuilder(t).WithNothingAdded().WithWorkingDir(workDir)
b := newTestSitesBuilder(t).WithNothingAdded().WithWorkingDir(workingDir)
b.WithLogger(loggers.NewErrorLogger())
b.Fs = fs
b.WithConfigFile("toml", config)
c.Assert(os.Chdir(workDir), qt.IsNil)
c.Assert(os.Chdir(workingDir), qt.IsNil)
b.Build(BuildCfg{})
@@ -846,7 +840,10 @@ workingDir = %q
b := newTestSitesBuilder(t).Running()
b.Fs = hugofs.NewDefault(config.New())
cfg := config.NewWithTestDefaults()
cfg.Set("workingDir", workingDir)
b.Fs = hugofs.NewDefault(cfg)
b.WithWorkingDir(workingDir).WithConfigFile("toml", tomlConfig)
b.WithTemplatesAdded("index.html", `
@@ -968,7 +965,9 @@ workingDir = %q
b := newTestSitesBuilder(c).Running()
b.Fs = hugofs.NewDefault(config.New())
cfg := config.NewWithTestDefaults()
cfg.Set("workingDir", workingDir)
b.Fs = hugofs.NewDefault(cfg)
os.MkdirAll(filepath.Join(workingDir, "content", "blog"), 0777)
@@ -1067,7 +1066,7 @@ func TestSiteWithGoModButNoModules(t *testing.T) {
workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-no-mod")
c.Assert(err, qt.IsNil)
cfg := config.New()
cfg := config.NewWithTestDefaults()
cfg.Set("workingDir", workDir)
fs := hugofs.NewFrom(hugofs.Os, cfg)
@@ -1093,7 +1092,7 @@ func TestModuleAbsMount(t *testing.T) {
absContentDir, clean2, err := htesting.CreateTempDir(hugofs.Os, "hugo-content")
c.Assert(err, qt.IsNil)
cfg := config.New()
cfg := config.NewWithTestDefaults()
cfg.Set("workingDir", workDir)
fs := hugofs.NewFrom(hugofs.Os, cfg)

View File

@@ -597,7 +597,7 @@ func (h *HugoSites) reset(config *BuildCfg) {
if config.ResetState {
for i, s := range h.Sites {
h.Sites[i] = s.reset()
if r, ok := s.Fs.Destination.(hugofs.Reseter); ok {
if r, ok := s.Fs.PublishDir.(hugofs.Reseter); ok {
r.Reset()
}
}

View File

@@ -496,9 +496,9 @@ func (h *HugoSites) writeBuildStats() error {
return err
}
// Write to the destination, too, if a mem fs is in play.
if h.Fs.Source != hugofs.Os {
if err := afero.WriteFile(h.Fs.Destination, filename, js, 0666); err != nil {
// Write to the destination as well if it's a in-memory fs.
if !hugofs.IsOsFs(h.Fs.Source) {
if err := afero.WriteFile(h.Fs.WorkingDirWritable, filename, js, 0666); err != nil {
return err
}
}

View File

@@ -489,7 +489,7 @@ func TestMultiSitesRebuild(t *testing.T) {
c.Assert(enSite.RegularPages()[0].Title(), qt.Equals, "new_en_2")
c.Assert(enSite.RegularPages()[1].Title(), qt.Equals, "new_en_1")
rendered := readDestination(t, fs, "public/en/new1/index.html")
rendered := readWorkingDir(t, fs, "public/en/new1/index.html")
c.Assert(strings.Contains(rendered, "new_en_1"), qt.Equals, true)
},
},
@@ -503,7 +503,7 @@ func TestMultiSitesRebuild(t *testing.T) {
[]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 := readDestination(t, fs, "public/en/sect/doc1-slug/index.html")
doc1 := readWorkingDir(t, fs, "public/en/sect/doc1-slug/index.html")
c.Assert(strings.Contains(doc1, "CHANGED"), qt.Equals, true)
},
},
@@ -521,7 +521,7 @@ func TestMultiSitesRebuild(t *testing.T) {
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 := readDestination(t, fs, "public/en/new1renamed/index.html")
rendered := readWorkingDir(t, fs, "public/en/new1renamed/index.html")
c.Assert(rendered, qt.Contains, "new_en_1")
},
},
@@ -538,7 +538,7 @@ func TestMultiSitesRebuild(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 := readDestination(t, fs, "public/en/sect/doc1-slug/index.html")
doc1 := readWorkingDir(t, fs, "public/en/sect/doc1-slug/index.html")
c.Assert(strings.Contains(doc1, "Template Changed"), qt.Equals, true)
},
},
@@ -555,9 +555,9 @@ func TestMultiSitesRebuild(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 := readDestination(t, fs, "public/en/sect/doc1-slug/index.html")
docEn := readWorkingDir(t, fs, "public/en/sect/doc1-slug/index.html")
c.Assert(strings.Contains(docEn, "Hello"), qt.Equals, true)
docFr := readDestination(t, fs, "public/fr/sect/doc1/index.html")
docFr := readWorkingDir(t, fs, "public/fr/sect/doc1/index.html")
c.Assert(strings.Contains(docFr, "Salut"), qt.Equals, true)
homeEn := enSite.getPage(page.KindHome)
@@ -700,7 +700,7 @@ END
func checkContent(s *sitesBuilder, filename string, matches ...string) {
s.T.Helper()
content := readDestination(s.T, s.Fs, filename)
content := readWorkingDir(s.T, s.Fs, filename)
for _, match := range matches {
if !strings.Contains(content, match) {
s.Fatalf("No match for\n%q\nin content for %s\n%q\nDiff:\n%s", match, filename, content, htesting.DiffStrings(content, match))
@@ -1170,13 +1170,13 @@ func writeToFs(t testing.TB, fs afero.Fs, filename, content string) {
}
}
func readDestination(t testing.TB, fs *hugofs.Fs, filename string) string {
func readWorkingDir(t testing.TB, fs *hugofs.Fs, filename string) string {
t.Helper()
return readFileFromFs(t, fs.Destination, filename)
return readFileFromFs(t, fs.WorkingDirReadOnly, filename)
}
func destinationExists(fs *hugofs.Fs, filename string) bool {
b, err := helpers.Exists(filename, fs.Destination)
func workingDirExists(fs *hugofs.Fs, filename string) bool {
b, err := helpers.Exists(filename, fs.WorkingDirReadOnly)
if err != nil {
panic(err)
}

View File

@@ -38,7 +38,7 @@ func TestImageOps(t *testing.T) {
defer clean()
newBuilder := func(timeout any) *sitesBuilder {
v := config.New()
v := config.NewWithTestDefaults()
v.Set("workingDir", workDir)
v.Set("baseURL", "https://example.org")
v.Set("timeout", timeout)
@@ -141,7 +141,7 @@ IMG SHORTCODE: /images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_129x239_r
assertImages := func() {
b.Helper()
b.AssertFileContent(filepath.Join(workDir, "public/index.html"), imgExpect)
b.AssertFileContent("public/index.html", imgExpect)
b.AssertImage(350, 219, "public/images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_350x0_resize_q75_box.a86fe88d894e5db613f6aa8a80538fefc25b20fa24ba0d782c057adcef616f56.jpg")
b.AssertImage(129, 239, "public/images/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_129x239_resize_q75_box.jpg")
}

View File

@@ -47,6 +47,8 @@ func NewIntegrationTestBuilder(conf IntegrationTestConfig) *IntegrationTestBuild
if doClean {
c.Cleanup(clean)
}
} else if conf.WorkingDir == "" {
conf.WorkingDir = helpers.FilePathSeparator
}
return &IntegrationTestBuilder{
@@ -157,7 +159,7 @@ func (s *IntegrationTestBuilder) AssertDestinationExists(filename string, b bool
}
func (s *IntegrationTestBuilder) destinationExists(filename string) bool {
b, err := helpers.Exists(filename, s.fs.Destination)
b, err := helpers.Exists(filename, s.fs.PublishDir)
if err != nil {
panic(err)
}
@@ -258,11 +260,7 @@ func (s *IntegrationTestBuilder) RenameFile(old, new string) *IntegrationTestBui
func (s *IntegrationTestBuilder) FileContent(filename string) string {
s.Helper()
filename = filepath.FromSlash(filename)
if !strings.HasPrefix(filename, s.Cfg.WorkingDir) {
filename = filepath.Join(s.Cfg.WorkingDir, filename)
}
return s.readDestination(s, s.fs, filename)
return s.readWorkingDir(s, s.fs, filepath.FromSlash(filename))
}
func (s *IntegrationTestBuilder) initBuilder() {
@@ -280,8 +278,6 @@ func (s *IntegrationTestBuilder) initBuilder() {
logger := loggers.NewBasicLoggerForWriter(s.Cfg.LogLevel, &s.logBuff)
fs := hugofs.NewFrom(afs, config.New())
for _, f := range s.data.Files {
filename := filepath.Join(s.Cfg.WorkingDir, f.Name)
s.Assert(afs.MkdirAll(filepath.Dir(filename), 0777), qt.IsNil)
@@ -301,10 +297,12 @@ func (s *IntegrationTestBuilder) initBuilder() {
},
)
s.Assert(err, qt.IsNil)
cfg.Set("workingDir", s.Cfg.WorkingDir)
fs := hugofs.NewFrom(afs, cfg)
s.Assert(err, qt.IsNil)
depsCfg := deps.DepsCfg{Cfg: cfg, Fs: fs, Running: s.Cfg.Running, Logger: logger}
sites, err := NewHugoSites(depsCfg)
s.Assert(err, qt.IsNil)
@@ -400,9 +398,9 @@ func (s *IntegrationTestBuilder) changeEvents() []fsnotify.Event {
return events
}
func (s *IntegrationTestBuilder) readDestination(t testing.TB, fs *hugofs.Fs, filename string) string {
func (s *IntegrationTestBuilder) readWorkingDir(t testing.TB, fs *hugofs.Fs, filename string) string {
t.Helper()
return s.readFileFromFs(t, fs.Destination, filename)
return s.readFileFromFs(t, fs.WorkingDirReadOnly, filename)
}
func (s *IntegrationTestBuilder) readFileFromFs(t testing.TB, fs afero.Fs, filename string) string {

View File

@@ -224,8 +224,8 @@ Content.
nnSite := b.H.Sites[1]
svSite := b.H.Sites[2]
b.AssertFileContent("/my/project/public/en/mystatic/file1.yaml", "en")
b.AssertFileContent("/my/project/public/nn/mystatic/file1.yaml", "nn")
b.AssertFileContent("public/en/mystatic/file1.yaml", "en")
b.AssertFileContent("public/nn/mystatic/file1.yaml", "nn")
// dumpPages(nnSite.RegularPages()...)
@@ -300,16 +300,16 @@ Content.
c.Assert(len(bundleSv.Resources()), qt.Equals, 4)
c.Assert(len(bundleEn.Resources()), qt.Equals, 4)
b.AssertFileContent("/my/project/public/en/sect/mybundle/index.html", "image/png: /en/sect/mybundle/logo.png")
b.AssertFileContent("/my/project/public/nn/sect/mybundle/index.html", "image/png: /nn/sect/mybundle/logo.png")
b.AssertFileContent("/my/project/public/sv/sect/mybundle/index.html", "image/png: /sv/sect/mybundle/logo.png")
b.AssertFileContent("public/en/sect/mybundle/index.html", "image/png: /en/sect/mybundle/logo.png")
b.AssertFileContent("public/nn/sect/mybundle/index.html", "image/png: /nn/sect/mybundle/logo.png")
b.AssertFileContent("public/sv/sect/mybundle/index.html", "image/png: /sv/sect/mybundle/logo.png")
b.AssertFileContent("/my/project/public/sv/sect/mybundle/featured.png", "PNG Data for sv")
b.AssertFileContent("/my/project/public/nn/sect/mybundle/featured.png", "PNG Data for nn")
b.AssertFileContent("/my/project/public/en/sect/mybundle/featured.png", "PNG Data for en")
b.AssertFileContent("/my/project/public/en/sect/mybundle/logo.png", "PNG Data")
b.AssertFileContent("/my/project/public/sv/sect/mybundle/logo.png", "PNG Data")
b.AssertFileContent("/my/project/public/nn/sect/mybundle/logo.png", "PNG Data")
b.AssertFileContent("public/sv/sect/mybundle/featured.png", "PNG Data for sv")
b.AssertFileContent("public/nn/sect/mybundle/featured.png", "PNG Data for nn")
b.AssertFileContent("public/en/sect/mybundle/featured.png", "PNG Data for en")
b.AssertFileContent("public/en/sect/mybundle/logo.png", "PNG Data")
b.AssertFileContent("public/sv/sect/mybundle/logo.png", "PNG Data")
b.AssertFileContent("public/nn/sect/mybundle/logo.png", "PNG Data")
nnSect := nnSite.getPage(page.KindSection, "sect")
c.Assert(nnSect, qt.Not(qt.IsNil))

View File

@@ -22,7 +22,7 @@ import (
func TestMinifyPublisher(t *testing.T) {
t.Parallel()
v := config.New()
v := config.NewWithTestDefaults()
v.Set("minify", true)
v.Set("baseURL", "https://example.org/")

View File

@@ -101,13 +101,13 @@ Resources: {{ resources.Match "**.js" }}
assertExists := func(name string, shouldExist bool) {
b.Helper()
b.Assert(b.CheckExists(filepath.Join(workingDir, name)), qt.Equals, shouldExist)
b.Assert(b.CheckExists(name), qt.Equals, shouldExist)
}
assertExists("public/a/b/p1/index.html", true)
assertExists("public/a/c/p2/index.html", false)
b.AssertFileContent(filepath.Join(workingDir, "public", "index.html"), `
b.AssertFileContent(filepath.Join("public", "index.html"), `
Data: map[mydata:map[b:map[b1:bval]]]:END
Template: false
Resource1: js/include.js:END

View File

@@ -23,7 +23,6 @@ import (
"time"
"github.com/gohugoio/hugo/htesting"
"github.com/gohugoio/hugo/markup/asciidocext"
"github.com/gohugoio/hugo/markup/rst"
@@ -35,7 +34,6 @@ import (
"github.com/gohugoio/hugo/resources/page"
"github.com/gohugoio/hugo/resources/resource"
"github.com/spf13/afero"
"github.com/spf13/jwalterweatherman"
qt "github.com/frankban/quicktest"
@@ -1031,14 +1029,14 @@ func TestPageWithLastmodFromGitInfo(t *testing.T) {
}
c := qt.New(t)
// We need to use the OS fs for this.
cfg := config.New()
fs := hugofs.NewFrom(hugofs.Os, cfg)
fs.Destination = &afero.MemMapFs{}
wd, err := os.Getwd()
c.Assert(err, qt.IsNil)
// We need to use the OS fs for this.
cfg := config.NewWithTestDefaults()
cfg.Set("workingDir", filepath.Join(wd, "testsite"))
fs := hugofs.NewFrom(hugofs.Os, cfg)
cfg.Set("frontmatter", map[string]any{
"lastmod": []string{":git", "lastmod"},
})
@@ -1060,8 +1058,6 @@ func TestPageWithLastmodFromGitInfo(t *testing.T) {
cfg.Set("languages", langConfig)
cfg.Set("enableGitInfo", true)
cfg.Set("workingDir", filepath.Join(wd, "testsite"))
b := newTestSitesBuilderFromDepsCfg(t, deps.DepsCfg{Fs: fs, Cfg: cfg}).WithNothingAdded()
b.Build(BuildCfg{SkipRender: true})
@@ -1314,7 +1310,7 @@ func TestChompBOM(t *testing.T) {
func TestPageWithEmoji(t *testing.T) {
for _, enableEmoji := range []bool{true, false} {
v := config.New()
v := config.NewWithTestDefaults()
v.Set("enableEmoji", enableEmoji)
b := newTestSitesBuilder(t).WithViper(v)

View File

@@ -127,22 +127,22 @@ func TestPageBundlerSiteRegular(t *testing.T) {
// Check both output formats
rel, filename := relFilename("/a/1/", "index.html")
b.AssertFileContent(filepath.Join("/work/public", filename),
b.AssertFileContent(filepath.Join("public", filename),
"TheContent",
"Single RelPermalink: "+rel,
)
rel, filename = relFilename("/cpath/a/1/", "cindex.html")
b.AssertFileContent(filepath.Join("/work/public", filename),
b.AssertFileContent(filepath.Join("public", filename),
"TheContent",
"Single RelPermalink: "+rel,
)
b.AssertFileContent(filepath.FromSlash("/work/public/images/hugo-logo.png"), "content")
b.AssertFileContent(filepath.FromSlash("public/images/hugo-logo.png"), "content")
// This should be just copied to destination.
b.AssertFileContent(filepath.FromSlash("/work/public/assets/pic1.png"), "content")
b.AssertFileContent(filepath.FromSlash("public/assets/pic1.png"), "content")
leafBundle1 := s.getPage(page.KindPage, "b/my-bundle/index.md")
c.Assert(leafBundle1, qt.Not(qt.IsNil))
@@ -159,8 +159,8 @@ func TestPageBundlerSiteRegular(t *testing.T) {
c.Assert(rootBundle, qt.Not(qt.IsNil))
c.Assert(rootBundle.Parent().IsHome(), qt.Equals, true)
if !ugly {
b.AssertFileContent(filepath.FromSlash("/work/public/root/index.html"), "Single RelPermalink: "+relURLBase+"/root/")
b.AssertFileContent(filepath.FromSlash("/work/public/cpath/root/cindex.html"), "Single RelPermalink: "+relURLBase+"/cpath/root/")
b.AssertFileContent(filepath.FromSlash("public/root/index.html"), "Single RelPermalink: "+relURLBase+"/root/")
b.AssertFileContent(filepath.FromSlash("public/cpath/root/cindex.html"), "Single RelPermalink: "+relURLBase+"/cpath/root/")
}
leafBundle2 := s.getPage(page.KindPage, "a/b/index.md")
@@ -202,17 +202,17 @@ func TestPageBundlerSiteRegular(t *testing.T) {
}
if ugly {
b.AssertFileContent("/work/public/2017/pageslug.html",
b.AssertFileContent("public/2017/pageslug.html",
relPermalinker("Single RelPermalink: %s/2017/pageslug.html"),
permalinker("Single Permalink: %s/2017/pageslug.html"),
relPermalinker("Sunset RelPermalink: %s/2017/pageslug/sunset1.jpg"),
permalinker("Sunset Permalink: %s/2017/pageslug/sunset1.jpg"))
} else {
b.AssertFileContent("/work/public/2017/pageslug/index.html",
b.AssertFileContent("public/2017/pageslug/index.html",
relPermalinker("Sunset RelPermalink: %s/2017/pageslug/sunset1.jpg"),
permalinker("Sunset Permalink: %s/2017/pageslug/sunset1.jpg"))
b.AssertFileContent("/work/public/cpath/2017/pageslug/cindex.html",
b.AssertFileContent("public/cpath/2017/pageslug/cindex.html",
relPermalinker("Single RelPermalink: %s/cpath/2017/pageslug/"),
relPermalinker("Short Sunset RelPermalink: %s/cpath/2017/pageslug/sunset2.jpg"),
relPermalinker("Sunset RelPermalink: %s/cpath/2017/pageslug/sunset1.jpg"),
@@ -220,15 +220,15 @@ func TestPageBundlerSiteRegular(t *testing.T) {
)
}
b.AssertFileContent(filepath.FromSlash("/work/public/2017/pageslug/c/logo.png"), "content")
b.AssertFileContent(filepath.FromSlash("/work/public/cpath/2017/pageslug/c/logo.png"), "content")
c.Assert(b.CheckExists("/work/public/cpath/cpath/2017/pageslug/c/logo.png"), qt.Equals, false)
b.AssertFileContent(filepath.FromSlash("public/2017/pageslug/c/logo.png"), "content")
b.AssertFileContent(filepath.FromSlash("public/cpath/2017/pageslug/c/logo.png"), "content")
c.Assert(b.CheckExists("public/cpath/cpath/2017/pageslug/c/logo.png"), qt.Equals, false)
// Custom media type defined in site config.
c.Assert(len(leafBundle1.Resources().ByType("bepsays")), qt.Equals, 1)
if ugly {
b.AssertFileContent(filepath.FromSlash("/work/public/2017/pageslug.html"),
b.AssertFileContent(filepath.FromSlash("public/2017/pageslug.html"),
"TheContent",
relPermalinker("Sunset RelPermalink: %s/2017/pageslug/sunset1.jpg"),
permalinker("Sunset Permalink: %s/2017/pageslug/sunset1.jpg"),
@@ -247,18 +247,18 @@ func TestPageBundlerSiteRegular(t *testing.T) {
// https://github.com/gohugoio/hugo/issues/5882
b.AssertFileContent(
filepath.FromSlash("/work/public/2017/pageslug.html"), "0: Page RelPermalink: |")
filepath.FromSlash("public/2017/pageslug.html"), "0: Page RelPermalink: |")
b.AssertFileContent(filepath.FromSlash("/work/public/cpath/2017/pageslug.html"), "TheContent")
b.AssertFileContent(filepath.FromSlash("public/cpath/2017/pageslug.html"), "TheContent")
// 은행
b.AssertFileContent(filepath.FromSlash("/work/public/c/은행/logo-은행.png"), "은행 PNG")
b.AssertFileContent(filepath.FromSlash("public/c/은행/logo-은행.png"), "은행 PNG")
} else {
b.AssertFileContent(filepath.FromSlash("/work/public/2017/pageslug/index.html"), "TheContent")
b.AssertFileContent(filepath.FromSlash("/work/public/cpath/2017/pageslug/cindex.html"), "TheContent")
b.AssertFileContent(filepath.FromSlash("/work/public/2017/pageslug/index.html"), "Single Title")
b.AssertFileContent(filepath.FromSlash("/work/public/root/index.html"), "Single Title")
b.AssertFileContent(filepath.FromSlash("public/2017/pageslug/index.html"), "TheContent")
b.AssertFileContent(filepath.FromSlash("public/cpath/2017/pageslug/cindex.html"), "TheContent")
b.AssertFileContent(filepath.FromSlash("public/2017/pageslug/index.html"), "Single Title")
b.AssertFileContent(filepath.FromSlash("public/root/index.html"), "Single Title")
}
})
@@ -397,23 +397,24 @@ func TestPageBundlerSiteWitSymbolicLinksInContent(t *testing.T) {
}()
c := qt.New(t)
// We need to use the OS fs for this.
cfg := config.New()
fs := hugofs.NewFrom(hugofs.Os, cfg)
workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugosym")
// We need to use the OS fs for this.
workingDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugosym")
c.Assert(err, qt.IsNil)
cfg := config.NewWithTestDefaults()
cfg.Set("workingDir", workingDir)
fs := hugofs.NewFrom(hugofs.Os, cfg)
contentDirName := "content"
contentDir := filepath.Join(workDir, contentDirName)
contentDir := filepath.Join(workingDir, contentDirName)
c.Assert(os.MkdirAll(filepath.Join(contentDir, "a"), 0777), qt.IsNil)
for i := 1; i <= 3; i++ {
c.Assert(os.MkdirAll(filepath.Join(workDir, fmt.Sprintf("symcontent%d", i)), 0777), qt.IsNil)
c.Assert(os.MkdirAll(filepath.Join(workingDir, fmt.Sprintf("symcontent%d", i)), 0777), qt.IsNil)
}
c.Assert(os.MkdirAll(filepath.Join(workDir, "symcontent2", "a1"), 0777), qt.IsNil)
c.Assert(os.MkdirAll(filepath.Join(workingDir, "symcontent2", "a1"), 0777), qt.IsNil)
// Symlinked sections inside content.
os.Chdir(contentDir)
@@ -431,11 +432,11 @@ func TestPageBundlerSiteWitSymbolicLinksInContent(t *testing.T) {
// Create a circular symlink. Will print some warnings.
c.Assert(os.Symlink(filepath.Join("..", contentDirName), filepath.FromSlash("circus")), qt.IsNil)
c.Assert(os.Chdir(workDir), qt.IsNil)
c.Assert(os.Chdir(workingDir), qt.IsNil)
defer clean()
cfg.Set("workingDir", workDir)
cfg.Set("workingDir", workingDir)
cfg.Set("contentDir", contentDirName)
cfg.Set("baseURL", "https://example.com")
@@ -488,9 +489,9 @@ TheContent.
c.Assert(len(a1Bundle.Resources()), qt.Equals, 2)
c.Assert(len(a1Bundle.Resources().ByType(pageResourceType)), qt.Equals, 1)
b.AssertFileContent(filepath.FromSlash(workDir+"/public/a/page/index.html"), "TheContent")
b.AssertFileContent(filepath.FromSlash(workDir+"/public/symbolic1/s1/index.html"), "TheContent")
b.AssertFileContent(filepath.FromSlash(workDir+"/public/symbolic2/a1/index.html"), "TheContent")
b.AssertFileContent(filepath.FromSlash("public/a/page/index.html"), "TheContent")
b.AssertFileContent(filepath.FromSlash("public/symbolic1/s1/index.html"), "TheContent")
b.AssertFileContent(filepath.FromSlash("public/symbolic2/a1/index.html"), "TheContent")
}
func TestPageBundlerHeadless(t *testing.T) {
@@ -563,12 +564,12 @@ HEADLESS {{< myShort >}}
th := newTestHelper(s.Cfg, s.Fs, t)
th.assertFileContent(filepath.FromSlash(workDir+"/public/s1/index.html"), "TheContent")
th.assertFileContent(filepath.FromSlash(workDir+"/public/s1/l1.png"), "PNG")
th.assertFileContent(filepath.FromSlash("public/s1/index.html"), "TheContent")
th.assertFileContent(filepath.FromSlash("public/s1/l1.png"), "PNG")
th.assertFileNotExist(workDir + "/public/s2/index.html")
th.assertFileNotExist("public/s2/index.html")
// But the bundled resources needs to be published
th.assertFileContent(filepath.FromSlash(workDir+"/public/s2/l1.png"), "PNG")
th.assertFileContent(filepath.FromSlash("public/s2/l1.png"), "PNG")
// No headless bundles here, please.
// https://github.com/gohugoio/hugo/issues/6492
@@ -1321,7 +1322,7 @@ func TestPageBundlerHome(t *testing.T) {
workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-bundler-home")
c.Assert(err, qt.IsNil)
cfg := config.New()
cfg := config.NewWithTestDefaults()
cfg.Set("workingDir", workDir)
fs := hugofs.NewFrom(hugofs.Os, cfg)

View File

@@ -18,6 +18,8 @@ import (
"path/filepath"
"strings"
hpaths "github.com/gohugoio/hugo/common/paths"
"github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/langs"
"github.com/gohugoio/hugo/modules"
@@ -51,6 +53,7 @@ type Paths struct {
// pagination path handling
PaginatePath string
// TODO1 check usage
PublishDir string
// When in multihost mode, this returns a list of base paths below PublishDir
@@ -123,7 +126,7 @@ func New(fs *hugofs.Fs, cfg config.Provider) (*Paths, error) {
languages = langs.Languages{&langs.Language{Lang: "en", Cfg: cfg, ContentDir: contentDir}}
}
absPublishDir := AbsPathify(workingDir, publishDir)
absPublishDir := hpaths.AbsPathify(workingDir, publishDir)
if !strings.HasSuffix(absPublishDir, FilePathSeparator) {
absPublishDir += FilePathSeparator
}
@@ -131,7 +134,7 @@ func New(fs *hugofs.Fs, cfg config.Provider) (*Paths, error) {
if absPublishDir == "//" {
absPublishDir = FilePathSeparator
}
absResourcesDir := AbsPathify(workingDir, resourceDir)
absResourcesDir := hpaths.AbsPathify(workingDir, resourceDir)
if !strings.HasSuffix(absResourcesDir, FilePathSeparator) {
absResourcesDir += FilePathSeparator
}
@@ -254,7 +257,7 @@ func (p *Paths) GetLangSubDir(lang string) string {
// AbsPathify creates an absolute path if given a relative path. If already
// absolute, the path is just cleaned.
func (p *Paths) AbsPathify(inPath string) string {
return AbsPathify(p.WorkingDir, inPath)
return hpaths.AbsPathify(p.WorkingDir, inPath)
}
// RelPathify trims any WorkingDir prefix from the given filename. If
@@ -267,12 +270,3 @@ func (p *Paths) RelPathify(filename string) string {
return strings.TrimPrefix(strings.TrimPrefix(filename, p.WorkingDir), FilePathSeparator)
}
// AbsPathify creates an absolute path if given a working dir and a relative path.
// If already absolute, the path is just cleaned.
func AbsPathify(workingDir, inPath string) string {
if filepath.IsAbs(inPath) {
return filepath.Clean(inPath)
}
return filepath.Join(workingDir, inPath)
}

View File

@@ -25,7 +25,7 @@ import (
func TestNewPaths(t *testing.T) {
c := qt.New(t)
v := config.New()
v := config.NewWithTestDefaults()
fs := hugofs.NewMem(v)
v.Set("languages", map[string]any{

View File

@@ -137,7 +137,7 @@ Edited content.
`)
b.Assert(b.Fs.Destination.Remove("public"), qt.IsNil)
b.Assert(b.Fs.WorkingDirWritable.Remove("public"), qt.IsNil)
b.H.ResourceSpec.ClearCaches()
}

View File

@@ -28,7 +28,7 @@ const robotTxtTemplate = `User-agent: Googlebot
func TestRobotsTXTOutput(t *testing.T) {
t.Parallel()
cfg := config.New()
cfg := config.NewWithTestDefaults()
cfg.Set("baseURL", "http://auth/bub/")
cfg.Set("enableRobotsTXT", true)

View File

@@ -50,7 +50,7 @@ func TestRSSOutput(t *testing.T) {
th.assertFileContent(filepath.Join("public", "categories", "hugo", rssURI), "<?xml", "rss version", "hugo on RSSTest")
// RSS Item Limit
content := readDestination(t, fs, filepath.Join("public", rssURI))
content := readWorkingDir(t, fs, filepath.Join("public", rssURI))
c := strings.Count(content, "<item>")
if c != rssLimit {
t.Errorf("incorrect RSS item count: expected %d, got %d", rssLimit, c)

View File

@@ -1212,7 +1212,7 @@ title: "Hugo Rocks!"
func TestShortcodeEmoji(t *testing.T) {
t.Parallel()
v := config.New()
v := config.NewWithTestDefaults()
v.Set("enableEmoji", true)
builder := newTestSitesBuilder(t).WithViper(v)
@@ -1277,7 +1277,7 @@ func TestShortcodeRef(t *testing.T) {
t.Run(fmt.Sprintf("plainIDAnchors=%t", plainIDAnchors), func(t *testing.T) {
t.Parallel()
v := config.New()
v := config.NewWithTestDefaults()
v.Set("baseURL", "https://example.org")
v.Set("blackfriday", map[string]any{
"plainIDAnchors": plainIDAnchors,

View File

@@ -363,7 +363,7 @@ func TestCreateSiteOutputFormats(t *testing.T) {
page.KindSection: []string{"JSON"},
}
cfg := config.New()
cfg := config.NewWithTestDefaults()
cfg.Set("outputs", outputsConfig)
outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false)
@@ -388,7 +388,7 @@ func TestCreateSiteOutputFormats(t *testing.T) {
// Issue #4528
t.Run("Mixed case", func(t *testing.T) {
c := qt.New(t)
cfg := config.New()
cfg := config.NewWithTestDefaults()
outputsConfig := map[string]any{
// Note that we in Hugo 0.53.0 renamed this Kind to "taxonomy",
@@ -410,7 +410,7 @@ func TestCreateSiteOutputFormatsInvalidConfig(t *testing.T) {
page.KindHome: []string{"FOO", "JSON"},
}
cfg := config.New()
cfg := config.NewWithTestDefaults()
cfg.Set("outputs", outputsConfig)
_, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false)
@@ -424,7 +424,7 @@ func TestCreateSiteOutputFormatsEmptyConfig(t *testing.T) {
page.KindHome: []string{},
}
cfg := config.New()
cfg := config.NewWithTestDefaults()
cfg.Set("outputs", outputsConfig)
outputs, err := createSiteOutputFormats(output.DefaultFormats, cfg.GetStringMap("outputs"), false)
@@ -439,7 +439,7 @@ func TestCreateSiteOutputFormatsCustomFormats(t *testing.T) {
page.KindHome: []string{},
}
cfg := config.New()
cfg := config.NewWithTestDefaults()
cfg.Set("outputs", outputsConfig)
var (

View File

@@ -336,7 +336,7 @@ func doTestShouldAlwaysHaveUglyURLs(t *testing.T, uglyURLs bool) {
}
for _, test := range tests {
content := readDestination(t, fs, test.doc)
content := readWorkingDir(t, fs, test.doc)
if content != test.expected {
t.Errorf("%s content expected:\n%q\ngot:\n%q", test.doc, test.expected, content)
@@ -362,7 +362,7 @@ func TestMainSections(t *testing.T) {
c := qt.New(t)
for _, paramSet := range []bool{false, true} {
c.Run(fmt.Sprintf("param-%t", paramSet), func(c *qt.C) {
v := config.New()
v := config.NewWithTestDefaults()
if paramSet {
v.Set("params", map[string]any{
"mainSections": []string{"a1", "a2"},

View File

@@ -76,7 +76,7 @@ func TestPageCount(t *testing.T) {
writeSourcesToSource(t, "", fs, urlFakeSource...)
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
_, err := s.Fs.Destination.Open("public/blue")
_, err := s.Fs.WorkingDirReadOnly.Open("public/blue")
if err != nil {
t.Errorf("No indexed rendered.")
}
@@ -87,7 +87,7 @@ func TestPageCount(t *testing.T) {
"public/sd3/index.html",
"public/sd4.html",
} {
if _, err := s.Fs.Destination.Open(filepath.FromSlash(pth)); err != nil {
if _, err := s.Fs.WorkingDirReadOnly.Open(filepath.FromSlash(pth)); err != nil {
t.Errorf("No alias rendered: %s", pth)
}
}

View File

@@ -80,7 +80,7 @@ func doTestSitemapOutput(t *testing.T, internal bool) {
"<loc>http://auth/bub/categories/hugo/</loc>",
)
content := readDestination(th, th.Fs, outputSitemap)
content := readWorkingDir(th, th.Fs, outputSitemap)
c.Assert(content, qt.Not(qt.Contains), "404")
c.Assert(content, qt.Not(qt.Contains), "<loc></loc>")
}

View File

@@ -114,7 +114,7 @@ type filenameContent struct {
}
func newTestSitesBuilder(t testing.TB) *sitesBuilder {
v := config.New()
v := config.NewWithTestDefaults()
fs := hugofs.NewMem(v)
litterOptions := litter.Options{
@@ -475,6 +475,9 @@ func (s *sitesBuilder) CreateSites() *sitesBuilder {
s.Fatalf("Failed to create sites: %s", err)
}
s.Assert(s.Fs.PublishDir, qt.IsNotNil)
s.Assert(s.Fs.WorkingDirReadOnly, qt.IsNotNil)
return s
}
@@ -536,7 +539,7 @@ func (s *sitesBuilder) CreateSitesE() error {
return errors.Wrap(err, "failed to load config")
}
s.Fs.Destination = hugofs.NewCreateCountingFs(s.Fs.Destination)
s.Fs.PublishDir = hugofs.NewCreateCountingFs(s.Fs.PublishDir)
depsCfg := s.depsCfg
depsCfg.Fs = s.Fs
@@ -759,8 +762,7 @@ func (s *sitesBuilder) AssertFileDoesNotExist(filename string) {
}
func (s *sitesBuilder) AssertImage(width, height int, filename string) {
filename = filepath.Join(s.workingDir, filename)
f, err := s.Fs.Destination.Open(filename)
f, err := s.Fs.WorkingDirReadOnly.Open(filename)
s.Assert(err, qt.IsNil)
defer f.Close()
cfg, err := jpeg.DecodeConfig(f)
@@ -771,17 +773,14 @@ func (s *sitesBuilder) AssertImage(width, height int, filename string) {
func (s *sitesBuilder) AssertNoDuplicateWrites() {
s.Helper()
d := s.Fs.Destination.(hugofs.DuplicatesReporter)
d := s.Fs.PublishDir.(hugofs.DuplicatesReporter)
s.Assert(d.ReportDuplicates(), qt.Equals, "")
}
func (s *sitesBuilder) FileContent(filename string) string {
s.T.Helper()
s.Helper()
filename = filepath.FromSlash(filename)
if !strings.HasPrefix(filename, s.workingDir) {
filename = filepath.Join(s.workingDir, filename)
}
return readDestination(s.T, s.Fs, filename)
return readWorkingDir(s.T, s.Fs, filename)
}
func (s *sitesBuilder) AssertObject(expected string, object any) {
@@ -797,7 +796,7 @@ func (s *sitesBuilder) AssertObject(expected string, object any) {
}
func (s *sitesBuilder) AssertFileContentRe(filename string, matches ...string) {
content := readDestination(s.T, s.Fs, filename)
content := readWorkingDir(s.T, s.Fs, filename)
for _, match := range matches {
r := regexp.MustCompile("(?s)" + match)
if !r.MatchString(content) {
@@ -807,7 +806,7 @@ func (s *sitesBuilder) AssertFileContentRe(filename string, matches ...string) {
}
func (s *sitesBuilder) CheckExists(filename string) bool {
return destinationExists(s.Fs, filepath.Clean(filename))
return workingDirExists(s.Fs, filepath.Clean(filename))
}
func (s *sitesBuilder) GetPage(ref string) page.Page {
@@ -848,7 +847,7 @@ type testHelper struct {
func (th testHelper) assertFileContent(filename string, matches ...string) {
th.Helper()
filename = th.replaceDefaultContentLanguageValue(filename)
content := readDestination(th, th.Fs, filename)
content := readWorkingDir(th, th.Fs, filename)
for _, match := range matches {
match = th.replaceDefaultContentLanguageValue(match)
th.Assert(strings.Contains(content, match), qt.Equals, true, qt.Commentf(match+" not in: \n"+content))
@@ -857,7 +856,7 @@ func (th testHelper) assertFileContent(filename string, matches ...string) {
func (th testHelper) assertFileContentRegexp(filename string, matches ...string) {
filename = th.replaceDefaultContentLanguageValue(filename)
content := readDestination(th, th.Fs, filename)
content := readWorkingDir(th, th.Fs, filename)
for _, match := range matches {
match = th.replaceDefaultContentLanguageValue(match)
r := regexp.MustCompile(match)
@@ -870,7 +869,7 @@ func (th testHelper) assertFileContentRegexp(filename string, matches ...string)
}
func (th testHelper) assertFileNotExist(filename string) {
exists, err := helpers.Exists(filename, th.Fs.Destination)
exists, err := helpers.Exists(filename, th.Fs.PublishDir)
th.Assert(err, qt.IsNil)
th.Assert(exists, qt.Equals, false)
}
@@ -892,7 +891,7 @@ func loadTestConfig(fs afero.Fs, withConfig ...func(cfg config.Provider) error)
func newTestCfgBasic() (config.Provider, *hugofs.Fs) {
mm := afero.NewMemMapFs()
v := config.New()
v := config.NewWithTestDefaults()
v.Set("defaultContentLanguageInSubdir", true)
fs := hugofs.NewFrom(hugofs.NewBaseFileDecorator(mm), v)