Sitemap
Guides

Images & Videos

Learn how to add images and videos in your sitemap.

Generated sitemaps are given the image and video namespaces by default. This allows you to add images and videos to your sitemap.

Images

To add images to your sitemap, you can use the images property on the sitemap entry.

You can learn more about images in sitemaps on the Google documentation.

export interface ImageEntry {
  loc: string
}

You can implement this as follows:

nuxt.config.ts
export default defineNuxtConfig({
  sitemap: {
    urls: [
      {
        loc: '/blog/my-post',
        images: [
          {
            loc: 'https://example.com/image.jpg',
            caption: 'My image caption',
            geoLocation: 'My image geo location',
            title: 'My image title',
            license: 'My image license',
          }
        ]
      }
    ]
  }
})

Automatic Image Discovery

When you prerender your pages, the module can discover images in your page and add them to your sitemap automatically.

To enable this, you must have a <main> tag in your layout that will be scanned for images. This is to avoid adding images from your header and footer.

Videos

To add videos to your sitemap, you can use the videos property on the sitemap entry.

The TypeScript interface for videos is as follows:

export interface VideoEntry {
  title: string
  thumbnail_loc: string | URL
  description: string
  content_loc?: string | URL
  player_loc?: string | URL
  duration?: number
  expiration_date?: Date | string
  rating?: number
  view_count?: number
  publication_date?: Date | string
  family_friendly?: 'yes' | 'no' | boolean
  restriction?: Restriction
  platform?: Platform
  price?: ({
    price?: number | string
    currency?: string
    type?: 'rent' | 'purchase' | 'package' | 'subscription'
  })[]
  requires_subscription?: 'yes' | 'no' | boolean
  uploader?: {
    uploader: string
    info?: string | URL
  }
  live?: 'yes' | 'no' | boolean
  tag?: string | string[]
}

You can learn more about videos in sitemaps on the Google documentation.

You can implement this as follows:

nuxt.config.ts
export default defineNuxtConfig({
  sitemap: {
    urls: [
      {
        loc: '/blog/my-post',
        videos: [
          {
            title: 'My video title',
            thumbnail_loc: 'https://example.com/video.jpg',
            description: 'My video description',
            content_loc: 'https://example.com/video.mp4',
            player_loc: 'https://example.com/video.mp4',
            duration: 600,
            expiration_date: '2021-01-01',
            rating: 4.2,
            view_count: 1000,
            publication_date: '2021-01-01',
            family_friendly: true,
            restriction: {
              relationship: 'allow',
              country: 'US',
            },
            platform: {
              relationship: 'allow',
              platform: 'web',
              date: '2021-01-01',
            },
            price: [
              {
                price: 1.99,
                currency: 'USD',
                type: 'rent',
              }
            ],
            requires_subscription: true,
            uploader: {
              uploader: 'My video uploader',
              info: 'https://example.com/uploader',
            },
            live: true,
            tag: ['tag1', 'tag2'],
          }
        ]
      }
    ]
  }
})