]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
hugolib: Emit ignorable warning when home page is a leaf bundle
authorJoe Mooring <joe.mooring@veriphor.com>
Fri, 6 Jun 2025 20:21:41 +0000 (13:21 -0700)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 7 Jun 2025 11:02:28 +0000 (13:02 +0200)
Closes #13538

Dockerfile
common/constants/constants.go
hugolib/page__new.go
hugolib/page_test.go

index e35fd4958b95d49807ce529fe477c51f3da0c2ad..a0e34353ffe9db0fac743dd64029c20f55abe848 100755 (executable)
@@ -2,7 +2,7 @@
 # Twitter:      https://twitter.com/gohugoio
 # Website:      https://gohugo.io/
 
-ARG GO_VERSION="1.24.0"
+ARG GO_VERSION="1.24"
 ARG ALPINE_VERSION="3.22"
 ARG DART_SASS_VERSION="1.79.3"
 
@@ -19,7 +19,7 @@ RUN apk add clang lld
 COPY --from=xx / /
 
 ARG TARGETPLATFORM
-RUN xx-apk add musl-dev gcc g++ 
+RUN xx-apk add musl-dev gcc g++
 
 # Optionally set HUGO_BUILD_TAGS to "none" or "withdeploy" when building like so:
 # docker build --build-arg HUGO_BUILD_TAGS=withdeploy .
@@ -72,7 +72,7 @@ RUN mkdir -p /var/hugo/bin /cache && \
     adduser -Sg hugo -u 1000 -h /var/hugo hugo && \
     chown -R hugo: /var/hugo /cache && \
     # For the Hugo's Git integration to work.
-    runuser -u hugo -- git config --global --add safe.directory /project && \ 
+    runuser -u hugo -- git config --global --add safe.directory /project && \
     # See https://github.com/gohugoio/hugo/issues/9810
     runuser -u hugo -- git config --global core.quotepath false
 
index 3f48f3e4abb5086ab0ea654d632046a792cebcf9..c7bbaa5412752e16fdb8a0bd59f29b163d256402 100644 (file)
@@ -24,6 +24,7 @@ const (
        WarnRenderShortcodesInHTML     = "warning-rendershortcodes-in-html"
        WarnGoldmarkRawHTML            = "warning-goldmark-raw-html"
        WarnPartialSuperfluousPrefix   = "warning-partial-superfluous-prefix"
+       WarnHomePageIsLeafBundle       = "warning-home-page-is-leaf-bundle"
 )
 
 // Field/method names with special meaning.
index 9d05abea6b5eb2c2b7d14e18cf2205003ab677ca..80115cc727dfa7cef0fb9b631f44c22c1c6b0ea0 100644 (file)
@@ -21,6 +21,7 @@ import (
        "github.com/gohugoio/hugo/hugofs/files"
        "github.com/gohugoio/hugo/resources"
 
+       "github.com/gohugoio/hugo/common/constants"
        "github.com/gohugoio/hugo/common/maps"
        "github.com/gohugoio/hugo/common/paths"
 
@@ -39,6 +40,14 @@ func (h *HugoSites) newPage(m *pageMeta) (*pageState, *paths.Path, error) {
                // Make sure that any partially created page part is marked as stale.
                m.MarkStale()
        }
+
+       if p != nil && pth != nil && p.IsHome() && pth.IsLeafBundle() {
+               msg := "Using %s in your content's root directory is usually incorrect for your home page. "
+               msg += "You should use %s instead. If you don't rename this file, your home page will be "
+               msg += "treated as a leaf bundle, meaning it won't be able to have any child pages or sections."
+               h.Log.Warnidf(constants.WarnHomePageIsLeafBundle, msg, pth.PathNoLeadingSlash(), strings.ReplaceAll(pth.PathNoLeadingSlash(), "index", "_index"))
+       }
+
        return p, pth, err
 }
 
index 0fec397e0d82caf3dc9266a22d393b6acf124902..1da67e58f56e11274336b3bbde2d3a15b1d4389c 100644 (file)
@@ -1968,3 +1968,35 @@ Title: {{ .Title }}
                "deprecated: path in front matter was deprecated",
        )
 }
+
+// Issue 13538
+func TestHomePageIsLeafBundle(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- hugo.toml --
+defaultContentLanguage = 'de'
+defaultContentLanguageInSubdir = true
+[languages.de]
+weight = 1
+[languages.en]
+weight = 2
+-- layouts/all.html --
+{{ .Title }}
+-- content/index.de.md --
+---
+title: home de
+---
+-- content/index.en.org --
+---
+title: home en
+---
+`
+
+       b := Test(t, files, TestOptWarn())
+
+       b.AssertFileContent("public/de/index.html", "home de")
+       b.AssertFileContent("public/en/index.html", "home en")
+       b.AssertLogContains("Using index.de.md in your content's root directory is usually incorrect for your home page. You should use _index.de.md instead.")
+       b.AssertLogContains("Using index.en.org in your content's root directory is usually incorrect for your home page. You should use _index.en.org instead.")
+}