aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2024-02-21 15:42:00 +0100
committerBjørn Erik Pedersen <[email protected]>2024-02-21 17:27:45 +0100
commitfd0185a84a677c836fbe4defec040b77e6deea49 (patch)
tree439493688c85f89767f1cf8461110b208eba61cd
parent6da1d8f370624b1a3640076b1e60380b0d8b2f92 (diff)
downloadhugo-fd0185a84a677c836fbe4defec040b77e6deea49.tar.gz
hugo-fd0185a84a677c836fbe4defec040b77e6deea49.zip
Fix relref regression with trailing slash
Fixes #12096
-rw-r--r--hugolib/pagecollections.go3
-rw-r--r--hugolib/site_test.go22
2 files changed, 24 insertions, 1 deletions
diff --git a/hugolib/pagecollections.go b/hugolib/pagecollections.go
index 58c646334..3783dadab 100644
--- a/hugolib/pagecollections.go
+++ b/hugolib/pagecollections.go
@@ -56,7 +56,7 @@ func (c *pageFinder) getPageRef(context page.Page, ref string) (page.Page, error
}
func (c *pageFinder) getPage(context page.Page, ref string) (page.Page, error) {
- n, err := c.getContentNode(context, false, paths.ToSlashTrimTrailing(ref))
+ n, err := c.getContentNode(context, false, ref)
if err != nil {
return nil, err
}
@@ -121,6 +121,7 @@ func (c *pageFinder) getPageForRefs(ref ...string) (page.Page, error) {
const defaultContentExt = ".md"
func (c *pageFinder) getContentNode(context page.Page, isReflink bool, ref string) (contentNodeI, error) {
+ ref = paths.ToSlashTrimTrailing(ref)
inRef := ref
if ref == "" {
ref = "/"
diff --git a/hugolib/site_test.go b/hugolib/site_test.go
index 63088ee88..1de1d688a 100644
--- a/hugolib/site_test.go
+++ b/hugolib/site_test.go
@@ -992,6 +992,28 @@ func TestRefLinking(t *testing.T) {
// TODO: and then the failure cases.
}
+func TestRelRefWithTrailingSlash(t *testing.T) {
+ files := `
+-- hugo.toml --
+-- content/docs/5.3/examples/_index.md --
+---
+title: "Examples"
+---
+-- content/_index.md --
+---
+title: "Home"
+---
+
+Examples: {{< relref "/docs/5.3/examples/" >}}
+-- layouts/home.html --
+Content: {{ .Content }}|
+`
+
+ b := Test(t, files)
+
+ b.AssertFileContent("public/index.html", "Examples: /docs/5.3/examples/")
+}
+
func checkLinkCase(site *Site, link string, currentPage page.Page, relative bool, outputFormat string, expected string, t *testing.T, i int) {
t.Helper()
if out, err := site.refLink(link, currentPage, relative, outputFormat); err != nil || out != expected {