mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-03 19:11:22 +01:00
feat: support the magic break string '[...]' in content, such that if found, outbound federation will use all content up to (and including) that string in its summary
This commit is contained in:
@@ -755,30 +755,36 @@ Mocks.notes.public = async (post) => {
|
|||||||
// attachment,
|
// attachment,
|
||||||
// };
|
// };
|
||||||
|
|
||||||
const sentences = tokenizer.sentences(post.content, { newline_boundaries: true });
|
const breakString = '[...]';
|
||||||
// Append sentences to summary until it contains just under 500 characters of content
|
if (post.content.includes(breakString)) {
|
||||||
const limit = 500;
|
const index = post.content.indexOf(breakString);
|
||||||
let remaining = limit;
|
summary = post.content.slice(0, index + breakString.length);
|
||||||
let finished = false;
|
} else {
|
||||||
summary = sentences.reduce((memo, sentence) => {
|
const sentences = tokenizer.sentences(post.content, { newline_boundaries: true });
|
||||||
if (finished) {
|
// Append sentences to summary until it contains just under 500 characters of content
|
||||||
|
const limit = 500;
|
||||||
|
let remaining = limit;
|
||||||
|
let finished = false;
|
||||||
|
summary = sentences.reduce((memo, sentence) => {
|
||||||
|
if (finished) {
|
||||||
|
return memo;
|
||||||
|
}
|
||||||
|
|
||||||
|
const clean = sanitize(sentence, {
|
||||||
|
allowedTags: [],
|
||||||
|
allowedAttributes: {},
|
||||||
|
});
|
||||||
|
remaining = remaining - clean.length;
|
||||||
|
if (remaining > 0) {
|
||||||
|
memo += ` ${sentence}`;
|
||||||
|
} else { // There was more but summary generation is complete
|
||||||
|
finished = true;
|
||||||
|
memo += ' [...]';
|
||||||
|
}
|
||||||
|
|
||||||
return memo;
|
return memo;
|
||||||
}
|
}, '');
|
||||||
|
}
|
||||||
const clean = sanitize(sentence, {
|
|
||||||
allowedTags: [],
|
|
||||||
allowedAttributes: {},
|
|
||||||
});
|
|
||||||
remaining = remaining - clean.length;
|
|
||||||
if (remaining > 0) {
|
|
||||||
memo += ` ${sentence}`;
|
|
||||||
} else { // There was more but summary generation is complete
|
|
||||||
finished = true;
|
|
||||||
memo += ' [...]';
|
|
||||||
}
|
|
||||||
|
|
||||||
return memo;
|
|
||||||
}, '');
|
|
||||||
|
|
||||||
// Final sanitization to clean up tags
|
// Final sanitization to clean up tags
|
||||||
summary = posts.sanitize(summary);
|
summary = posts.sanitize(summary);
|
||||||
|
|||||||
Reference in New Issue
Block a user