summaryrefslogtreecommitdiffstats
path: root/hugolib/pagecollections.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-02-28 14:22:05 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-02-29 18:32:06 +0100
commit1746e8a9b2be46dcd6cecbb4bc90983a9c69b333 (patch)
tree45a8cbb965f9070473e2a4d7a6330fd8fdf77b24 /hugolib/pagecollections.go
parent6f48146e75e9877c4271ec239b763e6f3bc3babb (diff)
Fix ref/relRef regression for relative refs from bundles
Fixes #6952
Diffstat (limited to 'hugolib/pagecollections.go')
-rw-r--r--hugolib/pagecollections.go16
1 files changed, 12 insertions, 4 deletions
diff --git a/hugolib/pagecollections.go b/hugolib/pagecollections.go
index 74d48fe22..7982b25ac 100644
--- a/hugolib/pagecollections.go
+++ b/hugolib/pagecollections.go
@@ -20,7 +20,7 @@ import (
"strings"
"sync"
- "github.com/gohugoio/hugo/common/herrors"
+ "github.com/gohugoio/hugo/hugofs/files"
"github.com/gohugoio/hugo/helpers"
@@ -207,13 +207,12 @@ func (c *PageCollections) getSectionOrPage(ref string) (*contentNode, string) {
}
func (c *PageCollections) getContentNode(context page.Page, isReflink bool, ref string) (*contentNode, error) {
- defer herrors.Recover()
ref = filepath.ToSlash(strings.ToLower(strings.TrimSpace(ref)))
if ref == "" {
ref = "/"
}
inRef := ref
-
+ navUp := strings.HasPrefix(ref, "..")
var doSimpleLookup bool
if isReflink || context == nil {
// For Ref/Reflink and .Site.GetPage do simple name lookups for the potentially ambigous myarticle.md and /myarticle.md,
@@ -227,7 +226,16 @@ func (c *PageCollections) getContentNode(context page.Page, isReflink bool, ref
if context.File().IsZero() {
base = context.SectionsPath()
} else {
- base = filepath.ToSlash(filepath.Dir(context.File().FileInfo().Meta().Path()))
+ meta := context.File().FileInfo().Meta()
+ base = filepath.ToSlash(filepath.Dir(meta.Path()))
+ if meta.Classifier() == files.ContentClassLeaf {
+ // Bundles are stored in subfolders e.g. blog/mybundle/index.md,
+ // so if the user has not explicitly asked to go up,
+ // look on the "blog" level.
+ if !navUp {
+ base = path.Dir(base)
+ }
+ }
}
ref = path.Join("/", strings.ToLower(base), ref)
}