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}}

-