From 532653110c9e0400967c42352415be6dccb8e6a4 Mon Sep 17 00:00:00 2001
From: Julian Lam
.*/g, '');
+
+ // Strip html
+ title = utils.stripHTMLTags(title);
+
+ // Split sentences and use only first one
+ const sentences = title
+ .split(/(\.|\?|!)\s/)
+ .reduce((memo, cur, idx, sentences) => {
+ if (idx % 2) {
+ memo.push(`${sentences[idx - 1]}${cur}`);
+ } else if (idx === sentences.length - 1) {
+ memo.push(cur);
+ }
+
+ return memo;
+ }, []);
+
+ if (sentences.length > 1) {
+ title = sentences.shift();
+ }
+
+ // Truncate down if too long
+ if (title.length > meta.config.maximumTitleLength) {
+ title = `${title.slice(0, meta.config.maximumTitleLength - 3)}...`;
+ }
+
+ return title;
+};
+
Helpers.remoteAnchorToLocalProfile = async (content, isMarkdown = false) => {
let anchorRegex;
if (isMarkdown) {
diff --git a/src/activitypub/notes.js b/src/activitypub/notes.js
index 6ccb2ca209..ef4abe9add 100644
--- a/src/activitypub/notes.js
+++ b/src/activitypub/notes.js
@@ -165,11 +165,7 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
// mainPid ok to leave as-is
if (!title) {
- // Naive pre-processing prior to sbd tokenization
- let sbdInput = content || sourceContent;
- sbdInput = sbdInput.replace('
', '
\n'); - - const sentences = tokenizer.sentences(sbdInput, { sanitize: true, newline_boundaries: true }); + const sentences = tokenizer.sentences(content || sourceContent, { sanitize: true }); title = sentences.shift(); }