diff --git a/hugolib/pagesfromdata/pagesfromgotmpl.go b/hugolib/pagesfromdata/pagesfromgotmpl.go index c2214cdca..bf7b7f633 100644 --- a/hugolib/pagesfromdata/pagesfromgotmpl.go +++ b/hugolib/pagesfromdata/pagesfromgotmpl.go @@ -17,7 +17,6 @@ import ( "context" "fmt" "io" - "path/filepath" "github.com/gohugoio/hugo/common/hashing" "github.com/gohugoio/hugo/common/hmaps" @@ -346,7 +345,7 @@ func (p *PagesFromTemplate) Execute(ctx context.Context) (BuildInfo, error) { } defer f.Close() - tmpl, err := p.TemplateStore.TextParse(filepath.ToSlash(p.GoTmplFi.Meta().Filename), helpers.ReaderToString(f)) + tmpl, err := p.TemplateStore.TextParse(p.GoTmplFi.Meta().PathInfo.Path(), helpers.ReaderToString(f)) if err != nil { return BuildInfo{}, err } diff --git a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go index f0bdb1548..958e6451f 100644 --- a/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go +++ b/hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go @@ -14,6 +14,7 @@ package pagesfromdata_test import ( + "bytes" "fmt" "strings" "testing" @@ -923,3 +924,25 @@ iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAA b.AssertFileContent("public/p1/index.html", "Resized: 1x1|") } + +// See https://github.com/gohugoio/hugo/issues/14999 +func TestContentAdapterTemplateMetricsRelativePath(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +templateMetrics = true +-- layouts/all.html -- +{{ .Title }} +-- content/docs/_content.gotmpl -- +{{ .AddPage (dict "path" "/docs/p1" "title" "P1") }} +` + b := hugolib.Test(t, files) + + var buf bytes.Buffer + b.H.Metrics.WriteMetrics(&buf) + got := buf.String() + + b.Assert(got, qt.Contains, "/docs/_content.gotmpl") + b.Assert(got, qt.Not(qt.Contains), "content/docs/_content.gotmpl") +}