kopia lustrzana https://github.com/cblgh/lieu
improve site:<domain> ux, add clear button
rodzic
0bf202d65b
commit
4f0b90d083
|
@ -2,6 +2,7 @@
|
|||
{{ template "nav" . }}
|
||||
<main id="results" class="flow2">
|
||||
<h1>{{ .Data.Title }} {{ if ne .Data.Site "" }} for {{ .Data.Site }} {{ end }}</h1>
|
||||
|
||||
<form method="GET" class="search">
|
||||
<label for="search">Search {{ .SiteName }} </label>
|
||||
<span class="search__input">
|
||||
|
@ -14,6 +15,16 @@
|
|||
</button>
|
||||
</span>
|
||||
</form>
|
||||
{{ if ne .Data.Site "" }}
|
||||
<!-- add a button to clear the search results if a site:<domain> param has been used -->
|
||||
<form method="GET" class="search">
|
||||
<span class="search__input">
|
||||
<input type="hidden" minlength="1" required name="q" placeholder="Search" value="{{ .Data.Query }}" class="search-box" id="search">
|
||||
<button type="submit" value="clear" name="clear">Clear</button>
|
||||
</button>
|
||||
</span>
|
||||
</form>
|
||||
{{ else }}
|
||||
<nav>
|
||||
<ul class="result-nav-list">
|
||||
<li title="content from webring sites only"
|
||||
|
@ -26,6 +37,7 @@
|
|||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
{{ end }}
|
||||
<article>
|
||||
<ul role="list" class="flow2 two-columns width-126ch">
|
||||
{{ range $index, $a := .Data.Pages }}
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"html/template"
|
||||
|
@ -57,6 +58,8 @@ var templates = template.Must(template.ParseFiles(
|
|||
|
||||
const useURLTitles = true
|
||||
|
||||
var sitePattern = regexp.MustCompile(`site:\S+`)
|
||||
|
||||
func (h RequestHandler) searchRoute(res http.ResponseWriter, req *http.Request) {
|
||||
var query string
|
||||
view := &TemplateView{}
|
||||
|
@ -74,6 +77,14 @@ func (h RequestHandler) searchRoute(res http.ResponseWriter, req *http.Request)
|
|||
domain = strings.TrimPrefix(parts[0], "https://")
|
||||
domain = strings.TrimPrefix(domain, "http://")
|
||||
domain = strings.TrimSuffix(domain, "/")
|
||||
} else if sitePattern.MatchString(query) {
|
||||
// if user searched with "site:<domain>" in text box, behave the same way as if a query param was used
|
||||
domain = sitePattern.FindString(query)[5:]
|
||||
}
|
||||
// if clear button was used -> clear site param / search text
|
||||
if parts, exists := params["clear"]; exists && parts[0] != "" {
|
||||
domain = ""
|
||||
query = sitePattern.ReplaceAllString(query, "")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue