Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions lib/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ import {
import {
getActivity,
createActivity,
deleteActivity
deleteActivity,
getHashtagsFromNote
} from './notes.js';

import debug from 'debug';
Expand Down Expand Up @@ -484,8 +485,24 @@ export const createNote = async (body, cw, inReplyTo, toUser, editOf) => {
}
}

// if it contains hashtags, add them
let hashtags = body.match(/#[a-z]+/gi)
if (hashtags) {
hashtags.forEach((tag) => {
tags.push({
"type": "Hashtag",
"href": `https://${ DOMAIN }/tags/${tag}`,
"name": tag
});
});
}

const mdContent = md.render(processedContent);

// rewrite links to tags in content
let content = mdContent.replace(/#([a-z]+)/gi, '<a href="https://' + DOMAIN + '/tags/$1" class="mention hashtag" rel="tag">#<span>$1</span></a>');

const content = md.render(processedContent);
content = '<span class="h-card">' + content + '</span>';

const activityId = `https://${ DOMAIN }/m/${guid}`;
const url = `https://${ DOMAIN }/notes/${guid}`;
Expand Down Expand Up @@ -538,6 +555,7 @@ export const createNote = async (body, cw, inReplyTo, toUser, editOf) => {
actor: object.attributedTo,
published: new Date(object.published).getTime(),
inReplyTo: object.inReplyTo,
hashtags: getHashtagsFromNote(object),
});
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,7 @@ export const getActivitySince = async (since, excludeSelf = false) => {
activitystream: res,
}
}

export const getHashtagsFromNote = (note) => {
return (note.tag && note.tag.length > 0) ? note.tag.filter((t) => t.type === 'Hashtag').map((t) => t.name) : [];
}
2 changes: 2 additions & 0 deletions lib/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import debug from 'debug';
const logger = debug('ono:storage');
import md5 from 'md5';
import dotenv from 'dotenv';
import { getHashtagsFromNote } from './notes.js';
dotenv.config();

export const dataDir = path.resolve('./', '.data/');
Expand Down Expand Up @@ -64,6 +65,7 @@ export const addActivityToIndex = (note, type = 'activity') => {
actor: note.attributedTo || note.actor,
published: new Date(note.published).getTime(),
inReplyTo: note.inReplyTo,
hashtags: getHashtagsFromNote(note)
});
}
export const deleteActivityFromIndex = (id) => {
Expand Down
21 changes: 20 additions & 1 deletion routes/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,23 @@ router.get('/notes/:guid', async (req, res) => {
});
}
}
});
});

router.get('/tags/:tag', async (req, res) => {
// all posts referencing tag by the owner user
const noteIds = INDEX.filter((i) => (i.actor === ActivityPub.actor.id) && i.hashtags.includes('#' + req.params.tag));
// get full posts
const posts = await Promise.all(noteIds.map(async (p) => {
return await getNote(p.id);
}));

res.render('public/tag', {
tag: req.params.tag,
layout: 'public',
me: ActivityPub.actor,
actor: ActivityPub.actor,
domain: DOMAIN,
user: USERNAME,
notes: posts
});
});