Add default pagination (Fixes #48)

This commit is contained in:
Jan-Lukas Else 2023-01-15 14:41:06 +01:00
parent 032d994b80
commit 57cc3dd94d
2 changed files with 18 additions and 1 deletions

View File

@ -386,7 +386,6 @@ func (a *goBlog) initConfig(logging bool) error {
if err := a.initDatabase(logging); err != nil {
return err
}
// Check config
// Parse addresses and hostnames
if a.cfg.Server.PublicAddress == "" {
return errors.New("no public address configured")
@ -505,6 +504,10 @@ func (a *goBlog) initConfig(logging bool) error {
}
// Check config for each blog
for blog, bc := range a.cfg.Blogs {
// Check pagination
if bc.Pagination == 0 {
bc.Pagination = 10
}
// Check sections and add section if none exists
if len(bc.Sections) == 0 {
bc.Sections = createDefaultSections()

View File

@ -5,6 +5,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
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)
}
}
})
}