-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(SoundCloud): Add support for SoundCloud songs & playlists (#9)
* Add soundcloud embeds * Update docs with soundcloud embed * Add line-break to Twitter docs * Revert docs line-break in Twitter docs * PR suggestion: Use implicit function returns * PR suggestions: Remove encoding of iframe soundcloud url and update embed defaults * PR suggestions: Update docs to reflect Soundcloud iframe src url changes * PR Suggestions: Remove trailing slash in soundcloud URL before params * Update soundcloud embed tests to explicitly show http soundcloud urls are valid * PR Suggestions: Update code style of Soundcloud html and url generation to 1-line template literal * Add Soundcloud transformer to transform list * Cleanup README * Don't allow autoplay
- Loading branch information
1 parent
373c71b
commit 9843fcf
Showing
4 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import cases from 'jest-in-case'; | ||
|
||
import { getHTML, shouldTransform } from '../soundcloud'; | ||
|
||
cases( | ||
'url validation', | ||
({ url, valid }) => { | ||
expect(shouldTransform(url)).toBe(valid); | ||
}, | ||
{ | ||
'non-soundcloud url': { | ||
url: 'https://not-a-soundcloud-url.com', | ||
valid: false, | ||
}, | ||
'url with soundcloud track id': { | ||
url: 'https://api.soundcloud.com/tracks/151129490', | ||
valid: false, | ||
}, | ||
'url with soundcloud playlist id': { | ||
url: 'https://api.soundcloud.com/playlists/703823211', | ||
valid: false, | ||
}, | ||
'url with widget soundcloud subdomain': { | ||
url: | ||
'https://w.soundcloud.com/player?url=https://soundcloud.com/clemenswenners/africa', | ||
valid: false, | ||
}, | ||
'valid soundcloud url with https protocol': { | ||
url: 'https://soundcloud.com/clemenswenners/africa', | ||
valid: true, | ||
}, | ||
'valid soundcloud url with http protocol': { | ||
url: 'http://soundcloud.com/clemenswenners/africa', | ||
valid: true, | ||
}, | ||
} | ||
); | ||
|
||
test('Gets the correct Soundcloud iframe', async () => { | ||
const html = await getHTML('https://soundcloud.com/clemenswenners/africa'); | ||
|
||
expect(html).toMatchInlineSnapshot( | ||
`"<iframe width=\\"100%\\" height=\\"300\\" scrolling=\\"no\\" frameborder=\\"no\\" src=https://w.soundcloud.com/player?url=https://soundcloud.com/clemenswenners/africa&color=ff5500&auto_play=false&hide_related=true&show_comments=true&show_user=true&show_reposts=false&show_teaser=false&visual=true></iframe>"` | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { URL } from 'url'; | ||
|
||
export const shouldTransform = string => | ||
new URL(string).host === 'soundcloud.com'; | ||
|
||
const getSoundcloudIFrameSrc = string => | ||
`https://w.soundcloud.com/player?url=${string}&color=ff5500&auto_play=false&hide_related=true&show_comments=true&show_user=true&show_reposts=false&show_teaser=false&visual=true`; | ||
|
||
export const getHTML = string => { | ||
const iframeUrl = getSoundcloudIFrameSrc(string); | ||
|
||
return `<iframe width="100%" height="300" scrolling="no" frameborder="no" src=${iframeUrl}></iframe>`; | ||
}; |