mirror of https://github.com/jlelse/GoBlog
Add default pagination (Fixes #48)
This commit is contained in:
parent
032d994b80
commit
57cc3dd94d
|
@ -386,7 +386,6 @@ func (a *goBlog) initConfig(logging bool) error {
|
||||||
if err := a.initDatabase(logging); err != nil {
|
if err := a.initDatabase(logging); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Check config
|
|
||||||
// Parse addresses and hostnames
|
// Parse addresses and hostnames
|
||||||
if a.cfg.Server.PublicAddress == "" {
|
if a.cfg.Server.PublicAddress == "" {
|
||||||
return errors.New("no public address configured")
|
return errors.New("no public address configured")
|
||||||
|
@ -505,6 +504,10 @@ func (a *goBlog) initConfig(logging bool) error {
|
||||||
}
|
}
|
||||||
// Check config for each blog
|
// Check config for each blog
|
||||||
for blog, bc := range a.cfg.Blogs {
|
for blog, bc := range a.cfg.Blogs {
|
||||||
|
// Check pagination
|
||||||
|
if bc.Pagination == 0 {
|
||||||
|
bc.Pagination = 10
|
||||||
|
}
|
||||||
// Check sections and add section if none exists
|
// Check sections and add section if none exists
|
||||||
if len(bc.Sections) == 0 {
|
if len(bc.Sections) == 0 {
|
||||||
bc.Sections = createDefaultSections()
|
bc.Sections = createDefaultSections()
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func createDefaultTestConfig(t *testing.T) *config {
|
func createDefaultTestConfig(t *testing.T) *config {
|
||||||
|
@ -138,3 +139,16 @@ func Test_configHttps(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_configDefaults(t *testing.T) {
|
||||||
|
t.Run("Pagination", func(t *testing.T) {
|
||||||
|
app := &goBlog{}
|
||||||
|
err := app.initConfig(false)
|
||||||
|
require.NoError(t, err)
|
||||||
|
if assert.Len(t, app.cfg.Blogs, 1) {
|
||||||
|
for _, bc := range app.cfg.Blogs {
|
||||||
|
assert.Equal(t, 10, bc.Pagination)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue