diff --git a/html/search.html b/html/search.html
index 71268fd..387f7e1 100644
--- a/html/search.html
+++ b/html/search.html
@@ -2,6 +2,7 @@
{{ template "nav" . }}
{{ .Data.Title }} {{ if ne .Data.Site "" }} for {{ .Data.Site }} {{ end }}
+
-
+ {{ if ne .Data.Site "" }}
+
+
+ {{ else }}
+
+ {{ end }}
{{ range $index, $a := .Data.Pages }}
diff --git a/server/server.go b/server/server.go
index 12b827c..80011cc 100644
--- a/server/server.go
+++ b/server/server.go
@@ -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:" 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, "")
}
}