Skip to content

Commit

Permalink
Merge pull request #161 from jeffsikes/issue-hashtag-spacing
Browse files Browse the repository at this point in the history
Hashtag Spacing and Empty Tag Handling
  • Loading branch information
ckolderup committed Nov 1, 2023
2 parents 2ced5fe + bf5713a commit 55c9665
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/activitypub.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,41 @@ export function createNoteObject(bookmark, account, domain) {
updatedBookmark.title = escapeHTML(bookmark.title);
updatedBookmark.description = escapeHTML(bookmark.description);

const linkedTags = bookmark.tags
?.split(' ')
.map((tag) => {
const tagName = tag.slice(1);
return `<a href="https://${domain}/tagged/${tagName}" class="mention hashtag" rel="tag nofollow noopener noreferrer">${tag}</a>`;
})
.join(' ');
let linkedTags = '';

if (bookmark.tags && bookmark.tags.length > 0) {
linkedTags = bookmark.tags
?.split(' ')
.map((tag) => {
const tagName = tag.slice(1);
return `<a href="https://${domain}/tagged/${tagName}" class="mention hashtag" rel="tag nofollow noopener noreferrer">${tag}</a>`;
})
.join(' ');
}

if (updatedBookmark.description?.trim().length > 0) {
updatedBookmark.description = `<br/>${updatedBookmark.description?.trim().replace('\n', '<br/>') || ''}`;
}

if (linkedTags.trim().length > 0) {
linkedTags = `<p>${linkedTags}</p>`;
}

const noteMessage = {
'@context': 'https://www.w3.org/ns/activitystreams',
id: `https://${domain}/m/${guidNote}`,
type: 'Note',
published: d.toISOString(),
attributedTo: `https://${domain}/u/${account}`,
content: `<strong><a href="${updatedBookmark.url}" rel="nofollow noopener noreferrer" target="_blank">${replaceEmptyText(
content: `<p><strong><a href="${updatedBookmark.url}" rel="nofollow noopener noreferrer">${replaceEmptyText(
updatedBookmark.title,
updatedBookmark.url,
)}</a></strong><br/>${updatedBookmark.description?.trim().replace('\n', '<br/>') || ''}<p>${linkedTags}</p>`,
)}</a></strong>${updatedBookmark.description}</p>${linkedTags}`,
to: [`https://${domain}/u/${account}/followers/`, 'https://www.w3.org/ns/activitystreams#Public'],
tag: [],
};

updatedBookmark.tags?.split(' ').forEach((tag) => {
bookmark.tags?.split(' ').forEach((tag) => {
const tagName = tag.slice(1);
noteMessage.tag.push({
type: 'Hashtag',
Expand Down

0 comments on commit 55c9665

Please sign in to comment.