2.5.1 • Published 2 years ago

gatsby-source-youtube v2.5.1

Weekly downloads
29
License
MIT
Repository
github
Last release
2 years ago

Npm version Npm downloads MIT license PRs welcome


gatsby-source-youtube is a Gatsby plugin to use Youtube as a data source.

Usage

  1. Download gatsby-source-youtube from the NPM registry:
yarn add gatsby-source-youtube
  1. Generate a OAuth 2.0 token

The package needs 3 .env variables with the following format to work:

GOOGLE_OAUTH_CLIENT_ID=2...m.apps.googleusercontent.com
GOOGLE_OAUTH_CLIENT_SECRET=Q...axL
YOUTUBE_TOKEN={"access_token":"ya...J0","refresh_token":"1..mE","scope":"https://www.googleapis.com/auth/youtube.readonly","token_type":"Bearer","expiry_date":1598284554759}

gatsby-source-youtube expose a script to make the generation easier.

Open a terminal at the root of your project and type:

gatsby-source-youtube-token
  1. Add the plugin in your gatsby-config.js file
module.exports = {
  plugins: [
    {
      resolve: "gatsby-source-youtube",
      options: {
        // All options are optional
        // By default, it will fetch videos from your playlists
        //
        // Comma-separated list of the YouTube channel ID(s)
        channelId: "AFD...dfgDF",
        // Comma-separated list of the YouTube playlist ID(s)
        playlistId: "AFD...dfgDF",
        // To update video:
        updateVideo: (video) => {
          const countryTag = video.tags.find((tag) => tag.startWith("country"))

          if (countryTag) {
            const [, country] = video.title.split(":")
            return {
              ...video,
              country,
            }
          }

          return video
        },
        // For a better stack trace and more information
        debug: true,
      },
    },
    // Recommanded to use with gatsby-image
    "gatsby-transformer-sharp",
    "gatsby-plugin-sharp",
  ],
}

Showcase

You are using gatsby-source-youtube for your website? Thank you!

Please add your website to the Showcase

Contributing

  • ⇄ Pull/Merge requests and ★ Stars are always welcome.
  • For bugs and feature requests, please create an issue.

Changelog

See CHANGELOG

License

This project is licensed under the MIT License - see the LICENCE file for details

2.5.1

2 years ago

2.5.0

2 years ago

2.4.0

2 years ago

2.3.2

3 years ago

2.3.1

3 years ago

2.3.0

3 years ago

2.2.0

4 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.1

6 years ago

1.0.0

6 years ago