Powerfully flexible XML Sitemaps that integrate seamlessly, for Nuxt.
npx @tessl/cli install tessl/npm-nuxtjs--sitemap@7.4.0@nuxtjs/sitemap is a comprehensive Nuxt.js module that provides powerfully flexible XML sitemap generation capabilities for Nuxt applications. It offers single and multiple sitemap support, automatic URL discovery, image and video discovery, lastmod detection, SWR caching, i18n integration, and extensive customization options for SEO-compliant XML sitemaps.
npx nuxi@latest module add sitemap// Main module and types
import type { ModuleOptions } from '@nuxtjs/sitemap';
// Content integration
import { schema, asSitemapCollection } from '@nuxtjs/sitemap/content';
// Utilities
import { parseSitemapXml, parseHtmlExtractSitemapMeta } from '@nuxtjs/sitemap/utils';Server-only imports (available only in server context):
// Server composables (only available in Nuxt server context)
import { asSitemapUrl, defineSitemapEventHandler } from '#sitemap/server/composables';// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@nuxtjs/sitemap'],
sitemap: {
hostname: 'https://example.com',
gzip: true,
urls: [
'/special-page',
{
loc: '/priority-page',
lastmod: new Date(),
changefreq: 'weekly',
priority: 0.8
}
]
}
})@nuxtjs/sitemap is built around several key components:
Core Nuxt module setup and comprehensive configuration options for sitemap generation, including single/multiple sitemap support, caching, filtering, and i18n integration.
interface ModuleOptions extends SitemapDefinition {
enabled: boolean;
debug: boolean;
minify: boolean;
credits: boolean;
autoLastmod: boolean;
excludeAppSources: true | AppSourceContext[];
sortEntries: boolean;
discoverImages: boolean;
discoverVideos: boolean;
defaultSitemapsChunkSize: number | false;
sitemaps?: boolean | MultiSitemapsInput;
sitemapsPathPrefix: string | false;
appendSitemaps?: (string | SitemapIndexEntry)[];
xsl: string | false;
xslTips: boolean;
xslColumns?: XslColumn[];
cacheMaxAgeSeconds: number | false;
runtimeCacheStorage: boolean | (Record<string, any> & { driver: string });
autoI18n?: boolean | AutoI18nConfig;
strictNuxtContentPaths: boolean;
experimentalWarmUp?: boolean;
experimentalCompression?: boolean;
}Nuxt Content integration with sitemap-specific schema validation and collection enhancement for seamless content-driven sitemap generation.
function asSitemapCollection<T extends ZodRawShape>(
collection: Collection<T>
): Collection<T>;
const schema: ZodObject<{
sitemap: ZodObject<SitemapContentFields>
}>;Server-side composables and utilities for runtime sitemap generation, URL processing, and event handler creation within the Nuxt server context.
function asSitemapUrl(
url: SitemapUrlInput | Record<string, any>
): SitemapUrlInput;
const defineSitemapEventHandler: typeof defineEventHandler<
EventHandlerRequest,
EventHandlerResponse<SitemapUrlInput[]>
>;Utility functions for parsing existing XML sitemaps and extracting sitemap metadata from HTML documents for analysis and integration purposes.
function parseSitemapXml(xml: string): Promise<SitemapParseResult>;
function parseHtmlExtractSitemapMeta(
html: string,
options?: {
images?: boolean;
videos?: boolean;
lastmod?: boolean;
alternatives?: boolean;
resolveUrl?: (s: string) => string;
}
): SitemapUrl[];
interface SitemapParseResult {
urls: SitemapUrlInput[];
warnings: SitemapWarning[];
}
interface SitemapWarning {
type: 'validation';
message: string;
context?: {
url?: string;
field?: string;
value?: unknown;
};
}Comprehensive type system covering sitemap entries, validation schemas, configuration interfaces, and runtime context objects for full type safety.
interface SitemapUrl {
loc: string;
lastmod?: string | Date;
changefreq?: Changefreq;
priority?: 0 | 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9 | 1;
alternatives?: AlternativeEntry[];
images?: ImageEntry[];
videos?: VideoEntry[];
}
interface SitemapDefinition {
include?: FilterInput[];
exclude?: FilterInput[];
sitemapName: string;
urls?: MaybeFunction<MaybePromise<SitemapUrlInput[]>>;
sources?: SitemapSourceInput[];
}