Skip to content

Commit

Permalink
Feat(MWPW:151162):nofollow a individual link. (#2692)
Browse files Browse the repository at this point in the history
* nofollow a link

* added units for nofollow link feature

* fixed liniting error
  • Loading branch information
sharath-kannan committed Aug 13, 2024
1 parent 59a1b33 commit 2091558
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libs/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,10 @@ export function decorateLinks(el) {
a.setAttribute('target', '_blank');
a.href = a.href.replace('#_blank', '');
}
if (a.href.includes('#_nofollow')) {
a.setAttribute('rel', 'nofollow');
a.href = a.href.replace('#_nofollow', '');
}
if (a.href.includes('#_dnb')) {
a.href = a.href.replace('#_dnb', '');
} else {
Expand Down
2 changes: 2 additions & 0 deletions test/utils/mocks/body.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
<p><a href="http://localhost:2000">http://localhost:2000/img/favicon.svg</a></p>
<!-- #_blank -->
<p><a class="new-tab" href="https://www.adobe.com/test#_blank">New Tab</a></p>
<!-- Nofollow individual link-->
<p><a class="no-follow" href="https://www.adobe.com/test#_nofollow">No Follow</a></p>
<!-- Nofollow -->
<p><a href="https://analytics.google.com">Google analytics</a></p>
<!-- Disable Auto Block-->
Expand Down
8 changes: 8 additions & 0 deletions test/utils/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ describe('Utils', () => {
expect(newTabLink.href).to.equal('https://www.adobe.com/test');
});

it('Add rel=nofollow to a link', () => {
const noFollowContainer = document.querySelector('main div');
utils.decorateLinks(noFollowContainer);
const noFollowLink = noFollowContainer.querySelector('.no-follow');
expect(noFollowLink.rel).to.contain('nofollow');
expect(noFollowLink.href).to.equal('https://www.adobe.com/test');
});

it('Sets up milo.deferredPromise', async () => {
const { resolveDeferred } = utils.getConfig();
expect(window.milo.deferredPromise).to.exist;
Expand Down

0 comments on commit 2091558

Please sign in to comment.