mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
f45cb31728
commit
2d159e9cc7
2 changed files with 40 additions and 5 deletions
|
@ -17,6 +17,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
qt "github.com/frankban/quicktest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPaginator(t *testing.T) {
|
func TestPaginator(t *testing.T) {
|
||||||
|
@ -105,3 +107,34 @@ func TestPaginateWithSort(t *testing.T) {
|
||||||
b.Build(BuildCfg{}).AssertFileContent("public/index.html",
|
b.Build(BuildCfg{}).AssertFileContent("public/index.html",
|
||||||
filepath.FromSlash("|content/sect/doc1.nn.md|content/sect/doc1.nb.md|content/sect/doc1.fr.md|content/sect/doc1.en.md"))
|
filepath.FromSlash("|content/sect/doc1.nn.md|content/sect/doc1.nb.md|content/sect/doc1.fr.md|content/sect/doc1.en.md"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/gohugoio/hugo/issues/6797
|
||||||
|
func TestPaginateOutputFormat(t *testing.T) {
|
||||||
|
b := newTestSitesBuilder(t).WithSimpleConfigFile()
|
||||||
|
b.WithContent("_index.md", `---
|
||||||
|
title: "Home"
|
||||||
|
cascade:
|
||||||
|
outputs:
|
||||||
|
- JSON
|
||||||
|
---`)
|
||||||
|
|
||||||
|
for i := 0; i < 22; i++ {
|
||||||
|
b.WithContent(fmt.Sprintf("p%d.md", i+1), fmt.Sprintf(`---
|
||||||
|
title: "Page"
|
||||||
|
weight: %d
|
||||||
|
---`, i+1))
|
||||||
|
}
|
||||||
|
|
||||||
|
b.WithTemplatesAdded("index.json", `JSON: {{ .Paginator.TotalNumberOfElements }}: {{ range .Paginator.Pages }}|{{ .RelPermalink }}{{ end }}:DONE`)
|
||||||
|
b.Build(BuildCfg{})
|
||||||
|
|
||||||
|
b.AssertFileContent("public/index.json",
|
||||||
|
`JSON: 22
|
||||||
|
|/p1/index.json|/p2/index.json|
|
||||||
|
`)
|
||||||
|
|
||||||
|
// This looks odd, so are most bugs.
|
||||||
|
b.Assert(b.CheckExists("public/page/1/index.json/index.html"), qt.Equals, false)
|
||||||
|
b.Assert(b.CheckExists("public/page/1/index.json"), qt.Equals, false)
|
||||||
|
b.AssertFileContent("public/page/2/index.json", `JSON: 22: |/p11/index.json|/p12/index.json`)
|
||||||
|
}
|
||||||
|
|
|
@ -205,12 +205,14 @@ func (s *Site) renderPaginator(p *pageState, templ tpl.Template) error {
|
||||||
panic(fmt.Sprintf("invalid paginator state for %q", p.pathOrTitle()))
|
panic(fmt.Sprintf("invalid paginator state for %q", p.pathOrTitle()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write alias for page 1
|
if f.IsHTML {
|
||||||
d.Addends = fmt.Sprintf("/%s/%d", paginatePath, 1)
|
// Write alias for page 1
|
||||||
targetPaths := page.CreateTargetPaths(d)
|
d.Addends = fmt.Sprintf("/%s/%d", paginatePath, 1)
|
||||||
|
targetPaths := page.CreateTargetPaths(d)
|
||||||
|
|
||||||
if err := s.writeDestAlias(targetPaths.TargetFilename, p.Permalink(), f, nil); err != nil {
|
if err := s.writeDestAlias(targetPaths.TargetFilename, p.Permalink(), f, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render pages for the rest
|
// Render pages for the rest
|
||||||
|
|
Loading…
Reference in a new issue