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