fix search modifying in server

master
Bel LaPointe 2022-02-09 16:51:29 -07:00
parent 9fe6381245
commit 7ee04bbe8e
2 changed files with 8 additions and 5 deletions

View File

@ -281,10 +281,11 @@ func (server *Server) urlFileId(id []string) string {
if len(id) == 0 {
return ""
}
result := id[0]
for i := 1; i < len(id); i++ {
id[0] = strings.Join([]string{id[0], url.PathEscape(id[i])}, "/")
result = strings.Join([]string{result, url.PathEscape(id[i])}, "/")
}
return id[0]
return result
}
func (server *Server) fileId(r *http.Request) []string {
@ -350,7 +351,7 @@ func (server *Server) apiV0SearchHandler(w http.ResponseWriter, r *http.Request)
result := []string{}
if err := tree.ForEach(func(id []string, leaf Leaf) error {
for _, pattern := range patterns {
if !pattern.MatchString(leaf.Content) && !pattern.MatchString(fmt.Sprint(id)) {
if !pattern.MatchString(leaf.Content) && !pattern.MatchString(leaf.Title) {
return nil
}
}

View File

@ -5,7 +5,7 @@
<script src="https://cdn.jsdelivr.net/npm/easymde/dist/easymde.min.js"></script>
<script src="https://cdn.jsdelivr.net/highlight.js/latest/highlight.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/highlight.js/latest/styles/github.min.css">
<!-- TODO
<!-- todo css
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/light.css">
-->
<style>
@ -88,6 +88,7 @@
function searchFilesFor(q) {
http("GET", "/api/v0/search?q=" + q, (body, status) => {
var results = JSON.parse(body)
console.log(q, results)
results.sort()
var innerHTML = "<ul>"
for (var result in results)
@ -231,7 +232,7 @@
<body style="width: 90%; max-width: 1024px; margin: auto;" onload="init(); return false;">
<div style="width: 100%; display: flex; flex-direction: column;">
<form action="return false;" style="margin: 1em; display: flex; flex-direction: row;">
<input type="text" id="searchbox" style="flex-grow: 1;" placeholder="todo"/>
<input type="text" id="searchbox" style="flex-grow: 1;" placeholder="search regexp"/>
<input type="submit" value="search" onclick="searchFiles(); return false;"/>
</form>
<div style="width: 100%; display: flex; flex-direction: row; flex-grow: 1;">
@ -251,6 +252,7 @@
</div>
<div id="saveFeedback" style="min-height: 1.2em; text-align: right;">
</div>
<!-- todo: each line no is an anchor -->
<textarea id="my-text-area"></textarea>
</article>
</div>