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

Resource Permalink returns incorrect base URL with multihost site #12560

Open
jmooring opened this issue Jun 1, 2024 · 3 comments
Open

Resource Permalink returns incorrect base URL with multihost site #12560

jmooring opened this issue Jun 1, 2024 · 3 comments

Comments

@jmooring
Copy link
Member

jmooring commented Jun 1, 2024

This isn't anything new. I am able to reproduce with v0.54.0 and later.

func TestFoo(t *testing.T) {
	t.Parallel()

	files := `
-- hugo.toml --
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
[languages.en]
baseURL = 'https://en.example.org/'
weight = 1
[languages.de]
baseURL = 'https://de.example.org/'
weight = 2
-- layouts/index.html --
{{ with resources.Get "main.css" }}{{ .Permalink }}{{ end }}
-- assets/main.css --
body {color: red;}
`

	b := hugolib.Test(t, files)

	b.AssertFileContent("public/en/main.css", "body {color: red;}")
	b.AssertFileContent("public/en/index.html", "https://en.example.org/main.css")
	b.AssertFileContent("public/de/main.css", "body {color: red;}")
	b.AssertFileContent("public/de/index.html", "https://de.example.org/main.css") // fails
}

The last assertion fails; the file is identical to public/en/index.html, which means it's pointing to the wrong site.

Reference: https://discourse.gohugo.io/t/multihost-trouble/50103

The work around is to use RelPermalink instead:

{{ with resources.Get "main.css" }}
  {{ .RelPermalink }}
{{ end }}
dholbach added a commit to dholbach/hugo-scroll that referenced this issue Jun 1, 2024
zjedi pushed a commit to zjedi/hugo-scroll that referenced this issue Jun 1, 2024
@bep bep removed the NeedsTriage label Jun 2, 2024
@bep bep added this to the v0.127.0 milestone Jun 2, 2024
@adityatelange
Copy link

@bep bep added the NotSure label Jun 3, 2024
@bep
Copy link
Member

bep commented Jun 3, 2024

Thinking back, I'm not sure I would label this as a bug. Resources inside /assets are considered global and we have never had any concept of "duplicating resources from assets" across languages. So, I think this is "as designed" -- whether the design is great, that cold be debated.

@jmooring
Copy link
Member Author

jmooring commented Jun 3, 2024

In a multihost configuration we are duplicating resources from assets across languages. The test case above produces this:

public/
├── de/
│   ├── index.html
│   └── main.css
└── en/
    ├── index.html
    └── main.css

The problem is that, for one of the sites, the .Permalink method points to the wrong place.

@bep bep modified the milestones: v0.127.0, v0.128.0 Jun 8, 2024
@bep bep modified the milestones: v0.128.0, v0.129.0 Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants