Skip to content

Commit

Permalink
embed latest episode. closes #75.
Browse files Browse the repository at this point in the history
  • Loading branch information
bradgarropy committed Mar 1, 2020
1 parent 1cff5ef commit 494f71e
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 8 deletions.
27 changes: 27 additions & 0 deletions src/components/YouTube.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react"
import PropTypes from "prop-types"
import styled from "styled-components"

const StyledYouTube = styled.iframe`
display: block;
`

const YouTube = ({id}) => {
return (
<StyledYouTube
title={id}
width="560"
height="315"
src={`https://www.youtube-nocookie.com/embed/${id}`}
frameBorder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen
/>
)
}

YouTube.propTypes = {
id: PropTypes.string.isRequired,
}

export default YouTube
1 change: 1 addition & 0 deletions src/hooks/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export {default as useTags} from "./useTags"
export {default as useAbout} from "./useAbout"
export {default as usePosts} from "./usePosts"
export {default as useEpisode} from "./useEpisode"
export {default as useEpisodes} from "./useEpisodes"
export {default as usePlaylist} from "./usePlaylist"
export {default as usePlaylists} from "./usePlaylists"
Expand Down
36 changes: 36 additions & 0 deletions src/hooks/useEpisode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {useStaticQuery, graphql} from "gatsby"

const useEpisode = () => {
const query = graphql`
{
allYoutubeVideo(
limit: 1
sort: {fields: publishedAt, order: DESC}
) {
nodes {
title
videoId
description
localThumbnail {
childImageSharp {
fluid(maxWidth: 700) {
...GatsbyImageSharpFluid
}
}
}
}
}
}
`

const data = useStaticQuery(query)

const episode = data.allYoutubeVideo.nodes[0]

// truncate description
episode.description = episode.description.split("---")[0]

return episode
}

export default useEpisode
2 changes: 1 addition & 1 deletion src/hooks/useEpisodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {useStaticQuery, graphql} from "gatsby"
const useEpisodes = ({limit = 0} = {}) => {
const query = graphql`
{
allYoutubeVideo {
allYoutubeVideo(sort: {fields: publishedAt, order: DESC}) {
nodes {
title
videoId
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/usePosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const usePosts = ({limit = 0} = {}) => {
{
allMarkdownRemark(
filter: {fileAbsolutePath: {regex: "/content/posts/"}}
sort: {fields: frontmatter___date}
sort: {fields: frontmatter___date, order: DESC}
) {
nodes {
frontmatter {
Expand Down
13 changes: 7 additions & 6 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import React from "react"
import {Link} from "gatsby"
import Section from "../styles/Section"
import Posts from "../components/Posts"
import Episodes from "../components/Episodes"
import YouTube from "../components/YouTube"
import Playlists from "../components/Playlists"
import {Meta, Twitter, Facebook} from "../components/SEO"
import {usePosts, useEpisodes, usePlaylists} from "../hooks"
import {usePosts, useEpisode, usePlaylist} from "../hooks"

const IndexPage = () => {
const posts = usePosts({limit: 3})
const episodes = useEpisodes({limit: 1})
const playlists = usePlaylists({name: "Daily Texas Country"})
const episode = useEpisode()
const playlist = usePlaylist({name: "Daily Texas Country"})

return (
<>
Expand All @@ -26,7 +26,7 @@ const IndexPage = () => {

<Section color="red">
<h1>episodes</h1>
<Episodes episodes={episodes} />
<YouTube id={episode.videoId} />
<Link to="/episodes">see more</Link>
</Section>

Expand All @@ -35,7 +35,8 @@ const IndexPage = () => {
</Section>

<Section color="red">
<Playlists playlists={playlists} />
<h1>playlists</h1>
<Playlists playlists={[playlist]} />
<Link to="/playlists">see more</Link>
</Section>
</>
Expand Down

0 comments on commit 494f71e

Please sign in to comment.