MCPcopy Index your code
hub / github.com/writefreely/writefreely / friendlyPostTitle

Function friendlyPostTitle

postrender.go:236–254  ·  view source on GitHub ↗

TODO: fix duplicated code from postTitle. postTitle is a widely used func we don't have time to investigate right now.

(content, friendlyId string)

Source from the content-addressed store, hash-verified

234// TODO: fix duplicated code from postTitle. postTitle is a widely used func we
235// don't have time to investigate right now.
236func 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.

Callers 3

DisplayTitleMethod · 0.85
SummaryMethod · 0.85
handleViewPostFunction · 0.85

Calls 3

TruncToWordFunction · 0.92
PostLedeFunction · 0.92
stripHTMLWithoutEscapingFunction · 0.85

Tested by

no test coverage detected