From 2091558c6126918cce6f3704c627f4b720df7530 Mon Sep 17 00:00:00 2001 From: sharathkannan <138484653+sharath-kannan@users.noreply.github.com> Date: Tue, 13 Aug 2024 21:38:28 +0530 Subject: [PATCH] Feat(MWPW:151162):nofollow a individual link. (#2692) * nofollow a link * added units for nofollow link feature * fixed liniting error --- libs/utils/utils.js | 4 ++++ test/utils/mocks/body.html | 2 ++ test/utils/utils.test.js | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/libs/utils/utils.js b/libs/utils/utils.js index b792862811..2970289cea 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -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 { diff --git a/test/utils/mocks/body.html b/test/utils/mocks/body.html index 38b0f5589a..6e636675b1 100644 --- a/test/utils/mocks/body.html +++ b/test/utils/mocks/body.html @@ -24,6 +24,8 @@
+ + diff --git a/test/utils/utils.test.js b/test/utils/utils.test.js index fbdfd5e184..d02c008716 100644 --- a/test/utils/utils.test.js +++ b/test/utils/utils.test.js @@ -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;