diff --git a/config.example.yaml b/config.example.yaml index 170218f..a614e89 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -71,3 +71,7 @@ trustIps: [] trustServerNames: ["xy.test","blog.xy.test"] # port port: 8082 +# 主题 为空值为option template,没有就默认为twentyfifteen +theme: "twentyfifteen" +# 文档排序默认升序还是降序 +postOrder: "desc" \ No newline at end of file diff --git a/internal/actions/index.go b/internal/actions/index.go index 7d8af97..b7c82b6 100644 --- a/internal/actions/index.go +++ b/internal/actions/index.go @@ -7,6 +7,7 @@ import ( "github.com/fthvgb1/wp-go/helper/slice" str "github.com/fthvgb1/wp-go/helper/strings" "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/logs" "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) } +var orders = []string{"asc", "desc"} + func (h *indexHandle) parseParams() (err error) { 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" + if order != "" && slice.IsContained(order, orders) { + h.order = order + } } year := h.c.Param("year") if year != "" { diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index aafb293..026020b 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -38,6 +38,7 @@ type Config struct { TrustIps []string `yaml:"trustIps"` TrustServerNames []string `yaml:"trustServerNames"` Theme string `yaml:"theme"` + PostOrder string `yaml:"postOrder"` } type Mail struct {