Skip to content
This repository has been archived by the owner on Feb 5, 2022. It is now read-only.

Commit

Permalink
Step 3: adding the post video to the page
Browse files Browse the repository at this point in the history
  • Loading branch information
colbyfayock committed Jun 7, 2021
1 parent 737e40b commit 37bd168
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/pages/posts/[postSlug].js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getApolloClient } from 'lib/apollo-client';

import styles from '../../styles/Home.module.css'

export default function Post({ post, site }) {
export default function Post({ post, site, video }) {
return (
<div className={styles.container}>
<Head>
Expand All @@ -20,6 +20,15 @@ export default function Post({ post, site }) {
{ post.title }
</h1>

{video && (
<figure>
<div dangerouslySetInnerHTML={{
__html: video.oEmbed.html
}} />
<figcaption>From { video.videoSource }</figcaption>
</figure>
)}

<div className={styles.grid}>
<div className={styles.content} dangerouslySetInnerHTML={{
__html: post.content
Expand Down Expand Up @@ -54,6 +63,10 @@ export async function getStaticProps({ params = {} } = {}) {
content
title
slug
video {
videoSource
videoUrl
}
}
}
`,
Expand All @@ -63,6 +76,14 @@ export async function getStaticProps({ params = {} } = {}) {
});

const post = data?.data.postBy;
let oEmbed;

if ( post.video ) {
if ( post.video.videoSource === 'YouTube') {
oEmbed = await fetch(`https://www.youtube.com/oembed?url=${post.video.videoUrl}`)
oEmbed = await oEmbed.json();
}
}

const site = {
...data?.data.generalSettings
Expand All @@ -71,7 +92,11 @@ export async function getStaticProps({ params = {} } = {}) {
return {
props: {
post,
site
site,
video: {
...post.video,
oEmbed
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@ a {
* {
box-sizing: border-box;
}

figure {
width: 100%;
text-align: center;
}

figure iframe {
aspect-ratio: 200 / 113;
width: 100%;
max-width: 400px;
height: auto;
}

0 comments on commit 37bd168

Please sign in to comment.