mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-29 20:00:49 +00:00
hugolib: Fix paginator URL for sections with URL in front matter
Fixes #4415
This commit is contained in:
parent
e39797fa72
commit
9f740b37cf
2 changed files with 61 additions and 1 deletions
|
@ -208,11 +208,15 @@ func createTargetPath(d targetPathDescriptor) string {
|
||||||
} else {
|
} else {
|
||||||
pagePath = filepath.Join(pagePath, d.URL)
|
pagePath = filepath.Join(pagePath, d.URL)
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.Addends != "" {
|
if d.Addends != "" {
|
||||||
pagePath = filepath.Join(pagePath, 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())
|
pagePath = filepath.Join(pagePath, d.Type.BaseName+d.Type.MediaType.FullSuffix())
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if d.Kind == KindPage {
|
} else if d.Kind == KindPage {
|
||||||
if d.ExpandedPermalink != "" {
|
if d.ExpandedPermalink != "" {
|
||||||
pagePath = filepath.Join(pagePath, d.ExpandedPermalink)
|
pagePath = filepath.Join(pagePath, d.ExpandedPermalink)
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
package hugolib
|
package hugolib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -124,3 +125,58 @@ Do not go gentle into that good night.
|
||||||
assert.NotNil(ugly)
|
assert.NotNil(ugly)
|
||||||
assert.Equal("/sect2/p2.html", ugly.RelPermalink())
|
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/")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue