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

站内搜索

{{if .Word}}{{with .SearchResult}}{{if gt (.Hits.Hits|len) 0}}
本次搜索共找到结果 {{.Hits.Total}} 条 (用时 {{.Took}} 秒)
{{range .Hits.Hits}}
{{dateformat .Source.CreateTime "2006-01-02"}} ... {{str2html (join .Highlight.Content "...")}} ...
{{end}}{{else}}
没有找到任何结果,请更换查询词试试~
或者试试 Google 站内搜索:site:{{$.Domain}} {{$.Word}}
{{end}}{{end}}{{else}}
热搜词:{{range .HotWords}}{{.}}{{end}}

支持的搜索格式:

  1. 输入关键词全文搜索:HTTP/2 性能优化
  2. 指定时间段搜索:date:2014date:2015-05
  3. 指定标签搜索:tag:性能优化tag:HTTPS
  4. 组合搜索:date:2015 tag:HTTP 优化
{{end}}
{{if or .Prev .Next}}{{end}}
{{end}} \ No newline at end of file +{{define "search"}}

站内搜索

{{if .Word}}{{with .SearchResult}}{{if gt (.Hits.Hits|len) 0}}
本次搜索共找到结果 {{.Hits.Total}} 条 (用时 {{.Took}} 秒)
{{range .Hits.Hits}}
{{if .Source.Img}}
{{end}}
{{dateformat .Source.CreateTime "2006-01-02"}} ... {{str2html (join .Highlight.Content "...")}} ...
{{end}}{{else}}
没有找到任何结果,请更换查询词试试~
或者试试 Google 站内搜索:site:{{$.Domain}} {{$.Word}}
{{end}}{{end}}{{else}}
热搜词:{{range .HotWords}}{{.}}{{end}}

支持的搜索格式:

  1. 输入关键词全文搜索:HTTP/2 性能优化
  2. 指定时间段搜索:date:2014date:2015-05
  3. 指定标签搜索:tag:性能优化tag:HTTPS
  4. 组合搜索:date:2015 tag:HTTP 优化
{{end}}
{{if or .Prev .Next}}{{end}}
{{end}} \ No newline at end of file