Skip to content

Resource Permalink returns incorrect base URL with multihost site #12560

@jmooring

Description

@jmooring

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

func TestIssue12560(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/home.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 }}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions