支持的搜索格式:
- 输入关键词全文搜索:HTTP/2 性能优化;
- 指定时间段搜索:date:2014、date:2015-05;
- 指定标签搜索:tag:性能优化、tag:HTTPS;
- 组合搜索:date:2015 tag:HTTP 优化;
diff --git a/conf/nginx/domain/deepzz.conf b/conf/nginx/domain/deepzz.conf index 8348407..900cb29 100644 --- a/conf/nginx/domain/deepzz.conf +++ b/conf/nginx/domain/deepzz.conf @@ -118,7 +118,7 @@ server { add_header Content-Security-Policy "default-src 'none'; script-src 'unsafe-inline' 'unsafe-eval' blob: https:; img-src data: https: https://st.deepzz.com; style-src 'unsafe-inline' https:; child-src https:; connect-src 'self' https://translate.googleapis.com; frame-src https://disqus.com https://www.slideshare.net"; # 中间证书证书指纹 # https://imququ.com/post/http-public-key-pinning.html - add_header Public-Key-Pins 'pin-sha256="JbQbUG5JMJUoI6brnx0x3vZF6jilxsapbXGVfjhN8Fg="; pin-sha256="YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg="; max-age=2592000; includeSubDomains'; + add_header Public-Key-Pins 'pin-sha256="lnsM2T/O9/J84sJFdnrpsFp3awZJ+ZZbYpCWhGloaHI="; pin-sha256="YLh1dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg="; max-age=2592000; includeSubDomains'; add_header Cache-Control no-cache; proxy_ignore_headers Set-Cookie; diff --git a/elasticsearch.go b/elasticsearch.go index 6a61a24..f46279c 100644 --- a/elasticsearch.go +++ b/elasticsearch.go @@ -140,11 +140,13 @@ func ElasticsearchSimple(q string, size, from int) *ESSearchResult { } func ElasticIndex(artc *Article) error { + img := PickFirstImage(artc.Content) mapping := map[string]interface{}{ "title": artc.Title, "content": IgnoreHtmlTag(artc.Content), "slug": artc.Slug, "tags": artc.Tags, + "img": img, "create_time": artc.CreateTime, } b, _ := json.Marshal(mapping) @@ -300,6 +302,7 @@ type ESSearchResult struct { Content string `json:"content"` CreateTime time.Time `json:"create_time"` Title string `json:"title"` + Img string `json:"img"` } `json:"_source"` Highlight struct { Title []string `json:"title"` diff --git a/front.go b/front.go index fa01225..ddfd61d 100644 --- a/front.go +++ b/front.go @@ -159,7 +159,7 @@ func HandleSearchPage(c *gin.Context) { } if q != "" { h["Word"] = q - h["HotWord"] = []string{} + h["HotWords"] = []string{"docker"} var result *ESSearchResult vals := c.Request.URL.Query() reg := regexp.MustCompile(`^[a-z]+:\w+$`) diff --git a/helper.go b/helper.go index 5d9d5cb..34a2661 100644 --- a/helper.go +++ b/helper.go @@ -35,3 +35,12 @@ func IgnoreHtmlTag(src string) string { re, _ = regexp.Compile("\\s{1,}") return re.ReplaceAllString(src, "") } + +func PickFirstImage(html string) string { + re, _ := regexp.Compile(`data-src="(.*?)"`) + sli := re.FindAllStringSubmatch(html, 1) + if len(sli) > 0 && len(sli[0]) > 1 { + return sli[0][1] + } + return "" +} diff --git a/views/search.html b/views/search.html index 46d1f58..ca07a6c 100644 --- a/views/search.html +++ b/views/search.html @@ -1 +1 @@ -{{define "search"}}
支持的搜索格式:
支持的搜索格式: