Function sitemap

Generates an XML sitemap for search engines.

Creates a properly formatted XML sitemap following the sitemap protocol specification. Perfect for SEO and helping search engines discover and index your pages.

import { sitemap } from '@raven-js/beak/seo';

const xml = sitemap({
domain: 'example.com',
pages: ['/', '/about', '/contact', '/blog']
});
// Output:
// <?xml version="1.0" encoding="UTF-8"?>
// <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
// <url>
// <loc>https://example.com/</loc>
// <lastmod>2024-01-15T10:30:00.000Z</lastmod>
// <changefreq>weekly</changefreq>
// <priority>0.8</priority>
// </url>
// <url>
// <loc>https://example.com/about</loc>
// <lastmod>2024-01-15T10:30:00.000Z</lastmod>
// <changefreq>weekly</changefreq>
// <priority>0.8</priority>
// </url>
// ...
// </urlset>
// With custom settings
const xml = sitemap({
domain: 'example.com',
pages: ['/', '/blog', '/contact'],
lastmod: '2024-01-01T00:00:00.000Z',
changefreq: 'daily',
priority: '1.0'
});
// Dynamic page generation
const blogPosts = ['/blog/post-1', '/blog/post-2', '/blog/post-3'];
const staticPages = ['/', '/about', '/contact'];
const allPages = [...staticPages, ...blogPosts];

const xml = sitemap({
domain: 'example.com',
pages: allPages
});
  • Parameters

    • config: SitemapConfig

      Configuration object for the sitemap

    Returns string

    The generated XML sitemap as a string