This package provides a YouTube video loader for the Astro Loader API https://www.npmjs.com/package/@richardnbanks/astro-loader-youtube
  • TypeScript 100%
Find a file
2026-06-04 07:47:47 +00:00
.forgejo/workflows chore(deps): update dependency pnpm to v11 2026-06-03 08:05:29 +00:00
.github chore(deps): pin dependencies 2026-06-03 15:28:06 +00:00
src feat: added deployment workflow 2026-02-11 01:03:54 +02:00
.gitignore feat: created a youtube content loader for astro 2025-01-19 19:20:57 +02:00
.npmrc chore: added npmrc config 2026-03-17 17:29:26 +02:00
index.ts feat: created a youtube content loader for astro 2025-01-19 19:20:57 +02:00
LICENSE fix: added missing license file 2025-01-19 20:35:28 +02:00
package.json chore(deps): pin dependencies 2026-06-04 07:47:47 +00:00
pnpm-lock.yaml chore(deps): pin dependencies 2026-06-04 07:47:47 +00:00
pnpm-workspace.yaml feat: added deployment workflow 2026-02-11 01:03:54 +02:00
README.md chore: update package import to correct name in readme (#13) 2025-05-03 19:50:37 +02:00
renovate.json chore: updated renovate config 2026-06-04 07:45:37 +00:00
tsconfig.json feat: created a youtube content loader for astro 2025-01-19 19:20:57 +02:00

Astro YouTube Video Loader

This package provides a YouTube video loader for the Astro Loader API. It allows you to load and parse YouTube video data and use the data in your Astro site.

Installation

npm install @richardnbanks/astro-loader-youtube
pnpm add @richardnbanks/astro-loader-youtube

Usage

This package requires Astro 5 or later (You can enable experimental support for the content loader API in astro 4.10 or later).

Firstly add the content loader to your content configuration:

// src/content.config.ts
import { defineCollection } from "astro:content";
import { youtubeLoader } from "@richardnbanks/astro-loader-youtube";

const youtube = defineCollection({
  loader: youtubeLoader({
    channelId: import.meta.env.YOUTUBE_CHANNEL_ID,
    apiKey: import.meta.env.YOUTUBE_API_KEY,
    maxResults: 1,
  }),
});

export const collections = { youtube };

Now just use it like any other content collection in astro:

---
import { getCollection, type CollectionEntry, render } from "astro:content";
import Layout from "../../layouts/Layout.astro";
const videos = await getCollection("youtube");
---

<Layout>
  {
    videos.map(async (video) => {
      return (
        <section>
            <a href={"https://youtube.com/watch?v=" + video.id} title={video.title}>
                <img src={video.data.thumbnails.default.url} alt={video.title} />
            </a>
        </section>
      );
    })
  }
</Layout>

Options

The youtubeLoader function takes an options object with the following properties:

  • channelId: The id of the channel you want to query videos from.
  • apiKey: API Key for the YouTube Data API.
  • maxResults (optional): The total number of videos you would like to fetch.

Rendering videos with Astro Embed

You can use Astro Embed to render YouTube videos for you.

---
import {getCollection} from "astro:content";
import {YouTube} from "astro-embed";

const videos = await getCollection("youtube");
---

{videos.map((video) => <YouTube id={video.id} />)}