generated from ElnuDev/go-project
Implement route handling
This commit is contained in:
parent
fb045b9276
commit
36710478f2
3 changed files with 47 additions and 13 deletions
33
dict/templates/index.html
Normal file
33
dict/templates/index.html
Normal file
|
@ -0,0 +1,33 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>jidict</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/missing.css@1.0.9/dist/missing.min.css">
|
||||
<style>
|
||||
li {
|
||||
margin-top: 0.75em;
|
||||
}
|
||||
</style>
|
||||
<script src="https://unpkg.com/htmx.org@1.9.3"></script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<a href="/">
|
||||
<img src="https://jichan.org/logo.svg" style="height: 4em; display: block; margin: 1em auto 1em auto">
|
||||
</a>
|
||||
<form
|
||||
hx-post="/api/search"
|
||||
hx-on::before-request="this.setAttribute('hx-replace-url', `/search/${this.querySelector('input').value}`)"
|
||||
hx-target="#results"
|
||||
hx-swap="innerHTML">
|
||||
<input type="text" name="q"{{ with .Query }} value="{{ . }}"{{ end }} placeholder="辞書をサーチする" class="width:100%" autocomplete="false">
|
||||
</form>
|
||||
<div id="results">
|
||||
{{ with .Results }}{{ template "search" . }}{{ end }}
|
||||
</div>
|
||||
<br>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
|
@ -1,3 +1,4 @@
|
|||
{{- define "search" -}}
|
||||
<p><i>{{ if eq .Count 0 }}No results{{ else }}{{ .Count }} result{{ if ne .Count 1}}s{{ end }}{{ end }}.</i></p>
|
||||
{{- range .ExactResults -}}
|
||||
{{- template "word" . -}}
|
||||
|
@ -5,4 +6,6 @@
|
|||
<hr>
|
||||
{{ range .OtherResults -}}
|
||||
{{ template "word" . }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- template "search" . -}}
|
Reference in a new issue