Powerfully flexible XML Sitemaps that integrate seamlessly, for Nuxt.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Nuxt Content integration with sitemap-specific schema validation and collection enhancement for seamless content-driven sitemap generation.
import { schema, asSitemapCollection } from '@nuxtjs/sitemap/content';
import type { SitemapSchema } from '@nuxtjs/sitemap/content';Zod schema for validating sitemap metadata in Nuxt Content frontmatter.
/**
* Zod schema object for sitemap frontmatter validation
* Defines the structure of sitemap-specific fields in content files
*/
const schema: ZodObject<{
sitemap: ZodObject<{
loc: ZodOptional<ZodString>;
lastmod: ZodOptional<ZodDate>;
changefreq: ZodOptional<ZodUnion<[
ZodLiteral<'always'>, ZodLiteral<'hourly'>, ZodLiteral<'daily'>,
ZodLiteral<'weekly'>, ZodLiteral<'monthly'>, ZodLiteral<'yearly'>, ZodLiteral<'never'>
]>>;
priority: ZodOptional<ZodNumber>;
images: ZodOptional<ZodArray<ZodObject<ImageSchema>>>;
videos: ZodOptional<ZodArray<ZodObject<VideoSchema>>>;
}>;
}>;
/**
* TypeScript type derived from the schema
*/
type SitemapSchema = TypeOf<typeof schema>;Function to enhance Nuxt Content collections with sitemap schema validation.
/**
* Enhances a Nuxt Content collection with sitemap schema validation
* @param collection - The Nuxt Content collection to enhance
* @returns Enhanced collection with sitemap schema validation
*/
function asSitemapCollection<T extends ZodRawShape>(
collection: Collection<T>
): Collection<T>;Basic Sitemap Fields
interface SitemapContentFields {
/** Custom URL location (overrides default content URL) */
loc?: string;
/** Last modification date */
lastmod?: Date;
/** How frequently the page is likely to change */
changefreq?: 'always' | 'hourly' | 'daily' | 'weekly' | 'monthly' | 'yearly' | 'never';
/** Priority of this URL relative to other URLs on your site (0.0 to 1.0) */
priority?: number;
/** Associated images for this content */
images?: ImageEntry[];
/** Associated videos for this content */
videos?: VideoEntry[];
}Image Metadata Schema
interface ImageEntry {
/** Image URL location */
loc: string;
/** Image caption */
caption?: string;
/** Geographic location of the image */
geo_location?: string;
/** Image title */
title?: string;
/** License URL for the image */
license?: string;
}Video Metadata Schema
interface VideoEntry {
/** Video content URL */
content_loc: string;
/** Video player URL */
player_loc?: string;
/** Duration in seconds */
duration?: string;
/** Expiration date for the video */
expiration_date?: Date;
/** Video rating (0.0 to 5.0) */
rating?: number;
/** View count */
view_count?: number;
/** Publication date */
publication_date?: Date;
/** Whether the video is family friendly */
family_friendly?: boolean;
/** Video tag */
tag?: string;
/** Video category */
category?: string;
/** Geographic restrictions */
restriction?: {
relationship?: 'allow';
value?: string;
};
/** Gallery location URL */
gallery_loc?: string;
/** Price information */
price?: string;
/** Whether a subscription is required */
requires_subscription?: boolean;
/** Uploader information */
uploader?: string;
}Usage Examples:
// content/blog/my-post.md frontmatter
/*
---
title: My Blog Post
sitemap:
priority: 0.8
changefreq: weekly
images:
- loc: /images/blog/my-post-hero.jpg
caption: Hero image for my blog post
title: Blog Post Hero
- loc: /images/blog/my-post-diagram.png
caption: Technical diagram
videos:
- content_loc: /videos/blog/my-post-demo.mp4
duration: "120"
family_friendly: true
category: tutorial
---
*/
// Enhance a Nuxt Content collection
import { asSitemapCollection } from '@nuxtjs/sitemap/content';
import { defineCollection, z } from '@nuxt/content';
export const blogCollection = asSitemapCollection(
defineCollection({
name: 'blog',
pattern: 'blog/**/*.md',
schema: z.object({
title: z.string(),
description: z.string(),
publishedAt: z.date(),
})
})
);
// Using the schema in validation
import { schema } from '@nuxtjs/sitemap/content';
const contentWithSitemap = {
title: 'My Article',
sitemap: {
priority: 0.9,
changefreq: 'weekly',
images: [{
loc: '/hero-image.jpg',
caption: 'Article hero image'
}]
}
};
const result = schema.parse(contentWithSitemap);Automatic Content-Driven Sitemaps
When using strictNuxtContentPaths: true in module configuration, the module automatically:
Content URL Generation
The module automatically generates URLs for content based on:
loc field overrides in frontmatterSchema Validation Benefits
Using the sitemap schema provides:
Install with Tessl CLI
npx tessl i tessl/npm-nuxtjs--sitemap