Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Site.Data falls back to assets/data when data directory not present in project root #12133

Closed
jmooring opened this issue Feb 23, 2024 · 3 comments

Comments

@jmooring
Copy link
Member

jmooring commented Feb 23, 2024

Works as expected with v0.122.0.
Tested with hugo v0.124.0-DEV-7508a16.

my-project/
├── assets/
│   └── data/          <-- .Site.Data is reading this directory
│       └── foo.toml
├── content/
│   └── _index.md
├── layouts/
│   └── index.html
└── hugo.toml
failing test case
func TestFoo(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 := hugolib.Test(t, files)

	b.AssertFileContent("public/index.html", "||")
}

Reference: https://discourse.gohugo.io/t/unable-to-load-text-file-from-global-resource/48365

@jmooring
Copy link
Member Author

We uncovered this problem when assets/data contained a text file (there's nothing wrong with that), resulting in this error when calling .Site.Data

Error: error building site: failed to load data: failed to load data: "/home/user/project/assets/data/foo.txt:1:1": unmarshal of format "" is not supported

@bep bep self-assigned this Feb 28, 2024
@bep bep added this to the v0.123.5 milestone Feb 28, 2024
bep added a commit to bep/hugo that referenced this issue Feb 28, 2024
And possibly some other related file mount issues.

Fixes gohugoio#12133
@bep
Copy link
Member

bep commented Feb 28, 2024

Apologise a little for not fixing this sooner, I have fixed issues in a "first see" order, so to speak, and didn't see this until today. I have a fix on its way.

@bep bep closed this as completed in 4a502f7 Feb 28, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants