From cc3e8e57154409469267b0526807a907d5166147 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Sun, 12 Jun 2022 23:04:13 -0700 Subject: admin page layout/css - truncate long new line posts --- post/util.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'post') diff --git a/post/util.go b/post/util.go index 8db2d02..bc2580b 100644 --- a/post/util.go +++ b/post/util.go @@ -469,7 +469,7 @@ func ParseAttachment(obj activitypub.ObjectBase, catalog bool) template.HTML { return template.HTML(media) } -func ParseContent(board activitypub.Actor, op string, content string, thread activitypub.ObjectBase) (template.HTML, error) { +func ParseContent(board activitypub.Actor, op string, content string, thread activitypub.ObjectBase, id string, _type string) (template.HTML, error) { // TODO: should escape more than just < and >, should also escape &, ", and ' nContent := strings.ReplaceAll(content, `<`, "<") nContent, err := ParseLinkComments(board, op, nContent, thread) @@ -478,12 +478,31 @@ func ParseContent(board activitypub.Actor, op string, content string, thread act return "", util.MakeError(err, "ParseContent") } + if _type == "new" { + nContent = ParseTruncate(nContent, board, op, id) + } nContent = ParseCommentQuotes(nContent) nContent = strings.ReplaceAll(nContent, `/\<`, ">") return template.HTML(nContent), nil } +func ParseTruncate(content string, board activitypub.Actor, op string, id string) string { + if strings.Count(content, "\r") > 30 { + content = strings.ReplaceAll(content, "\r\n", "\r") + lines := strings.SplitAfter(content, "\r") + content = "" + + for i := 0; i < 30; i++ { + content += lines[i] + } + + content += fmt.Sprintf("(view full post...)", board.Id+"/"+util.ShortURL(board.Outbox, op)+"#"+util.ShortURL(board.Outbox+"/outbox", id)) + } + + return content +} + func ParseLinkComments(board activitypub.Actor, op string, content string, thread activitypub.ObjectBase) (string, error) { re := regexp.MustCompile(`(>>(https?://[A-Za-z0-9_.:\-~]+\/[A-Za-z0-9_.\-~]+\/)(f[A-Za-z0-9_.\-~]+-)?([A-Za-z0-9_.\-~]+)?#?([A-Za-z0-9_.\-~]+)?)`) match := re.FindAllStringSubmatch(content, -1) -- cgit v1.2.3