Refactor search and stringutils into separate modules

This commit is contained in:
Eduard Urbach 2018-04-19 22:01:28 +02:00
parent 99ad9610d3
commit 617e36bc52
12 changed files with 27 additions and 23 deletions

View File

@ -1,5 +1,5 @@
component Japanese(text string)
if arn.ContainsUnicodeLetters(text)
if stringutils.ContainsUnicodeLetters(text)
for _, token := range arn.JapaneseTokenizer.Tokenize(text)
if token.Furigana
a.japanese(href="http://jisho.org/search/" + token.Original, target="_blank", rel="noopener")

View File

@ -27,7 +27,7 @@ component Postable(post arn.Postable, user *arn.User, highlightAuthorID string)
.post-toolbar(id="toolbar-" + post.ID())
.spacer
.post-likes.tip(id="likes-" + post.ID(), aria-label=arn.Plural(len(post.Likes()), "like"))= "+" + strconv.Itoa(len(post.Likes()))
.post-likes.tip(id="likes-" + post.ID(), aria-label=stringutils.Plural(len(post.Likes()), "like"))= "+" + strconv.Itoa(len(post.Likes()))
if user != nil
if user.ID != post.Creator().ID

View File

@ -1,5 +1,5 @@
component Rating(value float64, userCount int, user *arn.User)
if user == nil
.anime-rating.tip(aria-label="Rated by " + arn.Plural(userCount, "user"))= fmt.Sprintf("%.1f", value)
.anime-rating.tip(aria-label="Rated by " + stringutils.Plural(userCount, "user"))= fmt.Sprintf("%.1f", value)
else
.anime-rating.tip(aria-label="Rated by " + arn.Plural(userCount, "user"))= fmt.Sprintf("%." + strconv.Itoa(user.Settings().Format.RatingsPrecision) + "f", value)
.anime-rating.tip(aria-label="Rated by " + stringutils.Plural(userCount, "user"))= fmt.Sprintf("%." + strconv.Itoa(user.Settings().Format.RatingsPrecision) + "f", value)

View File

@ -214,7 +214,7 @@ component AnimeInformation(anime *arn.Anime)
tr.mountable(data-mountable-type="info")
td.anime-info-key Season:
td.anime-info-value
a(href="/explore/anime/" + anime.StartDate[:4] + "/" + strings.ToLower(anime.Season()) + "/any/" + anime.Type)= arn.Capitalize(anime.Season()) + " " + anime.StartDate[:4]
a(href="/explore/anime/" + anime.StartDate[:4] + "/" + strings.ToLower(anime.Season()) + "/any/" + anime.Type)= stringutils.Capitalize(anime.Season()) + " " + anime.StartDate[:4]
if anime.Source != "" && arn.AnimeSourceHumanReadable[anime.Source] != ""
tr.mountable(data-mountable-type="info")

View File

@ -7,21 +7,21 @@ component Editor(url string, score int, scoreTitle string, scoreTypes map[string
RawIcon("tv")
.feature-card-text
p Anime
p.editor-score= arn.Plural(scoreTypes["Anime"], "contribution")
p.editor-score= stringutils.Plural(scoreTypes["Anime"], "contribution")
a.feature-card.mountable(href="/editor/soundtracks/links")
.feature-card-icon.feature-card-color-soundtrack
RawIcon("music")
.feature-card-text
p SoundTracks
p.editor-score= arn.Plural(scoreTypes["SoundTrack"], "contribution")
p.editor-score= stringutils.Plural(scoreTypes["SoundTrack"], "contribution")
a.feature-card.mountable(href="/editor/companies/description")
.feature-card-icon.feature-card-color-company
RawIcon("building-o")
.feature-card-text
p Companies
p.editor-score= arn.Plural(scoreTypes["Company"], "contribution")
p.editor-score= stringutils.Plural(scoreTypes["Company"], "contribution")
.footer.mountable
a.footer-element(href="/editor/mal/diff/anime" + user.Settings().Editor.Filter.Suffix()) MALdiff

View File

@ -5,6 +5,7 @@ import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/arn/stringutils"
)
// AnimeTitles returns a list of the 500 most popular anime titles.
@ -26,7 +27,7 @@ func AnimeTitles(ctx *aero.Context) string {
for _, anime := range popularAnime {
popularAnimeTitles = append(popularAnimeTitles, anime.Title.Canonical)
if arn.ContainsUnicodeLetters(anime.Title.Japanese) {
if stringutils.ContainsUnicodeLetters(anime.Title.Japanese) {
popularAnimeTitles = append(popularAnimeTitles, anime.Title.Japanese)
}
}

View File

@ -71,7 +71,7 @@ component ProfileHead(viewUser *arn.User, user *arn.User, uri string)
a(href="https://osu.ppy.sh/u/" + viewUser.Accounts.Osu.Nick, target="_blank", rel="noopener")= toString(int(viewUser.Accounts.Osu.PP)) + " pp"
if viewUser.Accounts.Overwatch.BattleTag != "" && viewUser.Accounts.Overwatch.SkillRating >= 1000
p.profile-field.overwatch(title=arn.Capitalize(viewUser.Accounts.Overwatch.Tier) + " (Overwatch)")
p.profile-field.overwatch(title=stringutils.Capitalize(viewUser.Accounts.Overwatch.Tier) + " (Overwatch)")
Icon("overwatch")
a(href="https://playoverwatch.com/en-us/career/pc/" + strings.Replace(viewUser.Accounts.Overwatch.BattleTag, "#", "-", 1), target="_blank", rel="noopener")= toString(viewUser.Accounts.Overwatch.SkillRating) + " SR"
@ -90,7 +90,7 @@ component ProfileHead(viewUser *arn.User, user *arn.User, uri string)
if viewUser.Role != ""
p.profile-field.role
Icon("rocket")
span= arn.Capitalize(viewUser.Role)
span= stringutils.Capitalize(viewUser.Role)
if viewUser.IsPro()
p.profile-field.profile-pro-status

View File

@ -7,6 +7,7 @@ import (
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/arn/search"
"github.com/animenotifier/notify.moe/components"
)
@ -25,7 +26,7 @@ func Get(ctx *aero.Context) string {
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
users, animes, posts, threads, tracks, characters, companies := arn.Search(
users, animes, posts, threads, tracks, characters, companies := search.All(
term,
maxUsers,
maxAnime,
@ -49,7 +50,7 @@ func Anime(ctx *aero.Context) string {
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
animes := arn.SearchAnime(term, maxAnime)
animes := search.Anime(term, maxAnime)
return ctx.HTML(components.AnimeSearchResults(animes))
}
@ -58,7 +59,7 @@ func Characters(ctx *aero.Context) string {
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
characters := arn.SearchCharacters(term, maxCharacters)
characters := search.Characters(term, maxCharacters)
return ctx.HTML(components.CharacterSearchResults(characters))
}
@ -71,9 +72,9 @@ func Forum(ctx *aero.Context) string {
var threads []*arn.Thread
flow.Parallel(func() {
posts = arn.SearchPosts(term, maxPosts)
posts = search.Posts(term, maxPosts)
}, func() {
threads = arn.SearchThreads(term, maxThreads)
threads = search.Threads(term, maxThreads)
})
return ctx.HTML(components.ForumSearchResults(posts, threads))
@ -84,7 +85,7 @@ func SoundTracks(ctx *aero.Context) string {
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
tracks := arn.SearchSoundTracks(term, maxSoundTracks)
tracks := search.SoundTracks(term, maxSoundTracks)
return ctx.HTML(components.SoundTrackSearchResults(tracks))
}
@ -93,7 +94,7 @@ func Users(ctx *aero.Context) string {
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
users := arn.SearchUsers(term, maxUsers)
users := search.Users(term, maxUsers)
return ctx.HTML(components.UserSearchResults(users))
}
@ -102,6 +103,6 @@ func Companies(ctx *aero.Context) string {
term := ctx.Get("term")
term = strings.TrimPrefix(term, "/")
companies := arn.SearchCompanies(term, maxCompanies)
companies := search.Companies(term, maxCompanies)
return ctx.HTML(components.CompanySearchResults(companies))
}

View File

@ -24,7 +24,7 @@ component ShopItem(item *arn.ShopItem, popularity int)
.shop-item-info-column
h3.shop-item-name= item.Name
.shop-item-popularity= arn.Plural(popularity, "user") + " bought this"
.shop-item-popularity= stringutils.Plural(popularity, "user") + " bought this"
//- span.shop-item-duration= " " + duration
//- .shop-item-description!= markdown.Render(item.Description)

View File

@ -1,6 +1,8 @@
package statistics
import (
"fmt"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
@ -47,7 +49,7 @@ func getAnimeStats() []*arn.PieChart {
anidb["Not connected with AniDB"]++
}
rating[arn.ToString(int(anime.Rating.Overall+0.5))]++
rating[fmt.Sprint(int(anime.Rating.Overall+0.5))]++
found := false
for _, episode := range anime.Episodes().Items {

View File

@ -42,7 +42,7 @@ func getUserStats() []*arn.PieChart {
pixelRatio[fmt.Sprintf("%.0f", info.Screen.PixelRatio)]++
size := arn.ToString(info.Screen.Width) + " x " + arn.ToString(info.Screen.Height)
size := fmt.Sprint(info.Screen.Width) + " x " + fmt.Sprint(info.Screen.Height)
screenSize[size]++
if info.Connection.EffectiveType != "" {

View File

@ -4,7 +4,7 @@ func main() {
// defer arn.Node.Close()
// for track := range arn.StreamSoundTracks() {
// if arn.ContainsUnicodeLetters(track.Title) {
// if stringutils.ContainsUnicodeLetters(track.Title) {
// track.Title.Native = track.Title
// } else {
// track.Title.Canonical = track.Title