From b495dda30f4cac69a5e7fd6c76a4b9ac5e42aca3 Mon Sep 17 00:00:00 2001
From: xing
Date: Thu, 9 Feb 2023 20:49:33 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug=20=E5=AE=8C=E5=96=84?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
internal/actions/detail.go | 8 ++-
internal/actions/index.go | 11 +--
.../theme/twentyfifteen/layout/empty.gohtml | 2 +-
internal/theme/twentyfifteen/twentyfifteen.go | 68 ++++++++++++++++++
.../theme/twentyseventeen/layout/empty.gohtml | 71 +++++++++++--------
.../twentyseventeen/layout/sidebar.gohtml | 2 +-
.../theme/twentyseventeen/posts/index.gohtml | 17 ++---
.../theme/twentyseventeen/twentyseventeen.go | 21 ++++--
8 files changed, 142 insertions(+), 58 deletions(-)
create mode 100644 internal/theme/twentyfifteen/twentyfifteen.go
diff --git a/internal/actions/detail.go b/internal/actions/detail.go
index 4534738..2c158d7 100644
--- a/internal/actions/detail.go
+++ b/internal/actions/detail.go
@@ -32,7 +32,7 @@ func Detail(c *gin.Context) {
"post": post,
}
isApproveComment := false
- status := plugins.Ok
+ stats := plugins.Ok
pw := sessions.Default(c).Get("post_password")
defer func() {
@@ -40,7 +40,7 @@ func Detail(c *gin.Context) {
if err != nil {
code = http.StatusNotFound
c.Error(err)
- status = plugins.Error
+ stats = plugins.Error
return
}
if isApproveComment == true {
@@ -54,7 +54,7 @@ func Detail(c *gin.Context) {
Password: "",
Scene: plugins.Detail,
Code: code,
- Stats: status,
+ Stats: stats,
})
}()
id := str.ToInteger[uint64](c.Param("id"), 0)
@@ -62,10 +62,12 @@ func Detail(c *gin.Context) {
maxId, err := cache.GetMaxPostId(c)
logs.ErrPrintln(err, "get max post id")
if id > maxId || id <= 0 || err != nil {
+ stats = plugins.Empty404
return
}
post, err = cache.GetPostById(c, id)
if post.Id == 0 || err != nil || post.PostStatus != "publish" {
+ stats = plugins.Empty404
return
}
showComment := false
diff --git a/internal/actions/index.go b/internal/actions/index.go
index 57aed2a..608f803 100644
--- a/internal/actions/index.go
+++ b/internal/actions/index.go
@@ -185,7 +185,10 @@ func (h *indexHandle) parseParams() (err error) {
})
h.setTitleLR(h.category, wpconfig.Options.Value("blogname"))
}
- s := h.c.Query("s")
+ s, ok := h.c.GetQuery("s")
+ if ok {
+ h.scene = plugins.Search
+ }
if s != "" && strings.Replace(s, " ", "", -1) != "" {
q := str.Join("%", s, "%")
h.where = append(h.where, []string{
@@ -194,7 +197,7 @@ func (h *indexHandle) parseParams() (err error) {
"or", "post_excerpt", "like", q, "",
}, []string{"post_password", ""})
h.postType = append(h.postType, "page", "attachment")
- h.header = fmt.Sprintf("%s的搜索结果", s)
+ h.header = fmt.Sprintf("%s的搜索结果", s)
h.setTitleLR(str.Join(`"`, s, `"`, "的搜索结果"), wpconfig.Options.Value("blogname"))
h.search = s
h.scene = plugins.Search
@@ -229,8 +232,6 @@ func Index(c *gin.Context) {
"recentPosts": recent,
"archives": archive,
"categories": categoryItems,
- "search": h.search,
- "header": h.header,
"recentComments": recentComments,
"posts": posts,
}
@@ -266,6 +267,8 @@ func Index(c *gin.Context) {
return
}
ginH["title"] = h.getTitle()
+ ginH["search"] = h.search
+ ginH["header"] = h.header
if c.Param("month") != "" {
posts, totalRaw, err = cache.GetMonthPostIds(c, c.Param("year"), c.Param("month"), h.page, h.pageSize, h.order)
if err != nil {
diff --git a/internal/theme/twentyfifteen/layout/empty.gohtml b/internal/theme/twentyfifteen/layout/empty.gohtml
index d431380..34f1bc3 100644
--- a/internal/theme/twentyfifteen/layout/empty.gohtml
+++ b/internal/theme/twentyfifteen/layout/empty.gohtml
@@ -21,7 +21,7 @@
这儿似乎什么都没有,试试搜索?
{{end}}
-