2021-12-27 09:54:27 -08:00
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
|
2022-11-02 16:23:26 -07:00
|
|
|
"github.com/mikestefanello/pagoda/pkg/controller"
|
2023-12-16 08:07:20 -08:00
|
|
|
"github.com/mikestefanello/pagoda/templates"
|
2021-12-27 09:54:27 -08:00
|
|
|
|
|
|
|
"github.com/labstack/echo/v4"
|
|
|
|
)
|
|
|
|
|
|
|
|
type (
|
2022-02-10 05:56:07 -08:00
|
|
|
search struct {
|
2021-12-27 09:54:27 -08:00
|
|
|
controller.Controller
|
|
|
|
}
|
|
|
|
|
2022-02-10 05:56:07 -08:00
|
|
|
searchResult struct {
|
2021-12-27 09:54:27 -08:00
|
|
|
Title string
|
|
|
|
URL string
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2022-02-10 05:56:07 -08:00
|
|
|
func (c *search) Get(ctx echo.Context) error {
|
2021-12-27 09:54:27 -08:00
|
|
|
page := controller.NewPage(ctx)
|
2023-12-16 08:07:20 -08:00
|
|
|
page.Layout = templates.LayoutMain
|
|
|
|
page.Name = templates.PageSearch
|
2021-12-27 09:54:27 -08:00
|
|
|
|
|
|
|
// Fake search results
|
2022-02-10 05:56:07 -08:00
|
|
|
var results []searchResult
|
2021-12-27 09:54:27 -08:00
|
|
|
if search := ctx.QueryParam("query"); search != "" {
|
|
|
|
for i := 0; i < 5; i++ {
|
|
|
|
title := "Lorem ipsum example ddolor sit amet"
|
|
|
|
index := rand.Intn(len(title))
|
|
|
|
title = title[:index] + search + title[index:]
|
2022-02-10 05:56:07 -08:00
|
|
|
results = append(results, searchResult{
|
2021-12-27 09:54:27 -08:00
|
|
|
Title: title,
|
|
|
|
URL: fmt.Sprintf("https://www.%s.com", search),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
page.Data = results
|
|
|
|
|
|
|
|
return c.RenderPage(ctx, page)
|
|
|
|
}
|