spaCy/website/src/components/embed.js
Ines Montani e597110d31
💫 Update website (#3285)
<!--- Provide a general summary of your changes in the title. -->

## Description

The new website is implemented using [Gatsby](https://www.gatsbyjs.org) with [Remark](https://github.com/remarkjs/remark) and [MDX](https://mdxjs.com/). This allows authoring content in **straightforward Markdown** without the usual limitations. Standard elements can be overwritten with powerful [React](http://reactjs.org/) components and wherever Markdown syntax isn't enough, JSX components can be used. Hopefully, this update will also make it much easier to contribute to the docs. Once this PR is merged, I'll implement auto-deployment via [Netlify](https://netlify.com) on a specific branch (to avoid building the website on every PR). There's a bunch of other cool stuff that the new setup will allow us to do – including writing front-end tests, service workers, offline support, implementing a search and so on.

This PR also includes various new docs pages and content.
Resolves #3270. Resolves #3222. Resolves #2947. Resolves #2837.


### Types of change
enhancement

## Checklist
<!--- Before you submit the PR, go over this checklist and make sure you can
tick off all the boxes. [] -> [x] -->
- [x] I have submitted the spaCy Contributor Agreement.
- [x] I ran the tests, and all new and existing tests passed.
- [x] My changes don't require a change to the documentation, or if they do, I've added all required information.
2019-02-17 19:31:19 +01:00

121 lines
3.4 KiB
JavaScript

import React, { Fragment } from 'react'
import PropTypes from 'prop-types'
import classNames from 'classnames'
import Link from './link'
import { InlineCode } from './code'
import { markdownToReact } from './util'
import classes from '../styles/embed.module.sass'
const YouTube = ({ id, ratio }) => {
const embedClassNames = classNames(classes.root, classes.responsive, {
[classes.ratio16x9]: ratio === '16x9',
[classes.ratio4x3]: ratio === '4x3',
})
const url = `https://www.youtube.com/embed/${id}`
return (
<figure className={embedClassNames}>
<iframe
className={classes.iframe}
title={id}
src={url}
frameBorder={0}
height={500}
allowFullScreen
/>
</figure>
)
}
YouTube.defaultProps = {
ratio: '16x9',
}
YouTube.propTypes = {
id: PropTypes.string.isRequired,
ratio: PropTypes.oneOf(['16x9', '4x3']),
}
const SoundCloud = ({ id, color, title }) => {
const url = `https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/${id}&color=%23${color}&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true`
return (
<figure className={classes.root}>
<iframe
title={title}
width="100%"
height={166}
scrolling="no"
frameborder="no"
allow="autoplay"
src={url}
/>
</figure>
)
}
SoundCloud.defaultProps = {
color: '09a3d5',
}
SoundCloud.propTypes = {
id: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
color: PropTypes.string,
}
function formatHTML(html) {
const encoded = encodeURIComponent(html)
return `<html><head><meta charset="UTF-8"></head><body>${encoded}</body></html>`
}
const Iframe = ({ title, src, html, width, height }) => {
const source = html ? `data:text/html,${formatHTML(html)}` : src
return (
<iframe
className={classes.standalone}
title={title}
src={source}
width={width}
height={height}
allowFullScreen
frameBorder="0"
/>
)
}
Iframe.defaultProps = {
width: 800,
height: 300,
}
Iframe.propTypes = {
title: PropTypes.string.isRequired,
src: PropTypes.string,
html: PropTypes.string,
width: PropTypes.number,
height: PropTypes.number,
}
const Image = ({ src, alt, title, ...props }) => {
// This is only needed for image types that are NOT handled by
// gatsby-remark-images, i.e. mostly SVGs. The plugin adds formatting
// and support for captions, so this normalises that behaviour.
const linkClassNames = classNames('gatsby-resp-image-link', classes.imageLink)
const markdownComponents = { code: InlineCode, p: Fragment, a: Link }
return (
<figure className="gatsby-resp-image-figure">
<Link className={linkClassNames} href={src} hidden forceExternal>
<img className={classes.image} src={src} alt={alt} width={650} height="auto" />
</Link>
{title && (
<figcaption className="gatsby-resp-image-figcaption">
{markdownToReact(title, markdownComponents)}
</figcaption>
)}
</figure>
)
}
export { YouTube, SoundCloud, Iframe, Image }