Skip to content

Commit ee78c76

Browse files
committed
Normalize sitemap before reading URLs
Move normalizeSitemap earlier in postProcessLlmsOutput so the sitemap is normalized (dropping <loc> entries shadowed by vercel.json redirects and stripping trailing slashes from dotted-segment routes) before readSitemapUrls, pruneStaleLlmsLinks, and generateAllPagesIndex run. This ensures generated llms-all-*.txt indexes and pruning operate on the same 200-only URL set the deployed sitemap exposes and avoids pointing agents at redirecting pages. Add console logging for skipped or processed sitemap normalization.
1 parent 3c7b110 commit ee78c76

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

src/plugins/llms-html-injector/index.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,24 @@ async function postProcessLlmsOutput(outDir, siteUrl) {
204204
const rewriteCount = await rewriteLlmsIndexes(outDir, renames, siteUrl)
205205
console.log(`[llms-html-injector] Updated URLs in ${rewriteCount} llms*.txt file(s)`)
206206

207+
// Normalize the sitemap *before* reading its URLs: normalizeSitemap drops
208+
// `<loc>`s shadowed by a vercel.json redirect (they 3XX on the deployed
209+
// site) and strips trailing slashes from dotted-segment routes. Reading the
210+
// sitemap afterward ensures pruneStaleLlmsLinks and generateAllPagesIndex
211+
// operate on the same 200-only URL set the deployed sitemap exposes, so the
212+
// generated llms-all-*.txt indexes never point agents at redirecting pages.
213+
const sitemap = await normalizeSitemap(outDir, siteUrl)
214+
if (sitemap.skipped) {
215+
console.warn(
216+
'[llms-html-injector] No sitemap.xml found in outDir; skipping sitemap normalization.'
217+
)
218+
} else {
219+
console.log(
220+
`[llms-html-injector] Sitemap: stripped trailing slash from ${sitemap.rewritten} dotted-segment <loc>(s) ` +
221+
`and dropped ${sitemap.dropped} URL(s) shadowed by a vercel.json redirect`
222+
)
223+
}
224+
207225
const sitemapUrls = await readSitemapUrls(outDir)
208226
if (sitemapUrls) {
209227
const stale = await pruneStaleLlmsLinks(outDir, sitemapUrls, siteUrl)
@@ -238,18 +256,6 @@ async function postProcessLlmsOutput(outDir, siteUrl) {
238256
`[llms-html-injector] Stripped trailing slash from canonical/og:url on ${canonicalFixed} dotted-route page(s)`
239257
)
240258

241-
const sitemap = await normalizeSitemap(outDir, siteUrl)
242-
if (sitemap.skipped) {
243-
console.warn(
244-
'[llms-html-injector] No sitemap.xml found in outDir; skipping sitemap normalization.'
245-
)
246-
} else {
247-
console.log(
248-
`[llms-html-injector] Sitemap: stripped trailing slash from ${sitemap.rewritten} dotted-segment <loc>(s) ` +
249-
`and dropped ${sitemap.dropped} URL(s) shadowed by a vercel.json redirect`
250-
)
251-
}
252-
253259
// On Vercel preview/development deployments, rewrite every absolute URL in
254260
// generated llms*.txt files and per-page .md files from the canonical
255261
// production host to the preview's auto-assigned host. The HTML alternate

0 commit comments

Comments
 (0)