]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
hugolib: Don't render default site redirect for non-primary isHTML output formats
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 8 Feb 2026 15:20:24 +0000 (16:20 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 8 Feb 2026 16:35:32 +0000 (17:35 +0100)
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>
hugolib/alias_test.go
hugolib/site_render.go

index 320ca7dd74d4831cd90c20b1aa77aa2d2aedf33e..2867ca10b5e2ac009068ed852dc342cb0fa0ab0b 100644 (file)
@@ -683,3 +683,69 @@ Home.
                "/guest/v1.0.0/en/p3                =>/guest/v1.0.0/en/foo/p1/|",
        )
 }
+
+// Issue 14482
+func TestOutputFormatIsHTMLWithMultilangAliases(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- hugo.toml --
+defaultContentLanguageInSubdir = true
+disableKinds = ['page', 'section', 'rss', 'sitemap', 'taxonomy', 'term']
+
+[languages.en]
+[languages.de]
+
+[outputFormats.foo]
+baseName = 'foo'
+isHTML = false
+mediaType = 'text/html'
+
+[outputs]
+home = ['html', 'foo']
+-- content/index.de.md --
+---
+title: home de
+---
+-- content/index.en.md --
+---
+title: home en
+---
+-- layouts/home.html --
+Output format: html|Title: {{ .Title }}
+-- layouts/home.foo.html --
+Output format: foo|Title: {{ .Title }}
+`
+
+       b := Test(t, files)
+
+       b.AssertFileContent("public/en/index.html", `Output format: html|Title: home en`)
+       b.AssertFileContent("public/en/foo.html", `Output format: foo|Title: home en`)
+       b.AssertFileContent("public/de/index.html", `Output format: html|Title: home de`)
+       b.AssertFileContent("public/de/foo.html", `Output format: foo|Title: home de`)
+       b.AssertFileContent("public/index.html", `
+<head>
+  <title>/en/</title>
+  <link rel="canonical" href="/en/">
+  <meta charset="utf-8">
+  <meta http-equiv="refresh" content="0; url=/en/">
+</head>
+       `)
+
+       files = strings.ReplaceAll(files, "isHTML = false", "isHTML = true")
+
+       b = Test(t, files)
+
+       b.AssertFileContent("public/en/index.html", `Output format: html|Title: home en`)
+       b.AssertFileContent("public/en/foo.html", `Output format: foo|Title: home en`)
+       b.AssertFileContent("public/de/index.html", `Output format: html|Title: home de`)
+       b.AssertFileContent("public/de/foo.html", `Output format: foo|Title: home de`)
+       b.AssertFileContent("public/index.html", `
+<head>
+  <title>/en/</title>
+  <link rel="canonical" href="/en/">
+  <meta charset="utf-8">
+  <meta http-equiv="refresh" content="0; url=/en/">
+</head>
+       `)
+}
index c482e61ceaef02641f2da904200f7a3ae14b38f2..2da329255405154b4507c1f9c467d891989eb990 100644 (file)
@@ -217,7 +217,7 @@ func pageRenderer(
                        }
                }
 
-               if p.IsHome() && p.outputFormat().IsHTML && s.isDefault() {
+               if of := p.outputFormat(); p.IsHome() && of.IsHTML && s.isDefault() && (of.Path != "" || of.Name == "html") {
                        if err = s.renderDefaultSiteRedirect(p); err != nil {
                                if sendErr(err) {
                                        continue