pagesfromdata: Use relative path for content adapter template metrics

Fixes #14999
This commit is contained in:
anupamojha-eng
2026-06-08 06:56:47 -07:00
committed by GitHub
parent 121bc6ceb2
commit 1d018ef857
2 changed files with 24 additions and 2 deletions
+1 -2
View File
@@ -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
}
@@ -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")
}