From 7a7868ab43d7923a74ef55a8294b5dbd356c113c Mon Sep 17 00:00:00 2001 From: harlan Date: Mon, 25 Nov 2024 03:10:35 +1100 Subject: [PATCH 1/3] fix!: remove deprecations --- playground/nuxt.config.ts | 1 - src/module.ts | 45 +------------------ src/runtime/types.ts | 25 ----------- test/fixtures/i18n-micro/nuxt.config.ts | 2 +- test/fixtures/i18n/nuxt.config.ts | 2 +- test/fixtures/no-pages/nuxt.config.ts | 2 +- test/integration/multi/endpoints.ts | 4 +- test/integration/single/changeApiUrl.test.ts | 2 +- .../single/inferStaticPagesAsRoutes.test.ts | 3 +- test/integration/single/trailingSlashes.ts | 2 +- 10 files changed, 9 insertions(+), 79 deletions(-) diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index 24227384..3ef70181 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -124,7 +124,6 @@ export default defineNuxtConfig({ sitemap: { debug: true, // sitemapName: 'test.xml', - // dynamicUrlsApiEndpoint: '/__sitemap', minify: false, cacheMaxAgeSeconds: 10, xslColumns: [ diff --git a/src/module.ts b/src/module.ts index 5cf513ea..5123fb2d 100644 --- a/src/module.ts +++ b/src/module.ts @@ -5,7 +5,6 @@ import { addServerPlugin, createResolver, defineNuxtModule, - findPath, getNuxtModuleVersion, hasNuxtModule, hasNuxtModuleCompatibility, @@ -61,7 +60,6 @@ export default defineNuxtModule({ autoLastmod: false, discoverImages: true, discoverVideos: true, - dynamicUrlsApiEndpoint: '/api/_sitemap-urls', urls: [], sortEntries: true, sitemapsPathPrefix: '/__sitemap__/', @@ -78,7 +76,6 @@ export default defineNuxtModule({ // sources sources: [], excludeAppSources: [], - inferStaticPagesAsRoutes: true, }, async setup(config, nuxt) { const { resolve } = createResolver(import.meta.url) @@ -379,30 +376,6 @@ declare module 'vue-router' { fetch: '/__sitemap__/nuxt-content-urls.json', }) } - const hasLegacyDefaultApiSource = !!(await findPath(resolve(nuxt.options.serverDir, 'api/_sitemap-urls'))) - if ( - // make sure they didn't manually add it as a source - !config.sources?.includes('/api/_sitemap-urls') - // if they didn't and they have the file OR if they've manually configured the URL to something else, provide the source - && (hasLegacyDefaultApiSource || config.dynamicUrlsApiEndpoint !== '/api/_sitemap-urls') - ) { - userGlobalSources.push({ - context: { - name: 'dynamicUrlsApiEndpoint', - description: 'Generated from your dynamicUrlsApiEndpoint config.', - tips: [ - 'The `dynamicUrlsApiEndpoint` config is deprecated.', - hasLegacyDefaultApiSource - ? 'Consider renaming the `api/_sitemap-urls` file and add it the `sitemap.sources` config instead. This provides more explicit sitemap generation.' - : 'Consider switching to using the `sitemap.sources` config which also supports fetch options.', - ], - }, - fetch: hasLegacyDefaultApiSource ? '/api/_sitemap-urls' : config.dynamicUrlsApiEndpoint as string, - }) - } - else { - config.dynamicUrlsApiEndpoint = false - } // config -> sitemaps const sitemaps: ModuleRuntimeConfig['sitemaps'] = {} @@ -435,7 +408,7 @@ declare module 'vue-router' { { sitemapName, _route: withBase(joinURL(config.sitemapsPathPrefix, `${sitemapName}.xml`), nuxt.options.app.baseURL || '/'), - _hasSourceChunk: typeof definition.urls !== 'undefined' || definition.sources?.length || !!definition.dynamicUrlsApiEndpoint, + _hasSourceChunk: typeof definition.urls !== 'undefined' || definition.sources?.length, }, { ...definition, urls: undefined, sources: undefined }, { include: config.include, exclude: config.exclude }, @@ -562,10 +535,6 @@ declare module 'vue-router' { setupDevToolsUI(config, resolve) } - // support deprecated config - if (!config.inferStaticPagesAsRoutes) - config.excludeAppSources = true - const imports: typeof nuxt.options.imports.imports = [ { from: resolve('./runtime/server/composables/defineSitemapEventHandler'), @@ -701,18 +670,6 @@ declare module 'vue-router' { urls: await resolveUrls(definition.urls, { path: `sitemaps:${sitemapName}:urls`, logger }), }) } - if (definition!.dynamicUrlsApiEndpoint) { - sitemapSources[sitemapName].push({ - context: { - name: `${sitemapName}:dynamicUrlsApiEndpoint`, - description: `Generated from your ${sitemapName}:dynamicUrlsApiEndpoint config.`, - tips: [ - `You should switch to using the \`sitemaps.${sitemapName}.sources\` config which also supports fetch options.`, - ], - }, - fetch: definition!.dynamicUrlsApiEndpoint, - }) - } sitemapSources[sitemapName].push(...(definition.sources || []) .map((s) => { if (typeof s === 'string' || Array.isArray(s)) { diff --git a/src/runtime/types.ts b/src/runtime/types.ts index ba2dfe8e..20c2bafe 100644 --- a/src/runtime/types.ts +++ b/src/runtime/types.ts @@ -34,13 +34,6 @@ export interface ModuleOptions extends SitemapDefinition { * @default false */ autoLastmod: boolean - /** - * Should pages be automatically added to the sitemap. - * - * @default true - * @deprecated If set to false, use `excludeAppSources: ['pages', 'route-rules', 'prerender']` instead. Otherwise, remove this. - */ - inferStaticPagesAsRoutes: boolean /** * Sources to exclude from the sitemap. */ @@ -134,14 +127,6 @@ export interface ModuleOptions extends SitemapDefinition { * @default true */ credits: boolean - /** - * How long, in milliseconds, should the sitemap be cached for. - * - * @default 1 hour - * - * @deprecated use cacheMaxAgeSeconds - */ - cacheTtl?: number | false /** * How long, in seconds, should the sitemap be cached for. * @@ -312,12 +297,6 @@ export interface SitemapDefinition { * Additional sources of URLs to include in the sitemap. */ sources?: SitemapSourceInput[] - /** - * The endpoint to fetch dynamic URLs from. - * - * @deprecated use `sources` - */ - dynamicUrlsApiEndpoint?: string | false /** * @internal */ @@ -358,10 +337,6 @@ export interface SitemapUrl { videos?: Array _i18nTransform?: boolean _sitemap?: string - /** - * @deprecated use `loc` - */ - url?: string } export interface AlternativeEntry { diff --git a/test/fixtures/i18n-micro/nuxt.config.ts b/test/fixtures/i18n-micro/nuxt.config.ts index 865c2365..e94479d6 100644 --- a/test/fixtures/i18n-micro/nuxt.config.ts +++ b/test/fixtures/i18n-micro/nuxt.config.ts @@ -38,7 +38,7 @@ export default defineNuxtConfig({ meta: true, }, sitemap: { - dynamicUrlsApiEndpoint: '/__sitemap', + sources: ['/__sitemap'], autoLastmod: false, credits: false, debug: true, diff --git a/test/fixtures/i18n/nuxt.config.ts b/test/fixtures/i18n/nuxt.config.ts index 1128bcf9..1e7276f7 100644 --- a/test/fixtures/i18n/nuxt.config.ts +++ b/test/fixtures/i18n/nuxt.config.ts @@ -38,7 +38,7 @@ export default defineNuxtConfig({ ], }, sitemap: { - dynamicUrlsApiEndpoint: '/__sitemap', + sources: ['/__sitemap'], autoLastmod: false, credits: false, debug: true, diff --git a/test/fixtures/no-pages/nuxt.config.ts b/test/fixtures/no-pages/nuxt.config.ts index 67008b06..f0644404 100644 --- a/test/fixtures/no-pages/nuxt.config.ts +++ b/test/fixtures/no-pages/nuxt.config.ts @@ -9,7 +9,7 @@ export default defineNuxtConfig({ url: 'https://nuxtseo.com', }, sitemap: { - dynamicUrlsApiEndpoint: '/__sitemap', + sources: ['/__sitemap'], autoLastmod: false, credits: false, debug: true, diff --git a/test/integration/multi/endpoints.ts b/test/integration/multi/endpoints.ts index 343182c2..6175943a 100644 --- a/test/integration/multi/endpoints.ts +++ b/test/integration/multi/endpoints.ts @@ -10,14 +10,14 @@ await setup({ sitemap: { sitemaps: { foo: { - dynamicUrlsApiEndpoint: '/api/sitemap/foo', + sources: ['/api/sitemap/foo'], defaults: { changefreq: 'weekly', priority: 0.7, }, }, bar: { - dynamicUrlsApiEndpoint: '/api/sitemap/bar', + sources: ['/api/sitemap/bar'], }, }, }, diff --git a/test/integration/single/changeApiUrl.test.ts b/test/integration/single/changeApiUrl.test.ts index c75600a9..25e74742 100644 --- a/test/integration/single/changeApiUrl.test.ts +++ b/test/integration/single/changeApiUrl.test.ts @@ -8,7 +8,7 @@ await setup({ rootDir: resolve('../../fixtures/basic'), nuxtConfig: { sitemap: { - dynamicUrlsApiEndpoint: '/__sitemap', + sources: ['/__sitemap'], }, }, }) diff --git a/test/integration/single/inferStaticPagesAsRoutes.test.ts b/test/integration/single/inferStaticPagesAsRoutes.test.ts index f96f4886..3bdc0d65 100644 --- a/test/integration/single/inferStaticPagesAsRoutes.test.ts +++ b/test/integration/single/inferStaticPagesAsRoutes.test.ts @@ -13,8 +13,7 @@ await setup({ 'b/:name': { swr: 500 }, }, sitemap: { - inferStaticPagesAsRoutes: false, - dynamicUrlsApiEndpoint: '/__sitemap', + sources: ['/__sitemap'], }, }, }) diff --git a/test/integration/single/trailingSlashes.ts b/test/integration/single/trailingSlashes.ts index 8f67f69d..6feddf7e 100644 --- a/test/integration/single/trailingSlashes.ts +++ b/test/integration/single/trailingSlashes.ts @@ -13,7 +13,7 @@ await setup({ }, sitemap: { // test from endpoint as well - dynamicUrlsApiEndpoint: '/__sitemap', + sources: ['/__sitemap'], }, }, }) From 50690aa2f3ab98850a0566120d88c14cc41fe544 Mon Sep 17 00:00:00 2001 From: harlan Date: Mon, 25 Nov 2024 03:29:34 +1100 Subject: [PATCH 2/3] chore: drop `index` key usage --- playground/nuxt.config.ts | 2 +- src/runtime/server/plugins/nuxt-content.ts | 2 +- src/runtime/server/sitemap/nitro.ts | 6 ++---- src/util/nuxtSitemap.ts | 2 +- test/integration/i18n/route-rules.test.ts | 4 ++-- test/integration/single/routeRules.ts | 4 ++-- test/integration/single/routeRulesTrailingSlash.test.ts | 6 +++--- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index 3ef70181..e76dd956 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -58,7 +58,7 @@ export default defineNuxtConfig({ prerender: true, }, '/secret': { - index: false, + robots: false, }, '/users-test/*': { sitemap: { diff --git a/src/runtime/server/plugins/nuxt-content.ts b/src/runtime/server/plugins/nuxt-content.ts index 6619d4d2..99785ee8 100644 --- a/src/runtime/server/plugins/nuxt-content.ts +++ b/src/runtime/server/plugins/nuxt-content.ts @@ -10,7 +10,7 @@ export default defineNitroPlugin((nitroApp: NitroApp) => { // @ts-expect-error untyped nitroApp.hooks.hook('content:file:afterParse', async (content: ParsedContent) => { const validExtensions = ['md', 'mdx'] - if (content.sitemap === false || content._draft || !validExtensions.includes(content._extension) || content._partial || content.indexable === false || content.index === false) + if (content.sitemap === false || content._draft || !validExtensions.includes(content._extension) || content._partial || content.robots === false) return // add any top level images diff --git a/src/runtime/server/sitemap/nitro.ts b/src/runtime/server/sitemap/nitro.ts index c114cb88..cb96434b 100644 --- a/src/runtime/server/sitemap/nitro.ts +++ b/src/runtime/server/sitemap/nitro.ts @@ -70,10 +70,8 @@ export async function createSitemap(event: H3Event, definition: SitemapDefinitio if (routeRules.sitemap === false) return false - if ((typeof routeRules.index !== 'undefined' && !routeRules.index) - // @ts-expect-error runtime types - || (typeof routeRules.robots !== 'undefined' && !routeRules.robots) - ) { + // @ts-expect-error runtime types + if (typeof routeRules.robots !== 'undefined' && !routeRules.robots) { return false } const hasRobotsDisabled = Object.entries(routeRules.headers || {}) diff --git a/src/util/nuxtSitemap.ts b/src/util/nuxtSitemap.ts index dab01a61..2f291e42 100644 --- a/src/util/nuxtSitemap.ts +++ b/src/util/nuxtSitemap.ts @@ -221,7 +221,7 @@ export function generateExtraRoutesFromNuxtConfig(nuxt: Nuxt = useNuxt()) { // make sure key doesn't use a wildcard and its not for a file if (k.includes('*') || k.includes('.') || k.includes(':')) return false - if (typeof v.index === 'boolean' && !v.index) + if (typeof v.robots === 'boolean' && !v.robots) return false // make sure that we're not redirecting return !v.redirect diff --git a/test/integration/i18n/route-rules.test.ts b/test/integration/i18n/route-rules.test.ts index 29faf730..ab83e319 100644 --- a/test/integration/i18n/route-rules.test.ts +++ b/test/integration/i18n/route-rules.test.ts @@ -32,7 +32,7 @@ await setup({ }, routeRules: { '/hidden': { - index: false, + robots: false, }, '/defaults': { sitemap: { @@ -47,7 +47,7 @@ await setup({ }, }, '/wildcard/hidden/**': { - index: false, + robots: false, }, }, }, diff --git a/test/integration/single/routeRules.ts b/test/integration/single/routeRules.ts index 94a3b92d..71c44a6d 100644 --- a/test/integration/single/routeRules.ts +++ b/test/integration/single/routeRules.ts @@ -22,7 +22,7 @@ await setup({ redirect: '/defaults', }, '/hidden': { - index: false, + robots: false, }, '/defaults': { sitemap: { @@ -37,7 +37,7 @@ await setup({ }, }, '/wildcard/hidden/**': { - index: false, + robots: false, }, }, }, diff --git a/test/integration/single/routeRulesTrailingSlash.test.ts b/test/integration/single/routeRulesTrailingSlash.test.ts index 711244d0..c8416d1f 100644 --- a/test/integration/single/routeRulesTrailingSlash.test.ts +++ b/test/integration/single/routeRulesTrailingSlash.test.ts @@ -16,10 +16,10 @@ await setup({ }, routeRules: { '/hidden': { - index: false, + robots: false, }, '/hidden/': { - index: false, + robots: false, }, '/defaults': { sitemap: { @@ -34,7 +34,7 @@ await setup({ }, }, '/wildcard/hidden/**': { - index: false, + robots: false, }, }, }, From eacdfd755ac1290e79e34111ae8523f25d8e6b7f Mon Sep 17 00:00:00 2001 From: harlan Date: Mon, 25 Nov 2024 03:31:30 +1100 Subject: [PATCH 3/3] chore: legacy test --- .../single/inferStaticPagesAsRoutes.test.ts | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 test/integration/single/inferStaticPagesAsRoutes.test.ts diff --git a/test/integration/single/inferStaticPagesAsRoutes.test.ts b/test/integration/single/inferStaticPagesAsRoutes.test.ts deleted file mode 100644 index 3bdc0d65..00000000 --- a/test/integration/single/inferStaticPagesAsRoutes.test.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { describe, expect, it } from 'vitest' -import { createResolver } from '@nuxt/kit' -import { $fetch, setup } from '@nuxt/test-utils' - -const { resolve } = createResolver(import.meta.url) - -await setup({ - rootDir: resolve('../../fixtures/basic'), - nuxtConfig: { - routeRules: { - '/': { swr: 600 }, - '/a/:id': { swr: 600 }, // This result is something I don’t want to show in the sitemap - 'b/:name': { swr: 500 }, - }, - sitemap: { - sources: ['/__sitemap'], - }, - }, -}) -describe('inferStaticPagesAsRoutes', () => { - it('disabled', async () => { - const posts = await $fetch('/sitemap.xml') - - expect(posts).toMatchInlineSnapshot(` - " - - - https://nuxtseo.com/__sitemap/abs - - - https://nuxtseo.com/__sitemap/loc - - - https://nuxtseo.com/__sitemap/url - - " - `) - }, 60000) -})