diff --git a/plugins/fact/fact.templ b/plugins/fact/fact.templ
new file mode 100644
index 0000000..b821bb7
--- /dev/null
+++ b/plugins/fact/fact.templ
@@ -0,0 +1,51 @@
+package fact
+
+import "fmt"
+
+templ (p *FactoidPlugin) factIndex() {
+
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var4 string
+ templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(fact.Fact)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `plugins/fact/fact.templ`, Line: 44, Col: 23}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" | ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var5 string
+ templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(fact.Tidbit)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `plugins/fact/fact.templ`, Line: 45, Col: 25}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" | ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var6 string
+ templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(fact.Owner)
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `plugins/fact/fact.templ`, Line: 46, Col: 24}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" | ")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ var templ_7745c5c3_Var7 string
+ templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprint(fact.Count))
+ if templ_7745c5c3_Err != nil {
+ return templ.Error{Err: templ_7745c5c3_Err, FileName: `plugins/fact/fact.templ`, Line: 47, Col: 36}
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" |
")
+ if templ_7745c5c3_Err != nil {
+ return templ_7745c5c3_Err
+ }
+ if !templ_7745c5c3_IsBuffer {
+ _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
+ }
+ return templ_7745c5c3_Err
+ })
+}
diff --git a/plugins/fact/web.go b/plugins/fact/web.go
index 2a9fbc7..ba7069f 100644
--- a/plugins/fact/web.go
+++ b/plugins/fact/web.go
@@ -2,7 +2,6 @@ package fact
import (
"embed"
- "encoding/json"
"fmt"
"github.com/go-chi/chi/v5"
"html/template"
@@ -16,7 +15,7 @@ var embeddedFS embed.FS
// Register any web URLs desired
func (p *FactoidPlugin) registerWeb() {
r := chi.NewRouter()
- r.HandleFunc("/api", p.serveAPI)
+ r.Post("/search", p.handleSearch)
r.HandleFunc("/req", p.serveQuery)
r.HandleFunc("/", p.serveQuery)
p.b.GetWeb().RegisterWebName(r, "/factoid", "Factoid")
@@ -32,39 +31,19 @@ func linkify(text string) template.HTML {
return template.HTML(strings.Join(parts, " "))
}
-func (p *FactoidPlugin) serveAPI(w http.ResponseWriter, r *http.Request) {
- if r.Method != http.MethodPost {
- fmt.Fprintf(w, "Incorrect HTTP method")
- return
- }
- info := struct {
- Query string `json:"query"`
- }{}
- decoder := json.NewDecoder(r.Body)
- err := decoder.Decode(&info)
+func (p *FactoidPlugin) handleSearch(w http.ResponseWriter, r *http.Request) {
+ query := r.FormValue("query")
+
+ entries, err := getFacts(p.db, query, "")
if err != nil {
w.WriteHeader(500)
fmt.Fprint(w, err)
return
}
- entries, err := getFacts(p.db, info.Query, "")
- if err != nil {
- w.WriteHeader(500)
- fmt.Fprint(w, err)
- return
- }
-
- data, err := json.Marshal(entries)
- if err != nil {
- w.WriteHeader(500)
- fmt.Fprint(w, err)
- return
- }
- w.Write(data)
+ p.searchResults(entries).Render(r.Context(), w)
}
func (p *FactoidPlugin) serveQuery(w http.ResponseWriter, r *http.Request) {
- index, _ := embeddedFS.ReadFile("index.html")
- w.Write(index)
+ p.b.GetWeb().Index("Fact", p.factIndex()).Render(r.Context(), w)
}