Skip to content

Commit 6ac7d08

Browse files
bepjmooringclaude
committed
hugolib: Don't render default site redirect for non-primary isHTML output formats
When a custom output format has isHTML=true but no Path, renderDefaultSiteRedirect would derive intermediate redirect paths from homeLink (e.g. /en/foo.html), creating a spurious redirect at /en/ that overwrites the actual HTML content. Only render the default site redirect for the canonical "html" format or for formats with their own Path prefix (e.g. AMP). Fixes #14482 Co-Authored-By: Joe Mooring <joe.mooring@veriphor.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 24eb84f commit 6ac7d08

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

hugolib/alias_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,3 +683,69 @@ Home.
683683
"/guest/v1.0.0/en/p3 =>/guest/v1.0.0/en/foo/p1/|",
684684
)
685685
}
686+
687+
// Issue 14482
688+
func TestOutputFormatIsHTMLWithMultilangAliases(t *testing.T) {
689+
t.Parallel()
690+
691+
files := `
692+
-- hugo.toml --
693+
defaultContentLanguageInSubdir = true
694+
disableKinds = ['page', 'section', 'rss', 'sitemap', 'taxonomy', 'term']
695+
696+
[languages.en]
697+
[languages.de]
698+
699+
[outputFormats.foo]
700+
baseName = 'foo'
701+
isHTML = false
702+
mediaType = 'text/html'
703+
704+
[outputs]
705+
home = ['html', 'foo']
706+
-- content/index.de.md --
707+
---
708+
title: home de
709+
---
710+
-- content/index.en.md --
711+
---
712+
title: home en
713+
---
714+
-- layouts/home.html --
715+
Output format: html|Title: {{ .Title }}
716+
-- layouts/home.foo.html --
717+
Output format: foo|Title: {{ .Title }}
718+
`
719+
720+
b := Test(t, files)
721+
722+
b.AssertFileContent("public/en/index.html", `Output format: html|Title: home en`)
723+
b.AssertFileContent("public/en/foo.html", `Output format: foo|Title: home en`)
724+
b.AssertFileContent("public/de/index.html", `Output format: html|Title: home de`)
725+
b.AssertFileContent("public/de/foo.html", `Output format: foo|Title: home de`)
726+
b.AssertFileContent("public/index.html", `
727+
<head>
728+
<title>/en/</title>
729+
<link rel="canonical" href="/en/">
730+
<meta charset="utf-8">
731+
<meta http-equiv="refresh" content="0; url=/en/">
732+
</head>
733+
`)
734+
735+
files = strings.ReplaceAll(files, "isHTML = false", "isHTML = true")
736+
737+
b = Test(t, files)
738+
739+
b.AssertFileContent("public/en/index.html", `Output format: html|Title: home en`)
740+
b.AssertFileContent("public/en/foo.html", `Output format: foo|Title: home en`)
741+
b.AssertFileContent("public/de/index.html", `Output format: html|Title: home de`)
742+
b.AssertFileContent("public/de/foo.html", `Output format: foo|Title: home de`)
743+
b.AssertFileContent("public/index.html", `
744+
<head>
745+
<title>/en/</title>
746+
<link rel="canonical" href="/en/">
747+
<meta charset="utf-8">
748+
<meta http-equiv="refresh" content="0; url=/en/">
749+
</head>
750+
`)
751+
}

hugolib/site_render.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func pageRenderer(
217217
}
218218
}
219219

220-
if p.IsHome() && p.outputFormat().IsHTML && s.isDefault() {
220+
if of := p.outputFormat(); p.IsHome() && of.IsHTML && s.isDefault() && (of.Path != "" || of.Name == "html") {
221221
if err = s.renderDefaultSiteRedirect(p); err != nil {
222222
if sendErr(err) {
223223
continue

0 commit comments

Comments
 (0)