mirror of
https://github.com/Xevion/glance.git
synced 2025-12-10 06:07:20 -06:00
Add search box
This commit is contained in:
30
internal/widget/search.go
Normal file
30
internal/widget/search.go
Normal file
@@ -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)
|
||||
}
|
||||
@@ -45,6 +45,8 @@ func New(widgetType string) (Widget, error) {
|
||||
return &TwitchChannels{}, nil
|
||||
case "repository":
|
||||
return &Repository{}, nil
|
||||
case "search":
|
||||
return &Search{}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown widget type: %s", widgetType)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user