diff --git a/hugolib/page_paths.go b/hugolib/page_paths.go index 5f45f7adf..ce8a700b1 100644 --- a/hugolib/page_paths.go +++ b/hugolib/page_paths.go @@ -208,11 +208,15 @@ func createTargetPath(d targetPathDescriptor) string { } 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) diff --git a/hugolib/site_url_test.go b/hugolib/site_url_test.go index 4839c5e63..671695b4d 100644 --- a/hugolib/site_url_test.go +++ b/hugolib/site_url_test.go @@ -14,6 +14,7 @@ package hugolib import ( + "fmt" "path/filepath" "testing" @@ -124,3 +125,58 @@ Do not go gentle into that good night. 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"), "{{.Content}}") + writeSource(t, fs, filepath.Join("layouts", "_default", "list.html"), + "P{{.Paginator.PageNumber}}|URL: {{.Paginator.URL}}|{{ if .Paginator.HasNext }}Next: {{.Paginator.Next.URL }}{{ end }}") + + 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/") + +}