文章默认排序设置

This commit is contained in:
xing 2023-01-22 18:01:04 +08:00
parent c842c3a293
commit ca349f55d7
3 changed files with 14 additions and 1 deletions

View File

@ -71,3 +71,7 @@ trustIps: []
trustServerNames: ["xy.test","blog.xy.test"] trustServerNames: ["xy.test","blog.xy.test"]
# port # port
port: 8082 port: 8082
# 主题 为空值为option template没有就默认为twentyfifteen
theme: "twentyfifteen"
# 文档排序默认升序还是降序
postOrder: "desc"

View File

@ -7,6 +7,7 @@ import (
"github.com/fthvgb1/wp-go/helper/slice" "github.com/fthvgb1/wp-go/helper/slice"
str "github.com/fthvgb1/wp-go/helper/strings" str "github.com/fthvgb1/wp-go/helper/strings"
"github.com/fthvgb1/wp-go/internal/pkg/cache" "github.com/fthvgb1/wp-go/internal/pkg/cache"
"github.com/fthvgb1/wp-go/internal/pkg/config"
"github.com/fthvgb1/wp-go/internal/pkg/dao" "github.com/fthvgb1/wp-go/internal/pkg/dao"
"github.com/fthvgb1/wp-go/internal/pkg/logs" "github.com/fthvgb1/wp-go/internal/pkg/logs"
"github.com/fthvgb1/wp-go/internal/pkg/models" "github.com/fthvgb1/wp-go/internal/pkg/models"
@ -92,10 +93,17 @@ func (h *indexHandle) getSearchKey() string {
return fmt.Sprintf("action:%s|%s|%s|%s|%s|%s|%d|%d", h.author, h.search, h.orderBy, h.order, h.category, h.categoryType, h.page, h.pageSize) return fmt.Sprintf("action:%s|%s|%s|%s|%s|%s|%d|%d", h.author, h.search, h.orderBy, h.order, h.category, h.categoryType, h.page, h.pageSize)
} }
var orders = []string{"asc", "desc"}
func (h *indexHandle) parseParams() (err error) { func (h *indexHandle) parseParams() (err error) {
h.order = h.c.Query("order") h.order = h.c.Query("order")
if !slice.IsContained(h.order, []string{"asc", "desc"}) {
if !slice.IsContained(h.order, orders) {
order := config.Conf.Load().PostOrder
h.order = "asc" h.order = "asc"
if order != "" && slice.IsContained(order, orders) {
h.order = order
}
} }
year := h.c.Param("year") year := h.c.Param("year")
if year != "" { if year != "" {

View File

@ -38,6 +38,7 @@ type Config struct {
TrustIps []string `yaml:"trustIps"` TrustIps []string `yaml:"trustIps"`
TrustServerNames []string `yaml:"trustServerNames"` TrustServerNames []string `yaml:"trustServerNames"`
Theme string `yaml:"theme"` Theme string `yaml:"theme"`
PostOrder string `yaml:"postOrder"`
} }
type Mail struct { type Mail struct {