搜索
This commit is contained in:
parent
9a362fc329
commit
46088d1ed6
|
@ -18,10 +18,12 @@ var PostsCache sync.Map
|
||||||
func index(c *gin.Context) {
|
func index(c *gin.Context) {
|
||||||
page := 1
|
page := 1
|
||||||
pageSize := 10
|
pageSize := 10
|
||||||
|
status := []interface{}{"publish"}
|
||||||
order := c.Query("order")
|
order := c.Query("order")
|
||||||
if !helper.IsContainInArr(order, []string{"asc", "desc"}) {
|
if !helper.IsContainInArr(order, []string{"asc", "desc"}) {
|
||||||
order = "asc"
|
order = "asc"
|
||||||
}
|
}
|
||||||
|
header := ""
|
||||||
where := models.SqlBuilder{{
|
where := models.SqlBuilder{{
|
||||||
"post_type", "post",
|
"post_type", "post",
|
||||||
}, {"post_status", "in", ""}}
|
}, {"post_status", "in", ""}}
|
||||||
|
@ -37,6 +39,7 @@ func index(c *gin.Context) {
|
||||||
where = append(where, []string{
|
where = append(where, []string{
|
||||||
"month(post_date)", month,
|
"month(post_date)", month,
|
||||||
})
|
})
|
||||||
|
header = fmt.Sprintf("月度归档: <span>%s年%s月</span>", year, month)
|
||||||
}
|
}
|
||||||
tt := ""
|
tt := ""
|
||||||
category := c.Param("category")
|
category := c.Param("category")
|
||||||
|
@ -44,9 +47,22 @@ func index(c *gin.Context) {
|
||||||
category = c.Param("tag")
|
category = c.Param("tag")
|
||||||
if category != "" {
|
if category != "" {
|
||||||
tt = "post_tag"
|
tt = "post_tag"
|
||||||
|
header = fmt.Sprintf("标签: <span>%s</span>", category)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tt = "category"
|
tt = "category"
|
||||||
|
header = fmt.Sprintf("分类: <span>%s</span>", category)
|
||||||
|
}
|
||||||
|
s := c.Query("s")
|
||||||
|
if s != "" && strings.Replace(s, " ", "", -1) != "" {
|
||||||
|
q := helper.StrJoin("%", s, "%")
|
||||||
|
where = append(where, []string{
|
||||||
|
"and", "post_title", "like", q, "",
|
||||||
|
"or", "post_content", "like", q, "",
|
||||||
|
})
|
||||||
|
header = fmt.Sprintf("%s的搜索结果", s)
|
||||||
|
} else {
|
||||||
|
status = append(status, "private")
|
||||||
}
|
}
|
||||||
var join models.SqlBuilder
|
var join models.SqlBuilder
|
||||||
if category != "" {
|
if category != "" {
|
||||||
|
@ -70,7 +86,6 @@ func index(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status := []interface{}{"publish", "private"}
|
|
||||||
postIds, totalRaw, err := models.SimplePagination[models.WpPosts](where, "ID", "", page, pageSize, models.SqlBuilder{{"post_date", order}}, join, status)
|
postIds, totalRaw, err := models.SimplePagination[models.WpPosts](where, "ID", "", page, pageSize, models.SqlBuilder{{"post_date", order}}, join, status)
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -156,6 +171,8 @@ func index(c *gin.Context) {
|
||||||
"totalPage": totalPage,
|
"totalPage": totalPage,
|
||||||
"queryRaw": q,
|
"queryRaw": q,
|
||||||
"pagination": pagination(page, totalPage, 1, c.Request.URL.Path, q),
|
"pagination": pagination(page, totalPage, 1, c.Request.URL.Path, q),
|
||||||
|
"search": s,
|
||||||
|
"header": header,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,11 @@
|
||||||
{{define "content" }}
|
{{define "content" }}
|
||||||
<div id="primary" class="content-area">
|
<div id="primary" class="content-area">
|
||||||
<main id="main" class="site-main">
|
<main id="main" class="site-main">
|
||||||
|
{{if .header}}
|
||||||
|
<header class="page-header">
|
||||||
|
<h1 class="page-title">{{.header|unescaped}}</h1>
|
||||||
|
</header>
|
||||||
|
{{end}}
|
||||||
{{ range $k,$v:=.posts}}
|
{{ range $k,$v:=.posts}}
|
||||||
<article id="post-{{$v.Id}}"
|
<article id="post-{{$v.Id}}"
|
||||||
class="post-{{$v.Id}} post type-post status-publish format-standard hentry category-uncategorized">
|
class="post-{{$v.Id}} post type-post status-publish format-standard hentry category-uncategorized">
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
{{define "layout/sidebar" }}
|
{{define "layout/sidebar" }}
|
||||||
<div id="widget-area" class="widget-area" role="complementary">
|
<div id="widget-area" class="widget-area" role="complementary">
|
||||||
<aside id="search-2" class="widget widget_search">
|
<aside id="search-2" class="widget widget_search">
|
||||||
<form role="search" method="get" class="search-form" action="https://www.xloyy.com/">
|
<form role="search" method="get" class="search-form" action="/">
|
||||||
<label>
|
<label>
|
||||||
<span class="screen-reader-text">搜索:</span>
|
<span class="screen-reader-text">搜索:</span>
|
||||||
<input type="search" class="search-field" placeholder="搜索…" value="" name="s">
|
<input type="search" class="search-field" placeholder="搜索…" value="{{.search}}" name="s">
|
||||||
</label>
|
</label>
|
||||||
<input type="submit" class="search-submit screen-reader-text" value="搜索">
|
<input type="submit" class="search-submit screen-reader-text" value="搜索">
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user