shithub: hugo

Download patch

ref: 9f740b37cfb3278e34a5d085380ccd4d619dabff
parent: e39797fa720829dafd165aa25bfc2605700c38dc
author: Bjørn Erik Pedersen <[email protected]>
date: Mon Feb 26 12:45:51 EST 2018

hugolib: Fix paginator URL for sections with URL in front matter

Fixes #4415

--- a/hugolib/page_paths.go
+++ b/hugolib/page_paths.go
@@ -208,11 +208,15 @@
 		} else {
 			pagePath = filepath.Join(pagePath, d.URL)
 		}
+
 		if d.Addends != "" {
 			pagePath = filepath.Join(pagePath, d.Addends)
-		} else if strings.HasSuffix(d.URL, "/") || !strings.Contains(d.URL, ".") {
+		}
+
+		if strings.HasSuffix(d.URL, "/") || !strings.Contains(d.URL, ".") {
 			pagePath = filepath.Join(pagePath, d.Type.BaseName+d.Type.MediaType.FullSuffix())
 		}
+
 	} else if d.Kind == KindPage {
 		if d.ExpandedPermalink != "" {
 			pagePath = filepath.Join(pagePath, d.ExpandedPermalink)
--- a/hugolib/site_url_test.go
+++ b/hugolib/site_url_test.go
@@ -14,6 +14,7 @@
 package hugolib
 
 import (
+	"fmt"
 	"path/filepath"
 	"testing"
 
@@ -123,4 +124,59 @@
 	ugly := s.getPage(KindPage, "sect2/p2.md")
 	assert.NotNil(ugly)
 	assert.Equal("/sect2/p2.html", ugly.RelPermalink())
+}
+
+func TestSectionWithURLInFrontMatter(t *testing.T) {
+	t.Parallel()
+
+	assert := require.New(t)
+
+	const st = `---
+title: Do not go gentle into that good night
+url: %s
+---
+
+Wild men who caught and sang the sun in flight,
+And learn, too late, they grieved it on its way,
+Do not go gentle into that good night.
+
+`
+
+	const pt = `---
+title: Wild men who caught and sang the sun in flight
+---
+
+Wild men who caught and sang the sun in flight,
+And learn, too late, they grieved it on its way,
+Do not go gentle into that good night.
+
+`
+
+	cfg, fs := newTestCfg()
+	th := testHelper{cfg, fs, t}
+
+	cfg.Set("paginate", 1)
+
+	writeSource(t, fs, filepath.Join("content", "sect1", "_index.md"), fmt.Sprintf(st, "/ss1/"))
+	writeSource(t, fs, filepath.Join("content", "sect2", "_index.md"), fmt.Sprintf(st, "/ss2/"))
+
+	for i := 0; i < 5; i++ {
+		writeSource(t, fs, filepath.Join("content", "sect1", fmt.Sprintf("p%d.md", i+1)), pt)
+		writeSource(t, fs, filepath.Join("content", "sect2", fmt.Sprintf("p%d.md", i+1)), pt)
+	}
+
+	writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), "<html><body>{{.Content}}</body></html>")
+	writeSource(t, fs, filepath.Join("layouts", "_default", "list.html"),
+		"<html><body>P{{.Paginator.PageNumber}}|URL: {{.Paginator.URL}}|{{ if .Paginator.HasNext }}Next: {{.Paginator.Next.URL }}{{ end }}</body></html>")
+
+	s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
+
+	assert.Len(s.RegularPages, 10)
+
+	sect1 := s.getPage(KindSection, "sect1")
+	assert.NotNil(sect1)
+	assert.Equal("/ss1/", sect1.RelPermalink())
+	th.assertFileContent(filepath.Join("public", "ss1", "index.html"), "P1|URL: /ss1/|Next: /ss1/page/2/")
+	th.assertFileContent(filepath.Join("public", "ss1", "page", "2", "index.html"), "P2|URL: /ss1/page/2/|Next: /ss1/page/3/")
+
 }