Fix assets vs data issue

And possibly some other related file mount issues.

Fixes #12133
This commit is contained in:
Bjørn Erik Pedersen 2024-02-28 17:58:27 +01:00
parent be1dbba0f7
commit 4a502f7eb4
2 changed files with 19 additions and 4 deletions

View file

@ -43,7 +43,6 @@ var _ ReverseLookupProvder = (*RootMappingFs)(nil)
func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error) { func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error) {
rootMapToReal := radix.New() rootMapToReal := radix.New()
realMapToRoot := radix.New() realMapToRoot := radix.New()
var virtualRoots []RootMapping
addMapping := func(key string, rm RootMapping, to *radix.Tree) { addMapping := func(key string, rm RootMapping, to *radix.Tree) {
var mappings []RootMapping var mappings []RootMapping
@ -154,11 +153,8 @@ func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error) {
addMapping(rev, rm, realMapToRoot) addMapping(rev, rm, realMapToRoot)
virtualRoots = append(virtualRoots, rm)
} }
rootMapToReal.Insert(filepathSeparator, virtualRoots)
rfs := &RootMappingFs{ rfs := &RootMappingFs{
Fs: fs, Fs: fs,
rootMapToReal: rootMapToReal, rootMapToReal: rootMapToReal,
@ -414,6 +410,7 @@ func (fs *RootMappingFs) getRoots(key string) (string, []RootMapping) {
for { for {
var found bool var found bool
ss, vv, found := tree.LongestPrefix(key) ss, vv, found := tree.LongestPrefix(key)
if !found || (levels < 2 && ss == key) { if !found || (levels < 2 && ss == key) {
break break
} }

View file

@ -64,3 +64,21 @@ v1: {{ site.Data.MyFolder.MyData.v1 }}|
b.AssertFileContent("public/index.html", "v1: my_v1|") b.AssertFileContent("public/index.html", "v1: my_v1|")
} }
// Issue #12133
func TestDataNoAssets(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
-- assets/data/foo.toml --
content = "I am assets/data/foo.toml"
-- layouts/index.html --
|{{ site.Data.foo.content }}|
`
b := Test(t, files)
b.AssertFileContent("public/index.html", "||")
}