TODO: fix duplicated code from postTitle. postTitle is a widely used func we don't have time to investigate right now.
(content, friendlyId string)
| 234 | // TODO: fix duplicated code from postTitle. postTitle is a widely used func we |
| 235 | // don't have time to investigate right now. |
| 236 | func friendlyPostTitle(content, friendlyId string) string { |
| 237 | const maxTitleLen = 80 |
| 238 | |
| 239 | content = stripHTMLWithoutEscaping(content) |
| 240 | |
| 241 | content = strings.TrimLeftFunc(stripmd.Strip(content), unicode.IsSpace) |
| 242 | eol := strings.IndexRune(content, '\n') |
| 243 | blankLine := strings.Index(content, "\n\n") |
| 244 | if blankLine != -1 && blankLine <= eol && blankLine <= assumedTitleLen { |
| 245 | return strings.TrimSpace(content[:blankLine]) |
| 246 | } else if eol == -1 && utf8.RuneCountInString(content) <= maxTitleLen { |
| 247 | return content |
| 248 | } |
| 249 | title, truncd := parse.TruncToWord(parse.PostLede(content, true), maxTitleLen) |
| 250 | if truncd { |
| 251 | title += "..." |
| 252 | } |
| 253 | return title |
| 254 | } |
| 255 | |
| 256 | // Strip HTML tags with bluemonday's StrictPolicy, then unescape the HTML |
| 257 | // entities added in by sanitizing the content. |
no test coverage detected