Add config options page.nextPrevSortOrder/nextPrevInSectionSortOrder

See #12776
This commit is contained in:
Bjørn Erik Pedersen
2024-08-17 15:16:09 +02:00
parent 53c0ddfcb4
commit 01008ba512
6 changed files with 132 additions and 1 deletions

View File

@@ -182,6 +182,9 @@ type Config struct {
// Pagination configuration.
Pagination config.Pagination `mapstructure:"-"`
// Page configuration.
Page config.PageConfig `mapstructure:"-"`
// Privacy configuration.
Privacy privacy.Config `mapstructure:"-"`

View File

@@ -327,6 +327,25 @@ var allDecoderSetups = map[string]decodeWeight{
return err
},
},
"page": {
key: "page",
decode: func(d decodeWeight, p decodeConfig) error {
p.c.Page = config.PageConfig{
NextPrevSortOrder: "desc",
NextPrevInSectionSortOrder: "desc",
}
if p.p.IsSet(d.key) {
if err := mapstructure.WeakDecode(p.p.Get(d.key), &p.c.Page); err != nil {
return err
}
}
return nil
},
getCompiler: func(c *Config) configCompiler {
return &c.Page
},
},
"pagination": {
key: "pagination",
decode: func(d decodeWeight, p decodeConfig) error {

View File

@@ -422,3 +422,18 @@ type Pagination struct {
// Whether to disable generation of alias for the first pagination page.
DisableAliases bool
}
// PageConfig configures the behavior of pages.
type PageConfig struct {
// Sort order for Page.Next and Page.Prev. Default "desc" (the default page sort order in Hugo).
NextPrevSortOrder string
// Sort order for Page.NextInSection and Page.PrevInSection. Default "desc".
NextPrevInSectionSortOrder string
}
func (c *PageConfig) CompileConfig(loggers.Logger) error {
c.NextPrevInSectionSortOrder = strings.ToLower(c.NextPrevInSectionSortOrder)
c.NextPrevSortOrder = strings.ToLower(c.NextPrevSortOrder)
return nil
}