Skip to content

Commit 01241d5

Browse files
jmooringbep
authored andcommitted
hugolib: Emit ignorable warning when home page is a leaf bundle
Closes #13538
1 parent 8e61f1f commit 01241d5

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Twitter: https://twitter.com/gohugoio
33
# Website: https://gohugo.io/
44

5-
ARG GO_VERSION="1.24.0"
5+
ARG GO_VERSION="1.24"
66
ARG ALPINE_VERSION="3.22"
77
ARG DART_SASS_VERSION="1.79.3"
88

@@ -19,7 +19,7 @@ RUN apk add clang lld
1919
COPY --from=xx / /
2020

2121
ARG TARGETPLATFORM
22-
RUN xx-apk add musl-dev gcc g++
22+
RUN xx-apk add musl-dev gcc g++
2323

2424
# Optionally set HUGO_BUILD_TAGS to "none" or "withdeploy" when building like so:
2525
# docker build --build-arg HUGO_BUILD_TAGS=withdeploy .
@@ -72,7 +72,7 @@ RUN mkdir -p /var/hugo/bin /cache && \
7272
adduser -Sg hugo -u 1000 -h /var/hugo hugo && \
7373
chown -R hugo: /var/hugo /cache && \
7474
# For the Hugo's Git integration to work.
75-
runuser -u hugo -- git config --global --add safe.directory /project && \
75+
runuser -u hugo -- git config --global --add safe.directory /project && \
7676
# See https://github.com/gohugoio/hugo/issues/9810
7777
runuser -u hugo -- git config --global core.quotepath false
7878

common/constants/constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const (
2424
WarnRenderShortcodesInHTML = "warning-rendershortcodes-in-html"
2525
WarnGoldmarkRawHTML = "warning-goldmark-raw-html"
2626
WarnPartialSuperfluousPrefix = "warning-partial-superfluous-prefix"
27+
WarnHomePageIsLeafBundle = "warning-home-page-is-leaf-bundle"
2728
)
2829

2930
// Field/method names with special meaning.

hugolib/page__new.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/gohugoio/hugo/hugofs/files"
2222
"github.com/gohugoio/hugo/resources"
2323

24+
"github.com/gohugoio/hugo/common/constants"
2425
"github.com/gohugoio/hugo/common/maps"
2526
"github.com/gohugoio/hugo/common/paths"
2627

@@ -39,6 +40,14 @@ func (h *HugoSites) newPage(m *pageMeta) (*pageState, *paths.Path, error) {
3940
// Make sure that any partially created page part is marked as stale.
4041
m.MarkStale()
4142
}
43+
44+
if p != nil && pth != nil && p.IsHome() && pth.IsLeafBundle() {
45+
msg := "Using %s in your content's root directory is usually incorrect for your home page. "
46+
msg += "You should use %s instead. If you don't rename this file, your home page will be "
47+
msg += "treated as a leaf bundle, meaning it won't be able to have any child pages or sections."
48+
h.Log.Warnidf(constants.WarnHomePageIsLeafBundle, msg, pth.PathNoLeadingSlash(), strings.ReplaceAll(pth.PathNoLeadingSlash(), "index", "_index"))
49+
}
50+
4251
return p, pth, err
4352
}
4453

hugolib/page_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,3 +1968,35 @@ Title: {{ .Title }}
19681968
"deprecated: path in front matter was deprecated",
19691969
)
19701970
}
1971+
1972+
// Issue 13538
1973+
func TestHomePageIsLeafBundle(t *testing.T) {
1974+
t.Parallel()
1975+
1976+
files := `
1977+
-- hugo.toml --
1978+
defaultContentLanguage = 'de'
1979+
defaultContentLanguageInSubdir = true
1980+
[languages.de]
1981+
weight = 1
1982+
[languages.en]
1983+
weight = 2
1984+
-- layouts/all.html --
1985+
{{ .Title }}
1986+
-- content/index.de.md --
1987+
---
1988+
title: home de
1989+
---
1990+
-- content/index.en.org --
1991+
---
1992+
title: home en
1993+
---
1994+
`
1995+
1996+
b := Test(t, files, TestOptWarn())
1997+
1998+
b.AssertFileContent("public/de/index.html", "home de")
1999+
b.AssertFileContent("public/en/index.html", "home en")
2000+
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.")
2001+
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.")
2002+
}

0 commit comments

Comments
 (0)