CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-nuxtjs--sitemap

Powerfully flexible XML Sitemaps that integrate seamlessly, for Nuxt.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

content-integration.mddocs/

Content Integration

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';

Capabilities

Sitemap Schema

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>;

Collection Enhancement

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>;

Schema Field Types

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);

Integration with Nuxt Content

Automatic Content-Driven Sitemaps

When using strictNuxtContentPaths: true in module configuration, the module automatically:

  1. Discovers all content files in your content directory
  2. Extracts sitemap metadata from frontmatter using the schema
  3. Generates sitemap entries with proper URLs based on content file paths
  4. Applies any custom sitemap fields from the frontmatter
  5. Includes images and videos referenced in the content

Content URL Generation

The module automatically generates URLs for content based on:

  • Content file path structure
  • Nuxt Content route generation rules
  • Custom loc field overrides in frontmatter
  • i18n locale prefixes (when using @nuxtjs/i18n)

Schema Validation Benefits

Using the sitemap schema provides:

  • Type safety for sitemap-specific frontmatter fields
  • Validation of image and video metadata
  • IDE autocompletion for sitemap properties
  • Runtime validation of content metadata
  • Consistent structure across all content files

Install with Tessl CLI

npx tessl i tessl/npm-nuxtjs--sitemap

docs

content-integration.md

data-types-configuration.md

index.md

module-configuration.md

server-composables.md

xml-html-utilities.md

tile.json