From ca349f55d704b3c0af6e1f7656f360afcc033021 Mon Sep 17 00:00:00 2001 From: xing Date: Sun, 22 Jan 2023 18:01:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E7=AB=A0=E9=BB=98=E8=AE=A4=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.example.yaml | 4 ++++ internal/actions/index.go | 10 +++++++++- internal/pkg/config/config.go | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) 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 {