mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 15:28:54 +00:00
pagesfromdata: Use relative path for content adapter template metrics
Fixes #14999
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user