Added canonical title diff

This commit is contained in:
Eduard Urbach 2018-03-09 04:58:36 +01:00
parent ee04951f0e
commit 3ac77b889b
6 changed files with 71 additions and 28 deletions

View File

@ -59,6 +59,15 @@ func CompareMAL(ctx *aero.Context) string {
malAnime := obj.(*mal.Anime) malAnime := obj.(*mal.Anime)
var differences []utils.AnimeDiff var differences []utils.AnimeDiff
// Compare titles
if anime.Title.Canonical != malAnime.Title {
differences = append(differences, &utils.AnimeTitleDiff{
TitleA: anime.Title.Canonical,
TitleB: malAnime.Title,
})
}
// Compare genres
sumA := uint64(0) sumA := uint64(0)
for _, genre := range anime.Genres { for _, genre := range anime.Genres {
@ -84,6 +93,7 @@ func CompareMAL(ctx *aero.Context) string {
}) })
} }
// Add if there were any differences
if len(differences) > 0 { if len(differences) > 0 {
comparisons = append(comparisons, &utils.MALComparison{ comparisons = append(comparisons, &utils.MALComparison{
Anime: anime, Anime: anime,

View File

@ -1,6 +1,6 @@
component CompareMAL(comparisons []*utils.MALComparison, user *arn.User) component CompareMAL(comparisons []*utils.MALComparison, user *arn.User)
EditorTabs EditorTabs
h1.mountable MAL Comparison h1.mountable MAL comparison
.data-comparisons .data-comparisons
each comparison in comparisons each comparison in comparisons
@ -9,9 +9,11 @@ component CompareMAL(comparisons []*utils.MALComparison, user *arn.User)
.data-comparison-image-container .data-comparison-image-container
img.data-comparison-image.lazy(data-src=comparison.Anime.Image("small"), data-webp="true", alt=comparison.Anime.Title.ByUser(user)) img.data-comparison-image.lazy(data-src=comparison.Anime.Image("small"), data-webp="true", alt=comparison.Anime.Title.ByUser(user))
.data-comparison-titles .data-comparison-title
a.data-comparison-title(href=comparison.Anime.Link(), target="_blank")= comparison.Anime.Title.Canonical a(href=comparison.Anime.Link(), target="_blank")= comparison.Anime.Title.Canonical
a.data-comparison-title(href=comparison.MALAnime.URL, target="_blank")= comparison.MALAnime.Title .spacer
a(href=comparison.MALAnime.URL, target="_blank")
RawIcon("external-link")
.data-comparison-differences .data-comparison-differences
each difference in comparison.Differences each difference in comparison.Differences

View File

@ -8,6 +8,7 @@
vertical vertical
padding 0.5rem 0.75rem padding 0.5rem 0.75rem
margin 0.5rem margin 0.5rem
border-left 3px solid ui-border-color
.data-comparison-header .data-comparison-header
horizontal horizontal
@ -18,20 +19,21 @@
.data-comparison-image .data-comparison-image
anime-list-item-image anime-list-item-image
.data-comparison-titles
vertical
.data-comparison-title .data-comparison-title
line-height 1.5em horizontal
font-size 1.2rem
flex 1
align-items center
.data-comparison-differences .data-comparison-differences
vertical vertical
margin-top 0.5rem
.data-comparison-difference .data-comparison-difference
vertical vertical
ui-element ui-element
padding 0.5rem 0.75rem padding 0.5rem 0.75rem
margin 0.5rem 0 margin-bottom 0.5rem
.data-comparison-difference-title .data-comparison-difference-title
font-weight bold font-weight bold

24
utils/AnimeGenresDiff.go Normal file
View File

@ -0,0 +1,24 @@
package utils
import "strings"
// AnimeGenresDiff describes differing genres.
type AnimeGenresDiff struct {
GenresA []string
GenresB []string
}
// String returns the description.
func (diff *AnimeGenresDiff) String() string {
return "Genres are different"
}
// DetailsA shows the details for the first anime.
func (diff *AnimeGenresDiff) DetailsA() string {
return strings.Join(diff.GenresA, ", ")
}
// DetailsB shows the details for the second anime.
func (diff *AnimeGenresDiff) DetailsB() string {
return strings.Join(diff.GenresB, ", ")
}

22
utils/AnimeTitleDiff.go Normal file
View File

@ -0,0 +1,22 @@
package utils
// AnimeTitleDiff describes differing titles.
type AnimeTitleDiff struct {
TitleA string
TitleB string
}
// String returns the description.
func (diff *AnimeTitleDiff) String() string {
return "Titles are different"
}
// DetailsA shows the details for the first anime.
func (diff *AnimeTitleDiff) DetailsA() string {
return diff.TitleA
}
// DetailsB shows the details for the second anime.
func (diff *AnimeTitleDiff) DetailsB() string {
return diff.TitleB
}

View File

@ -1,35 +1,18 @@
package utils package utils
import ( import (
"strings"
"github.com/animenotifier/arn" "github.com/animenotifier/arn"
"github.com/animenotifier/mal" "github.com/animenotifier/mal"
) )
// AnimeDiff describes a difference between two anime.
type AnimeDiff interface { type AnimeDiff interface {
String() string String() string
DetailsA() string DetailsA() string
DetailsB() string DetailsB() string
} }
type AnimeGenresDiff struct { // MALComparison encapsulates the difference between an ARN anime and a MAL anime.
GenresA []string
GenresB []string
}
func (diff *AnimeGenresDiff) String() string {
return "Genres are different"
}
func (diff *AnimeGenresDiff) DetailsA() string {
return strings.Join(diff.GenresA, ", ")
}
func (diff *AnimeGenresDiff) DetailsB() string {
return strings.Join(diff.GenresB, ", ")
}
type MALComparison struct { type MALComparison struct {
Anime *arn.Anime Anime *arn.Anime
MALAnime *mal.Anime MALAnime *mal.Anime