Skip to content

Commit 09f1126

Browse files
committed
Added in-reply-to support to comments API
ref https://linear.app/tryghost/issue/PLG-230 - adds `in_reply_to_id` to API output - adds `in_reply_to_snippet` to API output - dynamically generated from the HTML of the replied-to comment - excluded if the replied-to comment has been deleted or hidden - adds `commentSnippet` to `@tryghost/html-to-plaintext` - skips anchor tag URLs as they won't be useful for snippet purposes - skips blockquotes so the snippet is more likely to contain the unique content of the replied-to comment when it's quoting a previous comment - returns a single line (no newline chars) - allows setting `in_reply_to_id` when creating comments - id must reference a reply with the same parent - id must reference a published comment - adds email notification for the original reply author when their comment is replied to
1 parent fbcfa3f commit 09f1126

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

packages/html-to-plaintext/lib/html-to-plaintext.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const baseSettings = {
3535
let excerptConverter;
3636
let emailConverter;
3737
let commentConverter;
38+
let commentSnippetConverter;
3839

3940
const loadConverters = () => {
4041
if (excerptConverter && emailConverter) {
@@ -78,9 +79,18 @@ const loadConverters = () => {
7879
]
7980
});
8081

82+
const commentSnippetSettings = mergeSettings({
83+
preserveNewlines: false,
84+
ignoreHref: true,
85+
selectors: [
86+
{selector: 'blockquote', format: 'skip'}
87+
]
88+
});
89+
8190
excerptConverter = compile(excerptSettings);
8291
emailConverter = compile(emailSettings);
8392
commentConverter = compile(commentSettings);
93+
commentSnippetConverter = compile(commentSnippetSettings);
8494
};
8595

8696
module.exports.excerpt = (html) => {
@@ -100,3 +110,11 @@ module.exports.comment = (html) => {
100110

101111
return commentConverter(html);
102112
};
113+
114+
module.exports.commentSnippet = (html) => {
115+
loadConverters();
116+
117+
return commentSnippetConverter(html)
118+
.replace(/\n/g, ' ')
119+
.replace(/\s+/g, ' ');
120+
};

packages/html-to-plaintext/test/html-to-plaintext.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,28 @@ describe('Html to Plaintext', function () {
8787
assert.equal(excerpt, expected);
8888
});
8989
});
90+
91+
describe('commentSnippet converter', function () {
92+
function testConverter({input, expected}) {
93+
return () => {
94+
const output = htmlToPlaintext.commentSnippet(input);
95+
assert.equal(output, expected);
96+
};
97+
}
98+
99+
it('skips href urls', testConverter({
100+
input: '<a href="https://mysite.com">A snippet from a post template</a>',
101+
expected: 'A snippet from a post template'
102+
}));
103+
104+
it('skips blockquotes', testConverter({
105+
input: '<blockquote>Previous comment quote</blockquote><p>And the new comment text</p>',
106+
expected: 'And the new comment text'
107+
}));
108+
109+
it('returns a single line', testConverter({
110+
input: '<p>First paragraph.</p><p>Second paragraph.</p>',
111+
expected: 'First paragraph. Second paragraph.'
112+
}));
113+
});
90114
});

0 commit comments

Comments
 (0)