Skip to content

Commit

Permalink
feat: open bio links in new tab, add nofollow and ugc
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Nov 3, 2024
1 parent 3fcd7d4 commit 6d2d220
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion js/src/forum/components/UserBio.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ export default class UserBio extends Component {
if (bioHtml) {
subContent = m.trust(bioHtml);
} else if (user.bio()) {
subContent = m.trust('<p>' + $('<div/>').text(user.bio()).html().replace(/\n/g, '<br>').autoLink({ rel: 'nofollow ugc' }) + '</p>');
subContent = m.trust(
'<p>' + $('<div/>').text(user.bio()).html().replace(/\n/g, '<br>').autoLink({ rel: 'nofollow ugc', target: '_blank' }) + '</p>'
);
} else if (editable) {
subContent = <p className="UserBio-placeholder">{this.bioPlaceholder}</p>;
}
Expand Down
12 changes: 12 additions & 0 deletions src/Formatter/UserBioFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ protected function getConfigurator()
(new \Flarum\BBCode\Configure())($configurator);
}

// Add target="_blank" and rel="noopener ugc" to all URL tags on the UserBioFormatter
$dom = $configurator->tags['URL']->template->asDOM();

foreach ($dom->getElementsByTagName('a') as $a) {
$a->setAttribute('target', '_blank');

$rel = $a->getAttribute('rel');
$a->setAttribute('rel', "$rel noopener ugc");
}

$dom->saveChanges();

return $configurator;
}

Expand Down

0 comments on commit 6d2d220

Please sign in to comment.