Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion scripts/seo-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,21 @@ const colorise = (level, text) => {
return `${codes[level] || ''}${text}\x1b[0m`
}

// @nuxtjs/sitemap >= 7.5 serves an empty 204 (and a meta-refresh instead of a
// 307) whenever the sitemap endpoints are requested with *any* query string,
// so the mock-prod query must not be appended to sitemap URLs. The sitemap is
// environment-independent here anyway; only robots.txt and page meta need the
// production mock.
const isSitemapPath = (pathname) =>
/^\/(sitemap[^/]*\.xml|sitemap_index\.xml|__sitemap__\/)/i.test(pathname)

/**
* Builds a URL relative to BASE and adds the dev mock-prod query when
* targeting localhost so we exercise the production robots/sitemap path.
*/
const buildUrl = (path) => {
const url = new URL(path, BASE)
if (USE_MOCK && !url.searchParams.has('mockProductionEnv')) {
if (USE_MOCK && !isSitemapPath(url.pathname) && !url.searchParams.has('mockProductionEnv')) {
url.searchParams.set('mockProductionEnv', '')
}
return url
Expand Down
Loading