diff --git a/jobs/sync-characters/sync-characters.go b/jobs/sync-characters/sync-characters.go index a7043f8a..0215cd72 100644 --- a/jobs/sync-characters/sync-characters.go +++ b/jobs/sync-characters/sync-characters.go @@ -2,6 +2,8 @@ package main import ( "fmt" + "path" + "strconv" "strings" "github.com/animenotifier/arn" @@ -17,11 +19,28 @@ func main() { for kitsuCharacter := range kitsuCharacters { character := &arn.Character{ - ID: kitsuCharacter.ID, - Name: kitsuCharacter.Attributes.Name, - Image: kitsu.FixImageURL(kitsuCharacter.Attributes.Image.Original), + ID: kitsuCharacter.ID, + Name: arn.CharacterName{ + Canonical: kitsuCharacter.Attributes.Name, + }, + Image: arn.CharacterImage{ + Extension: path.Ext(kitsu.FixImageURL(kitsuCharacter.Attributes.Image.Original)), + }, Description: kitsuCharacter.Attributes.Description, Attributes: []*arn.CharacterAttribute{}, + Mappings: []*arn.Mapping{ + &arn.Mapping{ + Service: "kitsu/character", + ServiceID: kitsuCharacter.ID, + }, + }, + } + + if kitsuCharacter.Attributes.MalID != 0 { + character.Mappings = append(character.Mappings, &arn.Mapping{ + Service: "myanimelist/character", + ServiceID: strconv.Itoa(kitsuCharacter.Attributes.MalID), + }) } // We use markdown, so replace
with two line breaks. diff --git a/jobs/sync-jikan-anime/sync-jikan-anime.go b/jobs/sync-jikan-anime/sync-jikan-anime.go deleted file mode 100644 index 3ddfbbc7..00000000 --- a/jobs/sync-jikan-anime/sync-jikan-anime.go +++ /dev/null @@ -1,52 +0,0 @@ -package main - -import ( - "fmt" - "time" - - "github.com/animenotifier/jikan" - - "github.com/animenotifier/arn" - "github.com/fatih/color" -) - -var jikanDB = arn.Node.Namespace("jikan") - -func main() { - color.Yellow("Syncing with Jikan API") - defer arn.Node.Close() - - count := 0 - - for anime := range arn.StreamAnime() { - malID := anime.GetMapping("myanimelist/anime") - - if malID != "" { - sync(anime, malID) - count++ - } - } - - color.Green("Finished syncing %d anime.", count) - - // Give OS some time to write buffers, just to be safe - time.Sleep(10 * time.Second) -} - -func sync(anime *arn.Anime, malID string) { - fmt.Printf("%s %s (MAL: %s)\n", anime.ID, anime.Title.Canonical, malID) - - if jikanDB.Exists("Anime", malID) { - return - } - - time.Sleep(2 * time.Second) - jikanAnime, err := jikan.GetAnime(malID) - - if err == nil { - jikanDB.Set("Anime", malID, jikanAnime) - return - } - - fmt.Printf("Error fetching %s: %v\n", malID, err) -} diff --git a/jobs/sync-jikan-characters/sync-jikan-characters.go b/jobs/sync-jikan-characters/sync-jikan-characters.go deleted file mode 100644 index 2ee5822b..00000000 --- a/jobs/sync-jikan-characters/sync-jikan-characters.go +++ /dev/null @@ -1,63 +0,0 @@ -package main - -import ( - "fmt" - "time" - - "github.com/animenotifier/jikan" - - "github.com/animenotifier/arn" - "github.com/fatih/color" -) - -var jikanDB = arn.Node.Namespace("jikan") - -func main() { - color.Yellow("Syncing characters with Jikan API") - defer arn.Node.Close() - - allAnime := jikanDB.All("Anime") - - count := 0 - - for animeObj := range allAnime { - anime := animeObj.(*jikan.Anime) - - if len(anime.Character) == 0 { - continue - } - - fmt.Println(anime.Title) - - for _, character := range anime.Character { - characterID := jikan.GetCharacterIDFromURL(character.URL) - - if characterID == "" { - fmt.Println("Invalid character ID") - continue - } - - fetchCharacter(characterID) - } - } - - color.Green("Finished syncing %d characters.", count) -} - -func fetchCharacter(malCharacterID string) { - fmt.Printf("Fetching character ID %s\n", malCharacterID) - - if jikanDB.Exists("Character", malCharacterID) { - return - } - - time.Sleep(500 * time.Millisecond) - character, err := jikan.GetCharacter(malCharacterID) - - if err == nil { - jikanDB.Set("Character", malCharacterID, character) - return - } - - fmt.Printf("Error fetching %s: %v\n", malCharacterID, err) -} diff --git a/pages/anime/character.pixy b/pages/anime/character.pixy index 4cd81216..7ae2d349 100644 --- a/pages/anime/character.pixy +++ b/pages/anime/character.pixy @@ -1,7 +1,7 @@ component Character(character *arn.Character) a.character(href="/character/" + character.ID) - img.character-image.lazy(data-src=character.Image, alt=character.Name, title=character.Name) + img.character-image.lazy(data-src=character.ImageLink("medium"), alt=character.Name, title=character.Name) component CharacterSmall(character *arn.Character) a.character(href="/character/" + character.ID) - img.character-image.character-image-small.lazy(data-src=character.Image, alt=character.Name, title=character.Name) \ No newline at end of file + img.character-image.character-image-small.lazy(data-src=character.ImageLink("small"), alt=character.Name, title=character.Name) \ No newline at end of file diff --git a/pages/character/character.go b/pages/character/character.go index 5b337a9c..a1f426aa 100644 --- a/pages/character/character.go +++ b/pages/character/character.go @@ -49,8 +49,8 @@ func Get(ctx *aero.Context) string { ctx.Data = &arn.OpenGraph{ Tags: map[string]string{ - "og:title": character.Name, - "og:image": "https:" + character.Image, + "og:title": character.Name.Canonical, + "og:image": "https:" + character.ImageLink("large"), "og:url": "https://" + ctx.App.Config.Domain + character.Link(), "og:site_name": "notify.moe", "og:description": description, @@ -61,7 +61,7 @@ func Get(ctx *aero.Context) string { }, Meta: map[string]string{ "description": description, - "keywords": character.Name + ",anime,character", + "keywords": character.Name.Canonical + ",anime,character", }, } diff --git a/pages/character/character.pixy b/pages/character/character.pixy index 62356fa4..299f88e3 100644 --- a/pages/character/character.pixy +++ b/pages/character/character.pixy @@ -3,11 +3,16 @@ component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime .character-left-column .character-header .character-image-container - img.character-image-fullsize(src=character.Image, alt=character.Name) + img.character-image-fullsize(src=character.ImageLink("large"), alt=character.Name.Canonical) .character-description-container - h1.character-name= character.Name + h1.character-name= character.Name.Canonical + .anime-alternative-title - Japanese("日本語の名前無し") + if character.Name.Japanese != "" + Japanese(character.Name.Japanese) + else + Japanese("日本語の名前無し") + .character-description!= markdown.Render(character.Description) h3 Anime diff --git a/pages/quote/edit.go b/pages/quote/edit.go index b4f0d9e0..515bc3a3 100644 --- a/pages/quote/edit.go +++ b/pages/quote/edit.go @@ -29,7 +29,7 @@ func Edit(ctx *aero.Context) string { } if quote.Character() != nil { - ctx.Data.(*arn.OpenGraph).Tags["og:image"] = quote.Character().Image + ctx.Data.(*arn.OpenGraph).Tags["og:image"] = quote.Character().ImageLink("large") } return ctx.HTML(components.QuoteTabs(quote, user) + editform.Render(quote, "Edit quote", user)) diff --git a/pages/quote/quote.go b/pages/quote/quote.go index 22bdfdb1..e4b4ec07 100644 --- a/pages/quote/quote.go +++ b/pages/quote/quote.go @@ -32,8 +32,8 @@ func Get(ctx *aero.Context) string { character, _ := arn.GetCharacter(quote.CharacterID) if character != nil { - openGraph.Tags["og:title"] = character.Name + "'s quote" - openGraph.Tags["og:image"] = "https:" + character.Image + openGraph.Tags["og:title"] = character.Name.Canonical + "'s quote" + openGraph.Tags["og:image"] = "https:" + character.ImageLink("large") } ctx.Data = openGraph diff --git a/utils/editform/editform.go b/utils/editform/editform.go index 4a7ac9ba..eacafc7a 100644 --- a/utils/editform/editform.go +++ b/utils/editform/editform.go @@ -157,7 +157,7 @@ func RenderField(b *bytes.Buffer, v *reflect.Value, field reflect.StructField, i character, err := arn.GetCharacter(characterID) if err == nil { - b.WriteString(components.EditFormImagePreview(character.Link(), character.Image, false)) + b.WriteString(components.EditFormImagePreview(character.Link(), character.ImageLink("small"), false)) } case "":