Improved exploration
This commit is contained in:
parent
10ef00a810
commit
750302b60e
@ -14,37 +14,49 @@ const maxPopularAnime = 10
|
||||
func main() {
|
||||
color.Yellow("Caching popular anime")
|
||||
|
||||
// Fetch all anime
|
||||
animeList, err := arn.AllAnime()
|
||||
arn.PanicOnError(err)
|
||||
|
||||
if err != nil {
|
||||
color.Red("Failed fetching anime channel")
|
||||
color.Red(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// Overall
|
||||
sort.Slice(animeList, func(i, j int) bool {
|
||||
return animeList[i].Rating.Overall > animeList[j].Rating.Overall
|
||||
})
|
||||
|
||||
// Change size of anime list to 10
|
||||
animeList = animeList[:maxPopularAnime]
|
||||
saveAs(animeList[:maxPopularAnime], "best anime overall")
|
||||
|
||||
// Convert to small anime list
|
||||
// Story
|
||||
sort.Slice(animeList, func(i, j int) bool {
|
||||
return animeList[i].Rating.Story > animeList[j].Rating.Story
|
||||
})
|
||||
|
||||
saveAs(animeList[:maxPopularAnime], "best anime story")
|
||||
|
||||
// Visuals
|
||||
sort.Slice(animeList, func(i, j int) bool {
|
||||
return animeList[i].Rating.Visuals > animeList[j].Rating.Visuals
|
||||
})
|
||||
|
||||
saveAs(animeList[:maxPopularAnime], "best anime visuals")
|
||||
|
||||
// Soundtrack
|
||||
sort.Slice(animeList, func(i, j int) bool {
|
||||
return animeList[i].Rating.Soundtrack > animeList[j].Rating.Soundtrack
|
||||
})
|
||||
|
||||
saveAs(animeList[:maxPopularAnime], "best anime soundtrack")
|
||||
|
||||
// Done.
|
||||
color.Green("Finished.")
|
||||
}
|
||||
|
||||
// Convert to ListOfIDs and save in cache.
|
||||
func saveAs(list []*arn.Anime, cacheKey string) {
|
||||
cache := &arn.ListOfIDs{}
|
||||
|
||||
for _, anime := range animeList {
|
||||
for _, anime := range list {
|
||||
cache.IDList = append(cache.IDList, anime.ID)
|
||||
}
|
||||
|
||||
println(len(cache.IDList))
|
||||
|
||||
saveErr := arn.DB.Set("Cache", "popular anime", cache)
|
||||
|
||||
if saveErr != nil {
|
||||
color.Red("Error saving popular anime")
|
||||
color.Red(saveErr.Error())
|
||||
return
|
||||
}
|
||||
|
||||
color.Green("Finished.")
|
||||
arn.PanicOnError(arn.DB.Set("Cache", cacheKey, cache))
|
||||
}
|
||||
|
6
main.go
6
main.go
@ -9,10 +9,10 @@ import (
|
||||
"github.com/animenotifier/notify.moe/layout"
|
||||
"github.com/animenotifier/notify.moe/middleware"
|
||||
"github.com/animenotifier/notify.moe/pages/admin"
|
||||
"github.com/animenotifier/notify.moe/pages/airing"
|
||||
"github.com/animenotifier/notify.moe/pages/anime"
|
||||
"github.com/animenotifier/notify.moe/pages/animelist"
|
||||
"github.com/animenotifier/notify.moe/pages/animelistitem"
|
||||
"github.com/animenotifier/notify.moe/pages/best"
|
||||
"github.com/animenotifier/notify.moe/pages/dashboard"
|
||||
"github.com/animenotifier/notify.moe/pages/editanime"
|
||||
"github.com/animenotifier/notify.moe/pages/embed"
|
||||
@ -57,9 +57,10 @@ func configure(app *aero.Application) *aero.Application {
|
||||
|
||||
// Ajax routes
|
||||
app.Ajax("/", dashboard.Get)
|
||||
app.Ajax("/anime", explore.Get)
|
||||
app.Ajax("/anime/:id", anime.Get)
|
||||
app.Ajax("/anime/:id/edit", editanime.Get)
|
||||
app.Ajax("/best/anime", best.Get)
|
||||
app.Ajax("/explore", explore.Get)
|
||||
app.Ajax("/forum", forums.Get)
|
||||
app.Ajax("/forum/:tag", forum.Get)
|
||||
app.Ajax("/threads/:id", threads.Get)
|
||||
@ -81,7 +82,6 @@ func configure(app *aero.Application) *aero.Application {
|
||||
app.Ajax("/search/:term", search.Get)
|
||||
app.Ajax("/users", users.Get)
|
||||
app.Ajax("/login", login.Get)
|
||||
app.Ajax("/airing", airing.Get)
|
||||
app.Ajax("/webdev", webdev.Get)
|
||||
app.Ajax("/extension/embed", embed.Get)
|
||||
// app.Ajax("/genres", genres.Get)
|
||||
|
@ -15,7 +15,7 @@ component LoggedOutMenu
|
||||
.extra-navigation
|
||||
NavigationButton("Users", "/users", "globe")
|
||||
|
||||
NavigationButton("Anime", "/anime", "th")
|
||||
NavigationButton("Explore", "/explore", "th")
|
||||
NavigationButton("Login", "/login", "sign-in")
|
||||
|
||||
component LoggedInMenu(user *arn.User)
|
||||
@ -34,7 +34,7 @@ component LoggedInMenu(user *arn.User)
|
||||
NavigationButton("Users", "/users", "globe")
|
||||
|
||||
.extra-navigation
|
||||
NavigationButton("Anime", "/anime", "th")
|
||||
NavigationButton("Explore", "/explore", "th")
|
||||
|
||||
NavigationButton("Settings", "/settings", "cog")
|
||||
|
||||
|
@ -1,21 +0,0 @@
|
||||
package airing
|
||||
|
||||
import (
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
)
|
||||
|
||||
// Get ...
|
||||
func Get(ctx *aero.Context) string {
|
||||
var cache arn.ListOfIDs
|
||||
err := arn.DB.GetObject("Cache", "airing anime", &cache)
|
||||
|
||||
airing, err := arn.GetAiringAnimeCached()
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(500, "Couldn't fetch airing anime", err)
|
||||
}
|
||||
|
||||
return ctx.HTML(components.Airing(airing))
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
component Airing(animeList []*arn.Anime)
|
||||
h2.page-title(title=toString(len(animeList)) + " anime") Airing
|
||||
AnimeGrid(animeList)
|
@ -38,7 +38,10 @@ component Anime(anime *arn.Anime, tracks []*arn.SoundTrack, user *arn.User, epis
|
||||
h3.anime-section-name Ratings
|
||||
.anime-rating-categories
|
||||
.anime-rating-category(title=toString(anime.Rating.Overall))
|
||||
.anime-rating-category-name Overall
|
||||
if anime.Status == "upcoming"
|
||||
.anime-rating-category-name Hype
|
||||
else
|
||||
.anime-rating-category-name Overall
|
||||
Rating(anime.Rating.Overall)
|
||||
.anime-rating-category(title=toString(anime.Rating.Story))
|
||||
.anime-rating-category-name Story
|
||||
|
@ -14,7 +14,7 @@ component AnimeListItem(viewUser *arn.User, item *arn.AnimeListItem, anime *arn.
|
||||
option(value=arn.AnimeListStatusDropped) Dropped
|
||||
|
||||
.anime-list-item-rating-edit
|
||||
InputNumber("Rating.Overall", item.Rating.Overall, item.OverallRatingName(), "Overall rating on a scale of 0 to 10", "0", "10", "0.1")
|
||||
InputNumber("Rating.Overall", item.Rating.Overall, arn.OverallRatingName(item.Episodes), "Overall rating on a scale of 0 to 10", "0", "10", "0.1")
|
||||
InputNumber("Rating.Story", item.Rating.Story, "Story", "Story rating on a scale of 0 to 10", "0", "10", "0.1")
|
||||
InputNumber("Rating.Visuals", item.Rating.Visuals, "Visuals", "Visuals rating on a scale of 0 to 10", "0", "10", "0.1")
|
||||
InputNumber("Rating.Soundtrack", item.Rating.Soundtrack, "Soundtrack", "Soundtrack rating on a scale of 0 to 10", "0", "10", "0.1")
|
||||
|
46
pages/best/best.go
Normal file
46
pages/best/best.go
Normal file
@ -0,0 +1,46 @@
|
||||
package best
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
)
|
||||
|
||||
const maxEntries = 7
|
||||
|
||||
// Get search page.
|
||||
func Get(ctx *aero.Context) string {
|
||||
overall, err := arn.GetListOfAnimeCached("best anime overall")
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Error fetching popular anime", err)
|
||||
}
|
||||
|
||||
story, err := arn.GetListOfAnimeCached("best anime story")
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Error fetching popular anime", err)
|
||||
}
|
||||
|
||||
visuals, err := arn.GetListOfAnimeCached("best anime visuals")
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Error fetching popular anime", err)
|
||||
}
|
||||
|
||||
soundtrack, err := arn.GetListOfAnimeCached("best anime soundtrack")
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Error fetching popular anime", err)
|
||||
}
|
||||
|
||||
airing, err := arn.GetAiringAnimeCached()
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(500, "Couldn't fetch airing anime", err)
|
||||
}
|
||||
|
||||
return ctx.HTML(components.BestAnime(overall[:maxEntries], story[:maxEntries], visuals[:maxEntries], soundtrack[:maxEntries], airing[:maxEntries]))
|
||||
}
|
15
pages/best/best.pixy
Normal file
15
pages/best/best.pixy
Normal file
@ -0,0 +1,15 @@
|
||||
component BestAnime(overall []*arn.Anime, story []*arn.Anime, visuals []*arn.Anime, soundtrack []*arn.Anime, airing []*arn.Anime)
|
||||
h2 Currently Airing
|
||||
AnimeGrid(airing)
|
||||
|
||||
h2 Best Overall
|
||||
AnimeGrid(overall)
|
||||
|
||||
h2 Best Story
|
||||
AnimeGrid(story)
|
||||
|
||||
h2 Best Visuals
|
||||
AnimeGrid(visuals)
|
||||
|
||||
h2 Best Soundtrack
|
||||
AnimeGrid(soundtrack)
|
@ -1,20 +1,21 @@
|
||||
package explore
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
)
|
||||
|
||||
// Get search page.
|
||||
// Get ...
|
||||
func Get(ctx *aero.Context) string {
|
||||
animeList, err := arn.GetPopularAnimeCached()
|
||||
var cache arn.ListOfIDs
|
||||
err := arn.DB.GetObject("Cache", "airing anime", &cache)
|
||||
|
||||
airing, err := arn.GetAiringAnimeCached()
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Error fetching popular anime", err)
|
||||
return ctx.Error(500, "Couldn't fetch airing anime", err)
|
||||
}
|
||||
|
||||
return ctx.HTML(components.ExploreAnime(nil, nil, animeList))
|
||||
return ctx.HTML(components.Airing(airing))
|
||||
}
|
||||
|
@ -1,9 +1,3 @@
|
||||
component ExploreAnime(overall []*arn.Anime, story []*arn.Anime, airing []*arn.Anime)
|
||||
h2 Highest Rating
|
||||
AnimeGrid(overall)
|
||||
|
||||
h2 Best Story
|
||||
AnimeGrid(story)
|
||||
|
||||
h2 Currently Airing
|
||||
AnimeGrid(airing)
|
||||
component Airing(animeList []*arn.Anime)
|
||||
h2.page-title(title=toString(len(animeList)) + " anime") Explore
|
||||
AnimeGrid(animeList)
|
Loading…
Reference in New Issue
Block a user