mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
12922 - Use absolute user URLs on production (#12968)
This commit is contained in:
@@ -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));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user