diff --git a/src/lib/sitemap.test.ts b/src/lib/sitemap.test.ts index dfbad97a..e96716d9 100644 --- a/src/lib/sitemap.test.ts +++ b/src/lib/sitemap.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import { finalizeSitemap } from './sitemap' +import { finalizeSitemap, shouldIncludeInSitemap } from './sitemap' const sitemap = ` @@ -72,3 +72,12 @@ describe('finalizeSitemap', () => { ).toHaveLength(1) }) }) + +describe('shouldIncludeInSitemap', () => { + it('keeps concrete routes and excludes dynamic route templates', () => { + expect(shouldIncludeInSitemap('/blog/t7-network-upgrade')).toBe(true) + expect(shouldIncludeInSitemap('/docs/guide/payments')).toBe(true) + expect(shouldIncludeInSitemap('/blog/[slug]')).toBe(false) + expect(shouldIncludeInSitemap('/examples/[id]/details')).toBe(false) + }) +}) diff --git a/src/lib/sitemap.ts b/src/lib/sitemap.ts index 1fc53bae..e2de97ff 100644 --- a/src/lib/sitemap.ts +++ b/src/lib/sitemap.ts @@ -1,6 +1,10 @@ const TEMPLATE_URL_PATTERN = /\s*([^<]*\/\[[^\]]+\][^<]*)<\/loc>[\s\S]*?<\/url>\s*/g const LOCATION_PATTERN = /([^<]+)<\/loc>/g +export function shouldIncludeInSitemap(path: string): boolean { + return !/\/\[[^\]]+\](?:\/|$)/.test(path) +} + export function finalizeSitemap( sitemap: string, blogPostSlugs: readonly string[], diff --git a/vocs.config.ts b/vocs.config.ts index 87851370..08eb34d2 100644 --- a/vocs.config.ts +++ b/vocs.config.ts @@ -3,6 +3,7 @@ import { resolveBaseUrl } from './src/lib/base-url' import { docsRouteDestination, proxiedLegacyDocsRoutes } from './src/lib/docs-routing' import { createFeedbackAdapter } from './src/lib/feedback-adapter' import { plainMarkdownComponents } from './src/lib/markdown-output' +import { shouldIncludeInSitemap } from './src/lib/sitemap' // Only set baseUrl in production — Vocs injects a tag from this value, // which causes all links to resolve to the absolute URL on preview deployments. @@ -125,6 +126,7 @@ export default defineConfig({ }, }, sitemap: { + include: shouldIncludeInSitemap, lastmod: (path, { lastmod }) => { const pagePath = typeof path === 'string' ? path : '/' if (pagePath === '/docs' || pagePath.startsWith('/docs/')) return false