mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Fix for data mounts in sub folders
Before this change, data files from Hugo modules were always mounted at the root of the `data` directory. The File and FileMetaInfo structs for modules are different from 'native' data directories. This changes how the keyParts for data files are generated so that data from modules or native directories are treated the same.
This commit is contained in:
parent
79f15be5b0
commit
286821e360
2 changed files with 34 additions and 3 deletions
|
@ -1178,3 +1178,32 @@ target = "content/resources-b"
|
||||||
b.AssertFileContent("public/resources-a/subdir/about/index.html", "Single")
|
b.AssertFileContent("public/resources-a/subdir/about/index.html", "Single")
|
||||||
b.AssertFileContent("public/resources-b/subdir/about/index.html", "Single")
|
b.AssertFileContent("public/resources-b/subdir/about/index.html", "Single")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMountData(t *testing.T) {
|
||||||
|
files := `
|
||||||
|
-- hugo.toml --
|
||||||
|
baseURL = 'https://example.org/'
|
||||||
|
disableKinds = ["taxonomy", "term", "RSS", "sitemap", "robotsTXT", "page", "section"]
|
||||||
|
|
||||||
|
[[module.mounts]]
|
||||||
|
source = "data"
|
||||||
|
target = "data"
|
||||||
|
|
||||||
|
[[module.mounts]]
|
||||||
|
source = "extra-data"
|
||||||
|
target = "data/extra"
|
||||||
|
-- extra-data/test.yaml --
|
||||||
|
message: Hugo Rocks
|
||||||
|
-- layouts/index.html --
|
||||||
|
{{ site.Data.extra.test.message }}
|
||||||
|
`
|
||||||
|
|
||||||
|
b := NewIntegrationTestBuilder(
|
||||||
|
IntegrationTestConfig{
|
||||||
|
T: t,
|
||||||
|
TxtarString: files,
|
||||||
|
},
|
||||||
|
).Build()
|
||||||
|
|
||||||
|
b.AssertFileContent("public/index.html", "Hugo Rocks")
|
||||||
|
}
|
||||||
|
|
|
@ -555,13 +555,14 @@ func (h *HugoSites) loadData(fis []hugofs.FileMetaInfo) (err error) {
|
||||||
|
|
||||||
h.data = make(map[string]any)
|
h.data = make(map[string]any)
|
||||||
for _, fi := range fis {
|
for _, fi := range fis {
|
||||||
|
basePath := fi.Meta().Path
|
||||||
fileSystem := spec.NewFilesystemFromFileMetaInfo(fi)
|
fileSystem := spec.NewFilesystemFromFileMetaInfo(fi)
|
||||||
files, err := fileSystem.Files()
|
files, err := fileSystem.Files()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, r := range files {
|
for _, r := range files {
|
||||||
if err := h.handleDataFile(r); err != nil {
|
if err := h.handleDataFile(basePath, r); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -570,7 +571,7 @@ func (h *HugoSites) loadData(fis []hugofs.FileMetaInfo) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HugoSites) handleDataFile(r source.File) error {
|
func (h *HugoSites) handleDataFile(basePath string, r source.File) error {
|
||||||
var current map[string]any
|
var current map[string]any
|
||||||
|
|
||||||
f, err := r.FileInfo().Meta().Open()
|
f, err := r.FileInfo().Meta().Open()
|
||||||
|
@ -581,7 +582,8 @@ func (h *HugoSites) handleDataFile(r source.File) error {
|
||||||
|
|
||||||
// Crawl in data tree to insert data
|
// Crawl in data tree to insert data
|
||||||
current = h.data
|
current = h.data
|
||||||
keyParts := strings.Split(r.Dir(), helpers.FilePathSeparator)
|
dataPath := filepath.Join(basePath, r.Dir())
|
||||||
|
keyParts := strings.Split(dataPath, helpers.FilePathSeparator)
|
||||||
|
|
||||||
for _, key := range keyParts {
|
for _, key := range keyParts {
|
||||||
if key != "" {
|
if key != "" {
|
||||||
|
|
Loading…
Reference in a new issue