Updated sync

This commit is contained in:
Eduard Urbach 2018-11-01 09:43:12 +09:00
parent dec90b056e
commit 3a33853c4a
3 changed files with 36 additions and 12 deletions

View File

@ -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
}
}

View File

@ -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

View File

@ -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{