Fix bundle resource ordering regression
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 9 Feb 2020 13:17:47 +0000 (14:17 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 9 Feb 2020 20:35:39 +0000 (21:35 +0100)
Introduced in Hugo 0.64.0

Fixes #6851

hugofs/fileinfo.go
hugofs/rootmapping_fs.go
hugolib/pagebundler_test.go

index 0f20ec3860c4df10e3c2a688bdb764fa0505c62a..255295b7540a9466e80d5ae5499601805c7b63b4 100644 (file)
@@ -272,7 +272,7 @@ func (fi *dirNameOnlyFileInfo) Sys() interface{} {
        return nil
 }
 
-func newDirNameOnlyFileInfo(name string, meta FileMeta, isOrdered bool, fileOpener func() (afero.File, error)) FileMetaInfo {
+func newDirNameOnlyFileInfo(name string, meta FileMeta, fileOpener func() (afero.File, error)) FileMetaInfo {
        name = normalizeFilename(name)
        _, base := filepath.Split(name)
 
@@ -281,7 +281,7 @@ func newDirNameOnlyFileInfo(name string, meta FileMeta, isOrdered bool, fileOpen
                m.setIfNotZero(metaKeyFilename, name)
        }
        m[metaKeyOpener] = fileOpener
-       m[metaKeyIsOrdered] = isOrdered
+       m[metaKeyIsOrdered] = false
 
        return NewFileMetaInfo(
                &dirNameOnlyFileInfo{name: base},
index ea8b7e04d5be22b4e6aa75a663c4f05358c69d7d..26d6ffa3c9b031cf532de9346306eec553f49b00 100644 (file)
@@ -367,7 +367,7 @@ func (fs *RootMappingFs) collectDirEntries(prefix string) ([]os.FileInfo, error)
                                opener := func() (afero.File, error) {
                                        return fs.Open(filepath.Join(rm.From, name))
                                }
-                               fi = newDirNameOnlyFileInfo(name, meta, false, opener)
+                               fi = newDirNameOnlyFileInfo(name, meta, opener)
                        }
 
                        fis = append(fis, fi)
@@ -396,7 +396,7 @@ func (fs *RootMappingFs) collectDirEntries(prefix string) ([]os.FileInfo, error)
                                return fs.Open(path)
                        }
 
-                       fi := newDirNameOnlyFileInfo(name, nil, false, opener)
+                       fi := newDirNameOnlyFileInfo(name, nil, opener)
                        fis = append(fis, fi)
 
                        return false
@@ -419,7 +419,7 @@ func (fs *RootMappingFs) collectDirEntries(prefix string) ([]os.FileInfo, error)
                                return fs.Open(rm.From)
                        }
 
-                       fi := newDirNameOnlyFileInfo(name, rm.Meta, false, opener)
+                       fi := newDirNameOnlyFileInfo(name, rm.Meta, opener)
 
                        fis = append(fis, fi)
 
@@ -441,7 +441,7 @@ func (fs *RootMappingFs) doLstat(name string) ([]FileMetaInfo, error) {
                if fs.hasPrefix(key) {
                        // We have directories mounted below this.
                        // Make it look like a directory.
-                       return []FileMetaInfo{newDirNameOnlyFileInfo(name, nil, true, fs.virtualDirOpener(name))}, nil
+                       return []FileMetaInfo{newDirNameOnlyFileInfo(name, nil, fs.virtualDirOpener(name))}, nil
                }
 
                // Find any real files or directories with this key.
@@ -484,7 +484,7 @@ func (fs *RootMappingFs) doLstat(name string) ([]FileMetaInfo, error) {
 
        if fileCount == 0 {
                // Dir only.
-               return []FileMetaInfo{newDirNameOnlyFileInfo(name, roots[0].Meta, true, fs.virtualDirOpener(name))}, nil
+               return []FileMetaInfo{newDirNameOnlyFileInfo(name, roots[0].Meta, fs.virtualDirOpener(name))}, nil
        }
 
        if fileCount > 1 {
index eeed51b91c031f15d88de7242674c59558dc1816..62b041d7c74efa6bb7679b0b3981f6474a24108c 100644 (file)
@@ -1336,3 +1336,35 @@ bundle min min key: {{ $jsonMinMin.Key }}
 
        }
 }
+
+func TestPageBundlerHome(t *testing.T) {
+       t.Parallel()
+       c := qt.New(t)
+
+       workDir, clean, err := htesting.CreateTempDir(hugofs.Os, "hugo-bundler-home")
+       c.Assert(err, qt.IsNil)
+
+       cfg := viper.New()
+       cfg.Set("workingDir", workDir)
+       fs := hugofs.NewFrom(hugofs.Os, cfg)
+
+       os.MkdirAll(filepath.Join(workDir, "content"), 0777)
+
+       defer clean()
+
+       b := newTestSitesBuilder(t)
+       b.Fs = fs
+
+       b.WithWorkingDir(workDir).WithViper(cfg)
+
+       b.WithContent("_index.md", "---\ntitle: Home\n---\n![Alt text](image.jpg)")
+       b.WithSourceFile("content/data.json", "DATA")
+
+       b.WithTemplates("index.html", `Title: {{ .Title }}|First Resource: {{ index .Resources 0 }}|Content: {{ .Content }}`)
+       b.WithTemplates("_default/_markup/render-image.html", `Hook Len Page Resources {{ len .Page.Resources }}`)
+
+       b.Build(BuildCfg{})
+       b.AssertFileContent("public/index.html", `
+Title: Home|First Resource: data.json|Content: <p>Hook Len Page Resources 1</p>
+`)
+}