<commit_before>import React from "react"
import upperCase from "voca/upper_case"
// import trimRight from "voca/trim_right"


// const truncateUrl = (url, maxLength) => {
//   if (url.length >= maxLength) {
//     url = trimRight(url, '/')
//     const regex = /(http:\/\/|https:\/\/)?([-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6})\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/ig
//     const urlParts = regex.exec(url)
//     if (urlParts) {
//       const afterSlash = urlParts[3].split('/')
//       url = `${urlParts[2]}/.../${afterSlash[afterSlash.length - 1]}`
//     }
//   }
//   return url.replace(/https?:\/\//, "")
// }

const getHostName = url =>
  upperCase(url.replace(/https?:\/\//, "").replace(/\/.*/g, ""))

export const Source = ({source: {url, title, site_name}}) => (
  <a href={url} target="_BLANK" className="fact-source">
    <span className="site-name">
      { upperCase(site_name) || getHostName(url) }
    </span>
    <span className="article-title">{title}</span>
  </a>
)
<commit_msg>[#4] - Embed video sources<commit_after>import React from "react"
import ReactPlayer from "react-player"
import upperCase from "voca/upper_case"
import lowerCase from "voca/lower_case"

// const truncateUrl = (url, maxLength) => {
//   if (url.length >= maxLength) {
//     url = trimRight(url, '/')
//     const regex = /(http:\/\/|https:\/\/)?([-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6})\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/ig
//     const urlParts = regex.exec(url)
//     if (urlParts) {
//       const afterSlash = urlParts[3].split('/')
//       url = `${urlParts[2]}/.../${afterSlash[afterSlash.length - 1]}`
//     }
//   }
//   return url.replace(/https?:\/\//, "")
// }

const supportedPlayers = ['youtube', 'dailymotion', 'twitch', 'soundcloud', 'streamable', 'vidme', 'vimeo', 'wistia']

const getHostName = url =>
  upperCase(url.replace(/https?:\/\//, "").replace(/\/.*/g, ""))

const isPlayer = site_name => supportedPlayers.includes(lowerCase(site_name))

export const Source = ({ source: { url, title, site_name } }) => {
  if (isPlayer(site_name)) {
    return <ReactPlayer width='100%' url={url} config={{
      youtube: { preload: false },
      facebook: { preload: false },
      dailymotion: { preload: false },
      soundcloud: { preload: false }
    }} />
  } else {
    return <a href={url} target="_BLANK" className="fact-source">
      <span className="site-name">
        {upperCase(site_name) || getHostName(url)}
      </span>
      <span className="article-title">{title}</span>
    </a>
  }
}

{'fraction_non_alphanumeric': 0.24354390147000396, 'fraction_numerical': 0.011918951132300357, 'mean_word_length': 2.9529042386185242, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3726432', 'n_tokens_mistral': 939, 'n_tokens_neox': 927, 'n_words': 164}