diff --git a/jobs/mal-sync/character.go b/jobs/mal-sync/character.go index b2510b6e..0e65f65b 100644 --- a/jobs/mal-sync/character.go +++ b/jobs/mal-sync/character.go @@ -86,8 +86,40 @@ func parseCharacterDescription(input string) (output string, attributes []*arn.C paragraph = strings.TrimSpace(paragraph) // Skip paragraph if it's too short. - if len(paragraph) < 30 { - if !strings.HasSuffix(paragraph, ".") || strings.HasSuffix(paragraph, "...") { + if len(paragraph) < 30 && !strings.HasSuffix(paragraph, ".") || strings.HasSuffix(paragraph, "...") { + continue + } + + // Is it an attribute? + if strings.Contains(paragraph, ":") { + parts := strings.Split(paragraph, ":") + name := strings.TrimSpace(parts[0]) + value := strings.TrimSpace(parts[1]) + + // Remove list indicators + name = strings.TrimPrefix(name, "- ") + name = strings.TrimPrefix(name, "* ") + + if strings.HasPrefix(name, "~") && strings.HasSuffix(value, "~") { + name = strings.TrimPrefix(name, "~") + value = strings.TrimSuffix(value, "~") + } + + if strings.HasPrefix(name, "[") && strings.HasSuffix(value, "]") { + name = strings.TrimPrefix(name, "[") + value = strings.TrimSuffix(value, "]") + } + + if name == "source" || name == "sources" { + name = "Source" + } + + if len(name) < 25 && len(value) < 40 && !strings.HasSuffix(value, ".") { + // fmt.Println(color.GreenString(name), color.YellowString(value)) + attributes = append(attributes, &arn.CharacterAttribute{ + Name: name, + Value: value, + }) continue } } diff --git a/mixins/Quote.pixy b/mixins/Quote.pixy index 397e5d3f..55c96e10 100644 --- a/mixins/Quote.pixy +++ b/mixins/Quote.pixy @@ -31,10 +31,7 @@ component QuoteCharacter(quote *arn.Quote, user *arn.User) CharacterSmall(quote.Character(), user) component QuoteTextPreview(quote *arn.Quote) - if len(quote.Text.English) > 170 - blockquote!= utils.RenderQuoteText(quote.Text.English[:167] + "...") - else - blockquote!= utils.RenderQuoteText(quote.Text.English) + blockquote!= utils.RenderQuoteText(utils.CutLongDescription(quote.Text.English)) component QuoteFooter(quote *arn.Quote) .quote-footer diff --git a/pages/character/character.go b/pages/character/character.go index c85f789e..cb6743dc 100644 --- a/pages/character/character.go +++ b/pages/character/character.go @@ -12,7 +12,6 @@ import ( ) const ( - maxDescriptionLength = 170 maxRelevantCharacters = 12 ) @@ -93,11 +92,7 @@ func Get(ctx *aero.Context) string { arn.SortQuotesPopularFirst(quotes) // Set OpenGraph attributes - description := character.Description - - if len(description) > maxDescriptionLength { - description = description[:maxDescriptionLength-3] + "..." - } + description := utils.CutLongDescription(character.Description) ctx.Data = &arn.OpenGraph{ Tags: map[string]string{