mirror of https://github.com/glanceapp/glance.git
Add search box
parent
7743664527
commit
0f01a8eda5
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
@ -0,0 +1,18 @@
|
|||||||
|
{{ template "widget-base.html" . }}
|
||||||
|
<!-- Search box -->
|
||||||
|
{{ define "widget-content" }}
|
||||||
|
<form class="search-form" action="{{ .SearchURL }}" method="get">
|
||||||
|
<div class="search-input-container">
|
||||||
|
<input type="text" class="search-input" value name="q" placeholder="Search...">
|
||||||
|
<button type="submit" class="search-button">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
|
||||||
|
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
|
||||||
|
class="icon icon-tabler icons-tabler-outline icon-tabler-search">
|
||||||
|
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
|
||||||
|
<path d="M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0" />
|
||||||
|
<path d="M21 21l-6 -6" />
|
||||||
|
</svg>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
{{ end }}
|
||||||
@ -0,0 +1,30 @@
|
|||||||
|
package widget
|
||||||
|
|
||||||
|
import (
|
||||||
|
"html/template"
|
||||||
|
|
||||||
|
"github.com/glanceapp/glance/internal/assets"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Search struct {
|
||||||
|
widgetBase `yaml:",inline"`
|
||||||
|
SearchURL string `yaml:"search-url"`
|
||||||
|
Query string `yaml:"query"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Search) Initialize() error {
|
||||||
|
widget.withTitle("Search").withError(nil)
|
||||||
|
|
||||||
|
if widget.SearchURL == "" {
|
||||||
|
// set to the duckduckgo search engine
|
||||||
|
widget.SearchURL = "https://duckduckgo.com/?q="
|
||||||
|
}
|
||||||
|
|
||||||
|
// if no query is provided, leave an empty string
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Search) Render() template.HTML {
|
||||||
|
return widget.render(widget, assets.SearchTemplate)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue