Skip to content

Commit

Permalink
fix: test poster is not prefixed before prefixing
Browse files Browse the repository at this point in the history
  • Loading branch information
vpicone committed Jul 22, 2020
1 parent 7994b85 commit 3a7d08e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/gatsby-theme-carbon/src/components/Video/Video.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,25 @@ import usePathPrefix from '../../util/hooks/usePathprefix';

const Video = ({ autoPlay, vimeoId, title, src, poster, ...props }) => {
const [isPlaying, setIsPlaying] = useState(autoPlay);
const pathPrefix = usePathPrefix();
const videoRef = useRef(null);
const iframeRef = useRef(null);
const buttonClassName = cx(videoButton, {
[videoIsPlaying]: isPlaying,
});
const pathPrefix = usePathPrefix();

// If a video/poster is imported into an MDX file and provided through
// a js variable, it will already have the path-prefix.
//
// If the src/poster is just a reference to a file in the static directory,
// then we need to prefix for them.
const srcContainsPrefix = pathPrefix && src && src.includes(pathPrefix);
const fixedSrc = srcContainsPrefix ? src : withPrefix(src);

const posterContainsPrefix =
pathPrefix && poster && poster.includes(pathPrefix);
const fixedPoster = posterContainsPrefix ? poster : withPrefix(poster);

if (vimeoId) {
return (
<div className={videoContainer}>
Expand Down Expand Up @@ -108,7 +118,7 @@ const Video = ({ autoPlay, vimeoId, title, src, poster, ...props }) => {
ref={videoRef}
onEnded={onEnded}
src={fixedSrc}
poster={withPrefix(poster)}
poster={fixedPoster}
{...props}
/>
</div>
Expand Down

0 comments on commit 3a7d08e

Please sign in to comment.