Summary gives a shortened summary of the post based on the post's title, especially for display in a longer list of posts. It extracts a summary for posts in the Title\n\nBody format, returning nothing if the entire was short enough that the extracted title == extracted summary.
()
| 242 | // posts in the Title\n\nBody format, returning nothing if the entire was short |
| 243 | // enough that the extracted title == extracted summary. |
| 244 | func (p Post) Summary() string { |
| 245 | if p.Content == "" { |
| 246 | return "" |
| 247 | } |
| 248 | p.Content = stripHTMLWithoutEscaping(p.Content) |
| 249 | // and Markdown |
| 250 | p.Content = stripmd.StripOptions(p.Content, stripmd.Options{SkipImages: true}) |
| 251 | |
| 252 | title := p.Title.String |
| 253 | var desc string |
| 254 | if title == "" { |
| 255 | // No title, so generate one |
| 256 | title = friendlyPostTitle(p.Content, p.ID) |
| 257 | desc = postDescription(p.Content, title, p.ID) |
| 258 | if desc == title { |
| 259 | return "" |
| 260 | } |
| 261 | return desc |
| 262 | } |
| 263 | |
| 264 | return shortPostDescription(p.Content) |
| 265 | } |
| 266 | |
| 267 | func (p Post) SummaryHTML() template.HTML { |
| 268 | return template.HTML(p.Summary()) |