12922 - Use absolute user URLs on production (#12968)

This commit is contained in:
Bart Enkelaar
2021-04-29 22:23:42 +02:00
committed by GitHub
parent 591c9bc98c
commit 920a093b0e
2 changed files with 49 additions and 28 deletions

View File

@@ -144,6 +144,11 @@ function findTextBlocks (text) {
return new TextBlocks(blocks);
}
function determineBaseUrl () {
// eslint-disable-next-line no-process-env
return process.env.NODE_ENV === 'production' ? 'https://habitica.com' : '';
}
/**
* Replaces `@user` mentions by `[@user](/profile/{user-id})` markup to inject
* a link towards the user's profile page.
@@ -164,10 +169,11 @@ export default async function highlightMentions (text) {
.select(['auth.local.username', '_id', 'preferences.pushNotifications', 'pushDevices', 'party', 'guilds'])
.lean()
.exec();
const baseUrl = determineBaseUrl();
members.forEach(member => {
const { username } = member.auth.local;
const regex = new RegExp(`@${username}(?![\\-\\w])`, 'g');
const replacement = `[@${username}](/profile/${member._id})`;
const replacement = `[@${username}](${baseUrl}/profile/${member._id})`;
textBlocks.transformValidBlocks(blockText => blockText.replace(regex, replacement));
});