Skip to content

Commit

Permalink
Merge pull request #1334 from dpc-sdp/bugfix/internal-links
Browse files Browse the repository at this point in the history
fix: removes unwanted internal: from URLs
  • Loading branch information
dylankelly authored Sep 23, 2024
2 parents 4b28c33 + 2e23ba8 commit 0243bda
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 10 additions & 0 deletions packages/ripple-tide-api/src/utils/mapping-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ const field = {
url: '/landing-page-cc-2',
origin_url: '/landing-page-cc-2'
},
field_related_link: {
uri: 'internal:/contact-us',
title: 'Get in touch',
options: []
},
field_paragraph_location: {
langcode: null,
country_code: 'AU',
Expand Down Expand Up @@ -160,6 +165,11 @@ describe('ripple-tide-api/mapping utils', () => {
text: '',
url: '/landing-page-cc-2'
})

expect(getLinkFromField(field, 'field_related_link')).toEqual({
text: 'Get in touch',
url: '/contact-us'
})
})

it(`returns null on invalid api key`, () => {
Expand Down
10 changes: 7 additions & 3 deletions packages/ripple-tide-api/src/utils/mapping-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,14 @@ export const getLinkFromField = (
return null
}

return {
text: linkField.title || linkField.text || '',
url: linkField.url || linkField.origin_url || linkField.uri || ''
let text = linkField.title || linkField.text || ''
let url = linkField.url || linkField.origin_url || linkField.uri || ''

if (url.startsWith('internal:')) {
url = url.replace(/^internal:/, '')
}

return { text, url }
}

export const getAddress = (field: drupalField) => {
Expand Down

0 comments on commit 0243bda

Please sign in to comment.