PreviewObject returns an activitystreams.Object that can be used as an Article's `preview` property.
(app *App, art *activitystreams.Object)
| 1304 | |
| 1305 | // PreviewObject returns an activitystreams.Object that can be used as an Article's `preview` property. |
| 1306 | func (p *PublicPost) PreviewObject(app *App, art *activitystreams.Object) *activitystreams.Object { |
| 1307 | o := activitystreams.NewNoteObject() |
| 1308 | o.To = nil |
| 1309 | o.ID = art.ID |
| 1310 | o.URL = art.URL |
| 1311 | o.Published = art.Published |
| 1312 | o.Updated = art.Updated |
| 1313 | o.Tag = art.Tag |
| 1314 | o.Attachment = art.Attachment |
| 1315 | |
| 1316 | baseURL := p.Collection.CanonicalURL() |
| 1317 | // Try to truncate at user-defined excerpt, if exists |
| 1318 | exc := strings.Index(p.Content, shortCodeMore) |
| 1319 | if exc == -1 { |
| 1320 | // No excerpt; fall back to truncating at first paragraph |
| 1321 | exc = strings.Index(p.Content, "\n\n") |
| 1322 | } |
| 1323 | if exc > -1 { |
| 1324 | p.HTMLExcerpt = template.HTML(applyMarkdown([]byte(p.Content[:exc]+" [...]"), baseURL, app.cfg)) |
| 1325 | } else { |
| 1326 | p.HTMLExcerpt = p.HTMLContent |
| 1327 | } |
| 1328 | o.Content = strings.TrimRight(string(p.Excerpt()), "\n") |
| 1329 | return o |
| 1330 | } |
| 1331 | |
| 1332 | // TODO: merge this into getSlugFromPost or phase it out |
| 1333 | func getSlug(title, lang string) string { |
no test coverage detected