mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
parent
6f48146e75
commit
1746e8a9b2
4 changed files with 31 additions and 6 deletions
|
@ -20,7 +20,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/common/herrors"
|
"github.com/gohugoio/hugo/hugofs/files"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/helpers"
|
"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) {
|
func (c *PageCollections) getContentNode(context page.Page, isReflink bool, ref string) (*contentNode, error) {
|
||||||
defer herrors.Recover()
|
|
||||||
ref = filepath.ToSlash(strings.ToLower(strings.TrimSpace(ref)))
|
ref = filepath.ToSlash(strings.ToLower(strings.TrimSpace(ref)))
|
||||||
if ref == "" {
|
if ref == "" {
|
||||||
ref = "/"
|
ref = "/"
|
||||||
}
|
}
|
||||||
inRef := ref
|
inRef := ref
|
||||||
|
navUp := strings.HasPrefix(ref, "..")
|
||||||
var doSimpleLookup bool
|
var doSimpleLookup bool
|
||||||
if isReflink || context == nil {
|
if isReflink || context == nil {
|
||||||
// For Ref/Reflink and .Site.GetPage do simple name lookups for the potentially ambigous myarticle.md and /myarticle.md,
|
// 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() {
|
if context.File().IsZero() {
|
||||||
base = context.SectionsPath()
|
base = context.SectionsPath()
|
||||||
} else {
|
} 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)
|
ref = path.Join("/", strings.ToLower(base), ref)
|
||||||
}
|
}
|
||||||
|
|
|
@ -777,7 +777,6 @@ func (s siteRefLinker) logNotFound(ref, what string, p page.Page, position text.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *siteRefLinker) refLink(ref string, source interface{}, relative bool, outputFormat string) (string, error) {
|
func (s *siteRefLinker) refLink(ref string, source interface{}, relative bool, outputFormat string) (string, error) {
|
||||||
|
|
||||||
p, err := unwrapPage(source)
|
p, err := unwrapPage(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
|
@ -940,6 +940,8 @@ func setupLinkingMockSite(t *testing.T) *Site {
|
||||||
{filepath.FromSlash("level2/level3/common.png"), ""},
|
{filepath.FromSlash("level2/level3/common.png"), ""},
|
||||||
|
|
||||||
{filepath.FromSlash("level2/level3/embedded.dot.md"), ""},
|
{filepath.FromSlash("level2/level3/embedded.dot.md"), ""},
|
||||||
|
|
||||||
|
{filepath.FromSlash("leafbundle/index.md"), ""},
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, fs := newTestCfg()
|
cfg, fs := newTestCfg()
|
||||||
|
@ -1026,3 +1028,18 @@ func checkLinkCase(site *Site, link string, currentPage page.Page, relative bool
|
||||||
t.Fatalf("[%d] Expected %q from %q to resolve to %q, got %q - error: %s", i, link, currentPage.Path(), expected, out, err)
|
t.Fatalf("[%d] Expected %q from %q to resolve to %q, got %q - error: %s", i, link, currentPage.Path(), expected, out, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/gohugoio/hugo/issues/6952
|
||||||
|
func TestRefBundle(t *testing.T) {
|
||||||
|
b := newTestSitesBuilder(t)
|
||||||
|
b.WithContent(
|
||||||
|
"post/b1/index.md", "---\ntitle: pb1\n---\nRef: {{< ref \"b2\" >}}",
|
||||||
|
"post/b2/index.md", "---\ntitle: pb2\n---\n",
|
||||||
|
)
|
||||||
|
b.WithTemplates("index.html", `Home`)
|
||||||
|
b.WithTemplates("_default/single.html", `Content: {{ .Content }}`)
|
||||||
|
|
||||||
|
b.Build(BuildCfg{})
|
||||||
|
|
||||||
|
b.AssertFileContent("public/post/b1/index.html", `Content: <p>Ref: http://example.com/post/b2/</p>`)
|
||||||
|
}
|
||||||
|
|
|
@ -443,7 +443,8 @@ func (s *sitesBuilder) writeFilePairs(folder string, files []filenameContent) *s
|
||||||
// our tests running with the in memory filesystem.
|
// our tests running with the in memory filesystem.
|
||||||
// That file system is backed by a map so not sure how this helps, but some
|
// That file system is backed by a map so not sure how this helps, but some
|
||||||
// randomness in tests doesn't hurt.
|
// randomness in tests doesn't hurt.
|
||||||
s.rnd.Shuffle(len(files), func(i, j int) { files[i], files[j] = files[j], files[i] })
|
// TODO(bep) this turns out to be more confusing than helpful.
|
||||||
|
//s.rnd.Shuffle(len(files), func(i, j int) { files[i], files[j] = files[j], files[i] })
|
||||||
|
|
||||||
for _, fc := range files {
|
for _, fc := range files {
|
||||||
target := folder
|
target := folder
|
||||||
|
|
Loading…
Reference in a new issue