(title, body, lang string)
| 1335 | } |
| 1336 | |
| 1337 | func getSlugFromPost(title, body, lang string) string { |
| 1338 | if title == "" { |
| 1339 | // Remove Markdown, so e.g. link URLs and image alt text don't make it into the slug |
| 1340 | body = strings.TrimSpace(stripmd.StripOptions(body, stripmd.Options{SkipImages: true})) |
| 1341 | title = postTitle(body, body) |
| 1342 | } |
| 1343 | title = parse.PostLede(title, false) |
| 1344 | // Truncate lede if needed |
| 1345 | title, _ = parse.TruncToWord(title, 80) |
| 1346 | var s string |
| 1347 | if lang != "" && len(lang) == 2 { |
| 1348 | s = slug.MakeLang(title, lang) |
| 1349 | } else { |
| 1350 | s = slug.Make(title) |
| 1351 | } |
| 1352 | |
| 1353 | // Transliteration may cause the slug to expand past the limit, so truncate again |
| 1354 | s, _ = parse.TruncToWord(s, 80) |
| 1355 | return strings.TrimFunc(s, func(r rune) bool { |
| 1356 | // TruncToWord doesn't respect words in a slug, since spaces are replaced |
| 1357 | // with hyphens. So remove any trailing hyphens. |
| 1358 | return r == '-' |
| 1359 | }) |
| 1360 | } |
| 1361 | |
| 1362 | // isFontValid returns whether or not the submitted post's appearance is valid. |
| 1363 | func (p *SubmittedPost) isFontValid() bool { |
no test coverage detected