Simplified search route

This commit is contained in:
Eduard Urbach 2017-11-11 16:16:25 +01:00
parent 3de29e9925
commit 783c3f878c
3 changed files with 5 additions and 18 deletions

View File

@ -139,8 +139,7 @@ func Configure(app *aero.Application) {
l.Page("/compare/animelist/:nick-1/:nick-2", compare.AnimeList)
// Search
l.Page("/search", search.Get)
l.Page("/search/:term", search.Get)
l.Page("/search/*term", search.Get)
// Shop
l.Page("/shop", shop.Get)

View File

@ -1,6 +1,8 @@
package search
import (
"strings"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
@ -14,7 +16,8 @@ const maxTracks = 4
// Get search page.
func Get(ctx *aero.Context) string {
term := ctx.Query("q")
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
users, animes, posts, threads, tracks := arn.Search(term, maxUsers, maxAnime, maxPosts, maxThreads, maxTracks)
return ctx.HTML(components.SearchResults(term, users, animes, posts, threads, tracks))

View File

@ -25,21 +25,6 @@ func rewrite(ctx *aero.RewriteContext) {
return
}
// Search
if strings.HasPrefix(requestURI, "/search/") {
searchTerm := requestURI[len("/search/"):]
ctx.Request.URL.RawQuery = "q=" + searchTerm
ctx.SetURI("/search")
return
}
if strings.HasPrefix(requestURI, "/_/search/") {
searchTerm := requestURI[len("/_/search/"):]
ctx.Request.URL.RawQuery = "q=" + searchTerm
ctx.SetURI("/_/search")
return
}
// Analytics
if requestURI == "/dark-flame-master" {
ctx.SetURI("/api/new/analytics")