MCPcopy
hub / github.com/writefreely/writefreely / PreviewObject

Method PreviewObject

posts.go:1306–1330  ·  view source on GitHub ↗

PreviewObject returns an activitystreams.Object that can be used as an Article's `preview` property.

(app *App, art *activitystreams.Object)

Source from the content-addressed store, hash-verified

1304
1305// PreviewObject returns an activitystreams.Object that can be used as an Article's `preview` property.
1306func (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
1333func getSlug(title, lang string) string {

Callers 1

ActivityObjectMethod · 0.95

Calls 3

applyMarkdownFunction · 0.85
ExcerptMethod · 0.80
CanonicalURLMethod · 0.45

Tested by

no test coverage detected