From 8947c3fa0beec021e14b3f8040857335e1ecd473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Mon, 2 Mar 2020 20:06:58 +0100 Subject: [PATCH] Fix ref/relref short lookup for pages in sub-folder Fixes #6952 --- hugolib/pagecollections.go | 2 +- hugolib/site_test.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/hugolib/pagecollections.go b/hugolib/pagecollections.go index 7982b25ac..2a5173c1a 100644 --- a/hugolib/pagecollections.go +++ b/hugolib/pagecollections.go @@ -305,7 +305,7 @@ func (c *PageCollections) getContentNode(context page.Page, isReflink bool, ref } // Ref/relref supports this potentially ambigous lookup. - return getByName(name) + return getByName(path.Base(name)) } diff --git a/hugolib/site_test.go b/hugolib/site_test.go index 22b078f5a..66b54e352 100644 --- a/hugolib/site_test.go +++ b/hugolib/site_test.go @@ -1030,11 +1030,13 @@ func checkLinkCase(site *Site, link string, currentPage page.Page, relative bool } // https://github.com/gohugoio/hugo/issues/6952 -func TestRefBundle(t *testing.T) { +func TestRefIssues(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", + "post/nested-a/content-a.md", "---\ntitle: ca\n---\n{{< ref \"content-b\" >}}", + "post/nested-b/content-b.md", "---\ntitle: ca\n---\n", ) b.WithTemplates("index.html", `Home`) b.WithTemplates("_default/single.html", `Content: {{ .Content }}`) @@ -1042,4 +1044,6 @@ func TestRefBundle(t *testing.T) { b.Build(BuildCfg{}) b.AssertFileContent("public/post/b1/index.html", `Content:

Ref: http://example.com/post/b2/

`) + b.AssertFileContent("public/post/nested-a/content-a/index.html", `Content: http://example.com/post/nested-b/content-b/`) + }