media.js 967 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. const Youtube = props => {
  2. const { link, rest } = props
  3. const src = link.match(/\?v=(.*)/)[1]
  4. return (
  5. <iframe
  6. width='285'
  7. height='160'
  8. src={`https://www.youtube.com/embed/${src}`}
  9. frameBorder='0'
  10. allow='accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture'
  11. allowFullScreen
  12. {...rest}
  13. />
  14. )
  15. }
  16. const Spotify = props => {
  17. const { link, rest } = props
  18. const src = link.match(/track\/(.*)/)[1]
  19. return (
  20. <iframe
  21. src={`https://open.spotify.com/embed/track/${src}`}
  22. width='300'
  23. height='80'
  24. frameBorder='0'
  25. allowtransparency='true'
  26. allow='encrypted-media'
  27. {...rest}
  28. />
  29. )
  30. }
  31. const Media = props => {
  32. if (props.link.includes('youtube.com')) {
  33. return <Youtube {...props} />
  34. } else if (props.link.includes('spotify.com')) {
  35. return <Spotify {...props} />
  36. } else {
  37. return <p>Link not recognized.</p>
  38. }
  39. }
  40. export default Media