diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-11-01 11:28:30 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-11-01 21:06:35 +0100 |
commit | 1d18eb0574a57c3e9f468659d076a666a3dd76f2 (patch) | |
tree | 8536aa6e8e2fc496b3b2d7b66a2e5f0110e625a6 /tpl | |
parent | 33a7b36fd42ee31dd79115ec6639bed24247332f (diff) |
Add file (line/col) info to ref/relref errors
See #5371
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/template.go | 4 | ||||
-rw-r--r-- | tpl/tplimpl/embedded/templates.autogen.go | 4 | ||||
-rw-r--r-- | tpl/tplimpl/embedded/templates/shortcodes/ref.html | 2 | ||||
-rw-r--r-- | tpl/tplimpl/embedded/templates/shortcodes/relref.html | 2 | ||||
-rw-r--r-- | tpl/urls/urls.go | 13 |
5 files changed, 10 insertions, 15 deletions
diff --git a/tpl/template.go b/tpl/template.go index 913b20ed2..3225814c0 100644 --- a/tpl/template.go +++ b/tpl/template.go @@ -165,14 +165,14 @@ func (t *TemplateAdapter) addFileContext(name string, inerr error) error { // Since this can be a composite of multiple template files (single.html + baseof.html etc.) // we potentially need to look in both -- and cannot rely on line number alone. lineMatcher := func(m herrors.LineMatcher) bool { - if m.FileError.LineNumber() != m.LineNumber { + if m.Position.LineNumber != m.LineNumber { return false } if !hasMaster { return true } - identifiers := t.extractIdentifiers(m.FileError.Error()) + identifiers := t.extractIdentifiers(m.Error.Error()) for _, id := range identifiers { if strings.Contains(m.Line, id) { diff --git a/tpl/tplimpl/embedded/templates.autogen.go b/tpl/tplimpl/embedded/templates.autogen.go index e2d94dc8b..defc0f313 100644 --- a/tpl/tplimpl/embedded/templates.autogen.go +++ b/tpl/tplimpl/embedded/templates.autogen.go @@ -398,8 +398,8 @@ if (!doNotTrack) { </style> {{ end }} {{ end }}`}, - {`shortcodes/ref.html`, `{{ ref .Page .Params }}`}, - {`shortcodes/relref.html`, `{{ relref .Page .Params }}`}, + {`shortcodes/ref.html`, `{{ ref . .Params }}`}, + {`shortcodes/relref.html`, `{{ relref . .Params }}`}, {`shortcodes/twitter.html`, `{{- $pc := .Page.Site.Config.Privacy.Twitter -}} {{- if not $pc.Disable -}} {{- if $pc.Simple -}} diff --git a/tpl/tplimpl/embedded/templates/shortcodes/ref.html b/tpl/tplimpl/embedded/templates/shortcodes/ref.html index c4d9f1d16..cd9c3defc 100644 --- a/tpl/tplimpl/embedded/templates/shortcodes/ref.html +++ b/tpl/tplimpl/embedded/templates/shortcodes/ref.html @@ -1 +1 @@ -{{ ref .Page .Params }}
\ No newline at end of file +{{ ref . .Params }}
\ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/shortcodes/relref.html b/tpl/tplimpl/embedded/templates/shortcodes/relref.html index d3a31ea44..82005bd82 100644 --- a/tpl/tplimpl/embedded/templates/shortcodes/relref.html +++ b/tpl/tplimpl/embedded/templates/shortcodes/relref.html @@ -1 +1 @@ -{{ relref .Page .Params }}
\ No newline at end of file +{{ relref . .Params }}
\ No newline at end of file diff --git a/tpl/urls/urls.go b/tpl/urls/urls.go index 8f6f92f3d..7abf45ba2 100644 --- a/tpl/urls/urls.go +++ b/tpl/urls/urls.go @@ -20,10 +20,10 @@ import ( "html/template" "net/url" + "github.com/gohugoio/hugo/common/urls" + "github.com/gohugoio/hugo/deps" _errors "github.com/pkg/errors" "github.com/russross/blackfriday" - - "github.com/gohugoio/hugo/deps" "github.com/spf13/cast" ) @@ -91,14 +91,9 @@ func (ns *Namespace) Anchorize(a interface{}) (string, error) { return blackfriday.SanitizedAnchorName(s), nil } -type reflinker interface { - Ref(args map[string]interface{}) (string, error) - RelRef(args map[string]interface{}) (string, error) -} - // Ref returns the absolute URL path to a given content item. func (ns *Namespace) Ref(in interface{}, args interface{}) (template.HTML, error) { - p, ok := in.(reflinker) + p, ok := in.(urls.RefLinker) if !ok { return "", errors.New("invalid Page received in Ref") } @@ -112,7 +107,7 @@ func (ns *Namespace) Ref(in interface{}, args interface{}) (template.HTML, error // RelRef returns the relative URL path to a given content item. func (ns *Namespace) RelRef(in interface{}, args interface{}) (template.HTML, error) { - p, ok := in.(reflinker) + p, ok := in.(urls.RefLinker) if !ok { return "", errors.New("invalid Page received in RelRef") } |