Skip to content

Commit 55c9665

Browse files
authored
Merge pull request ckolderup#161 from jeffsikes/issue-hashtag-spacing
Hashtag Spacing and Empty Tag Handling
2 parents 2ced5fe + bf5713a commit 55c9665

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/activitypub.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,41 @@ export function createNoteObject(bookmark, account, domain) {
3434
updatedBookmark.title = escapeHTML(bookmark.title);
3535
updatedBookmark.description = escapeHTML(bookmark.description);
3636

37-
const linkedTags = bookmark.tags
38-
?.split(' ')
39-
.map((tag) => {
40-
const tagName = tag.slice(1);
41-
return `<a href="https://${domain}/tagged/${tagName}" class="mention hashtag" rel="tag nofollow noopener noreferrer">${tag}</a>`;
42-
})
43-
.join(' ');
37+
let linkedTags = '';
38+
39+
if (bookmark.tags && bookmark.tags.length > 0) {
40+
linkedTags = bookmark.tags
41+
?.split(' ')
42+
.map((tag) => {
43+
const tagName = tag.slice(1);
44+
return `<a href="https://${domain}/tagged/${tagName}" class="mention hashtag" rel="tag nofollow noopener noreferrer">${tag}</a>`;
45+
})
46+
.join(' ');
47+
}
48+
49+
if (updatedBookmark.description?.trim().length > 0) {
50+
updatedBookmark.description = `<br/>${updatedBookmark.description?.trim().replace('\n', '<br/>') || ''}`;
51+
}
52+
53+
if (linkedTags.trim().length > 0) {
54+
linkedTags = `<p>${linkedTags}</p>`;
55+
}
4456

4557
const noteMessage = {
4658
'@context': 'https://www.w3.org/ns/activitystreams',
4759
id: `https://${domain}/m/${guidNote}`,
4860
type: 'Note',
4961
published: d.toISOString(),
5062
attributedTo: `https://${domain}/u/${account}`,
51-
content: `<strong><a href="${updatedBookmark.url}" rel="nofollow noopener noreferrer" target="_blank">${replaceEmptyText(
63+
content: `<p><strong><a href="${updatedBookmark.url}" rel="nofollow noopener noreferrer">${replaceEmptyText(
5264
updatedBookmark.title,
5365
updatedBookmark.url,
54-
)}</a></strong><br/>${updatedBookmark.description?.trim().replace('\n', '<br/>') || ''}<p>${linkedTags}</p>`,
66+
)}</a></strong>${updatedBookmark.description}</p>${linkedTags}`,
5567
to: [`https://${domain}/u/${account}/followers/`, 'https://www.w3.org/ns/activitystreams#Public'],
5668
tag: [],
5769
};
5870

59-
updatedBookmark.tags?.split(' ').forEach((tag) => {
71+
bookmark.tags?.split(' ').forEach((tag) => {
6072
const tagName = tag.slice(1);
6173
noteMessage.tag.push({
6274
type: 'Hashtag',

0 commit comments

Comments
 (0)