sitemap-xml.ts

src/utils/sitemap-xml.ts
export interface SitemapEntry {
url: string
lastmod?: string
}
export function buildSitemapXml(entries: SitemapEntry[]): string {
const urls = entries
.map(
(entry) => {
const url = entry.url.endsWith('/') ? entry.url : `${entry.url}/`
return ` <url>\n <loc>${url}</loc>${entry.lastmod ? `\n <lastmod>${entry.lastmod}</lastmod>` : ''}\n </url>`
}
)
.join('\n')
return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls}\n</urlset>`
}
export function buildSitemapIndexXml(
sitemaps: { loc: string; lastmod?: string }[]

Showing the first 20 lines.

Get full code

Support

Talk to the developers of this project to learn more

We have been building professional websites for big clients for over 15 years. Gallop templates and blocks is our best foundation for SEO websites and web apps.

© 2026 Web Plant Media, LLC