search for a book with a single value
This commit is contained in:
+43
-1
@@ -1,4 +1,46 @@
|
||||
{{ define "content" }}
|
||||
<h3>A simple API to store, search and download books.</h3>
|
||||
<p>No extra JS, CSS or fancy stuff. You click, you search, you found, you're happy.</p>
|
||||
<div>No extra JS, CSS or fancy stuff. You click, you search, you found, you're happy.</div>
|
||||
<form action="/home" method="post" enctype="multipart/form-data">
|
||||
<div class="main-container">
|
||||
<div class="form-item">
|
||||
<div class="form-container">
|
||||
<h4>Search</h4>
|
||||
</div>
|
||||
<div class="form-container">
|
||||
<input type="text" name="search" value="{{.Search.Value}}" />
|
||||
</div>
|
||||
{{ if .Search.Err }}
|
||||
<div class="error">{{.Search.Err}}</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
<div class="form-item">
|
||||
<div class="form-container">
|
||||
<button id="submit" type="submit">Search</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{{ if ne (errStr .Error) "" }}
|
||||
<div class="error">{{.Error | errStr}}</div>
|
||||
{{ end }}
|
||||
<table>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Editor</th>
|
||||
<th>Authors</th>
|
||||
<th>Year</th>
|
||||
</tr>
|
||||
{{range .Results}}
|
||||
<tr>
|
||||
<td><div style="margin: 10px;">{{.Name}}</div></td>
|
||||
<td style="text-align: center;"><div style="margin: 10px;">{{.Editor}}</div></td>
|
||||
<td style="text-align: center;"><div style="margin: 10px;">{{.Authors | join }}</div></td>
|
||||
<td><div style="margin: 20px;">{{.Year}}</div></td>
|
||||
<td><div style="margin: 20px;">{{.Path | bookUrl}}</div></td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</table>
|
||||
|
||||
</ul>
|
||||
{{ end }}
|
||||
@@ -2,8 +2,10 @@ package templates
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"mime/multipart"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -52,6 +54,10 @@ var funcMap = template.FuncMap{
|
||||
}
|
||||
return ""
|
||||
},
|
||||
"bookUrl": func(path string) string {
|
||||
_, filename := filepath.Split(path)
|
||||
return fmt.Sprintf("https://books.thegux.fr/downloads/%s", filename)
|
||||
},
|
||||
}
|
||||
|
||||
var homeTmpl = sync.OnceValue[*template.Template](func() *template.Template {
|
||||
@@ -60,7 +66,7 @@ var homeTmpl = sync.OnceValue[*template.Template](func() *template.Template {
|
||||
log.Fatal().Err(err).Msg("unable to parse base tmpl")
|
||||
}
|
||||
|
||||
if _, err := baseTmpl.New("home").Parse(home); err != nil {
|
||||
if _, err := baseTmpl.New("home").Funcs(funcMap).Parse(home); err != nil {
|
||||
log.Fatal().Err(err).Msg("unable to parse home tmpl")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user