diff --git a/jobs/search-index/search-index.go b/jobs/search-index/search-index.go index 8a16e1d9..fd52dfe6 100644 --- a/jobs/search-index/search-index.go +++ b/jobs/search-index/search-index.go @@ -36,7 +36,9 @@ func updateAnimeIndex() { animeSearchIndex.TextToID[strings.ToLower(anime.Title.English)] = anime.ID } - if anime.Title.Japanese != "" { + // Make sure we only include Japanese titles that actually contain unicode letters + // because otherwise they might overlap with the English titles. + if anime.Title.Japanese != "" && arn.ContainsUnicodeLetters(anime.Title.Japanese) { animeSearchIndex.TextToID[strings.ToLower(anime.Title.Japanese)] = anime.ID } diff --git a/main_test.go b/main_test.go index a766bc9f..7598d804 100644 --- a/main_test.go +++ b/main_test.go @@ -11,7 +11,7 @@ import ( func TestRoutes(t *testing.T) { app := configure(aero.New()) - for _, examples := range tests { + for _, examples := range routeTests { for _, example := range examples { request, err := http.NewRequest("GET", example, nil) diff --git a/pages/search/search.go b/pages/search/search.go index a7dd0516..df5f1a59 100644 --- a/pages/search/search.go +++ b/pages/search/search.go @@ -6,12 +6,12 @@ import ( "github.com/animenotifier/notify.moe/components" ) -const maxUsers = 9 * 7 -const maxAnime = 9 * 7 +const maxUsers = 9 * 4 +const maxAnime = 9 * 4 // Get search page. func Get(ctx *aero.Context) string { - term := ctx.Get("term") + term := ctx.Query("q") userResults, animeResults := arn.Search(term, maxUsers, maxAnime) return ctx.HTML(components.SearchResults(userResults, animeResults)) diff --git a/pages/search/search.pixy b/pages/search/search.pixy index 6e12b652..8439d587 100644 --- a/pages/search/search.pixy +++ b/pages/search/search.pixy @@ -7,7 +7,8 @@ component SearchResults(users []*arn.User, animeResults []*arn.Anime) p No users found. else each user in users - Avatar(user) + .mountable(data-mountable-type="user") + Avatar(user) //- a.ajax(href=user.Link())= user.Nick .widget @@ -17,5 +18,5 @@ component SearchResults(users []*arn.User, animeResults []*arn.Anime) p No anime found. else each anime in animeResults - a.profile-watching-list-item.ajax(href=anime.Link(), title=anime.Title.Canonical) + a.profile-watching-list-item.mountable.ajax(href=anime.Link(), title=anime.Title.Canonical, data-mountable-type="anime") img.anime-cover-image.anime-search-result(src=anime.Image.Tiny, alt=anime.Title.Canonical) \ No newline at end of file diff --git a/rewrite.go b/rewrite.go index a171a56b..8d66ef8a 100644 --- a/rewrite.go +++ b/rewrite.go @@ -18,10 +18,26 @@ func init() { newURI := "/user/" userName := requestURI[2:] ctx.SetURI(newURI + userName) - } else if strings.HasPrefix(requestURI, plusRouteAjax) { + return + } + + if strings.HasPrefix(requestURI, plusRouteAjax) { newURI := "/_/user/" userName := requestURI[4:] ctx.SetURI(newURI + userName) + return + } + + if strings.HasPrefix(requestURI, "/search/") { + searchTerm := requestURI[len("/search/"):] + ctx.Request.URL.RawQuery = "q=" + searchTerm + ctx.SetURI("/search") + } + + if strings.HasPrefix(requestURI, "/_/search/") { + searchTerm := requestURI[len("/_/search/"):] + ctx.Request.URL.RawQuery = "q=" + searchTerm + ctx.SetURI("/_/search") } }) } diff --git a/scripts/Actions.ts b/scripts/Actions.ts index a2431b15..69673e42 100644 --- a/scripts/Actions.ts +++ b/scripts/Actions.ts @@ -145,10 +145,10 @@ export function search(arn: AnimeNotifier, search: HTMLInputElement, e: Keyboard let term = search.value - if(!window.location.pathname.startsWith("/search/")) { - history.pushState("search", null, "/search/" + term) - } else { + if(window.location.pathname.startsWith("/search/")) { history.replaceState("search", null, "/search/" + term) + } else { + history.pushState("search", null, "/search/" + term) } if(!term || term.length < 2) { @@ -165,7 +165,7 @@ export function search(arn: AnimeNotifier, search: HTMLInputElement, e: Keyboard arn.app.content.appendChild(results) } - arn.app.get("/_/search/" + encodeURI(term)) + arn.app.get("/_/search/" + term) .then(html => { if(!search.value) { return diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index f51a828b..71e8a660 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -199,13 +199,23 @@ export class AnimeNotifier { } modifyDelayed(className: string, func: (element: HTMLElement) => void) { + let mountableTypes = { + general: 0 + } + const delay = 20 - const maxDelay = 500 + const maxDelay = 1000 let time = 0 for(let element of findAll(className)) { - time += delay + let type = element.dataset.mountableType || "general" + + if(type in mountableTypes) { + time = mountableTypes[element.dataset.mountableType] += delay + } else { + time = mountableTypes[element.dataset.mountableType] = 0 + } if(time > maxDelay) { func(element)