diff options
author | FChannel <> | 2022-06-12 23:04:13 -0700 |
---|---|---|
committer | FChannel <> | 2022-06-19 12:53:29 -0700 |
commit | cc3e8e57154409469267b0526807a907d5166147 (patch) | |
tree | 59acbf28290c8658a538f8843a1d0d9e1a598baf /post/util.go | |
parent | 0418dab57f9cf19540234d157a512e30a70a7152 (diff) |
admin page layout/css - truncate long new line posts
Diffstat (limited to 'post/util.go')
-rw-r--r-- | post/util.go | 21 |
1 files changed, 20 insertions, 1 deletions
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("<a href=\"%s\">(view full post...)</a>", 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) |