From 23deffffd13a4fb9f8a1a2205ee031ac0cf48411 Mon Sep 17 00:00:00 2001 From: xing Date: Sat, 17 Sep 2022 15:37:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- route/actions.go | 8 +++++++- templates/index/index.html | 13 ++++++++++++- templates/layout/empty.html | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 templates/layout/empty.html diff --git a/route/actions.go b/route/actions.go index 0f2cb35..6b26ca6 100644 --- a/route/actions.go +++ b/route/actions.go @@ -23,7 +23,7 @@ func index(c *gin.Context) { if !helper.IsContainInArr(order, []string{"asc", "desc"}) { order = "asc" } - title := models.Options["blogname"] + title := "" header := "" postType := []interface{}{"post"} where := models.SqlBuilder{{ @@ -94,6 +94,9 @@ func index(c *gin.Context) { page = pa } } + if page == 1 { + title = helper.StrJoin(models.Options["blogname"], "-", models.Options["blogdescription"]) + } postIds, totalRaw, err := models.SimplePagination[models.WpPosts](where, "ID", "", page, pageSize, models.SqlBuilder{{"post_date", order}}, join, postType, status) defer func() { @@ -104,6 +107,9 @@ func index(c *gin.Context) { if err != nil { return } + if len(postIds) < 1 && category != "" { + title = "未找到页面" + } var all []uint64 var allPosts []models.WpPosts var needQuery []interface{} diff --git a/templates/index/index.html b/templates/index/index.html index 69ce685..ed11355 100644 --- a/templates/index/index.html +++ b/templates/index/index.html @@ -1,10 +1,17 @@ {{template "layout/base" .}} {{define "content" }} +{{if .posts}}
{{if .header}} {{end}} {{ range $k,$v:=.posts}} @@ -56,4 +63,8 @@ {{template "layout/page" .}}
+{{else }} +{{template "layout/empty" .}} +{{end}} + {{end}} diff --git a/templates/layout/empty.html b/templates/layout/empty.html new file mode 100644 index 0000000..d84c0db --- /dev/null +++ b/templates/layout/empty.html @@ -0,0 +1,37 @@ +{{define "layout/empty"}} +
+
+ +
+ + +
+ +

{{if .search}} + 抱歉,没有符合您搜索条件的结果。请换其它关键词再试。 + {{else}} + 这儿似乎什么都没有,试试搜索? + {{end}} +

+ + +
+
+ +
+
+{{end}} \ No newline at end of file