Skip to content

Commit

Permalink
fix!: remove deprecations (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw authored Nov 24, 2024
1 parent 987729e commit eb8c8c2
Show file tree
Hide file tree
Showing 16 changed files with 20 additions and 131 deletions.
3 changes: 1 addition & 2 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default defineNuxtConfig({
prerender: true,
},
'/secret': {
index: false,
robots: false,
},
'/users-test/*': {
sitemap: {
Expand Down Expand Up @@ -124,7 +124,6 @@ export default defineNuxtConfig({
sitemap: {
debug: true,
// sitemapName: 'test.xml',
// dynamicUrlsApiEndpoint: '/__sitemap',
minify: false,
cacheMaxAgeSeconds: 10,
xslColumns: [
Expand Down
45 changes: 1 addition & 44 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
addServerPlugin,
createResolver,
defineNuxtModule,
findPath,
getNuxtModuleVersion,
hasNuxtModule,
hasNuxtModuleCompatibility,
Expand Down Expand Up @@ -61,7 +60,6 @@ export default defineNuxtModule<ModuleOptions>({
autoLastmod: false,
discoverImages: true,
discoverVideos: true,
dynamicUrlsApiEndpoint: '/api/_sitemap-urls',
urls: [],
sortEntries: true,
sitemapsPathPrefix: '/__sitemap__/',
Expand All @@ -78,7 +76,6 @@ export default defineNuxtModule<ModuleOptions>({
// sources
sources: [],
excludeAppSources: [],
inferStaticPagesAsRoutes: true,
},
async setup(config, nuxt) {
const { resolve } = createResolver(import.meta.url)
Expand Down Expand Up @@ -378,30 +375,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'] = {}
Expand Down Expand Up @@ -434,7 +407,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 },
Expand Down Expand Up @@ -561,10 +534,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'),
Expand Down Expand Up @@ -700,18 +669,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)) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/server/plugins/nuxt-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/runtime/server/sitemap/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {})
Expand Down
25 changes: 0 additions & 25 deletions src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -358,10 +337,6 @@ export interface SitemapUrl {
videos?: Array<VideoEntry>
_i18nTransform?: boolean
_sitemap?: string
/**
* @deprecated use `loc`
*/
url?: string
}

export interface AlternativeEntry {
Expand Down
2 changes: 1 addition & 1 deletion src/util/nuxtSitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/i18n-micro/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default defineNuxtConfig({
meta: true,
},
sitemap: {
dynamicUrlsApiEndpoint: '/__sitemap',
sources: ['/__sitemap'],
autoLastmod: false,
credits: false,
debug: true,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/i18n/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default defineNuxtConfig({
],
},
sitemap: {
dynamicUrlsApiEndpoint: '/__sitemap',
sources: ['/__sitemap'],
autoLastmod: false,
credits: false,
debug: true,
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/no-pages/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default defineNuxtConfig({
url: 'https://nuxtseo.com',
},
sitemap: {
dynamicUrlsApiEndpoint: '/__sitemap',
sources: ['/__sitemap'],
autoLastmod: false,
credits: false,
debug: true,
Expand Down
4 changes: 2 additions & 2 deletions test/integration/i18n/route-rules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ await setup({
},
routeRules: {
'/hidden': {
index: false,
robots: false,
},
'/defaults': {
sitemap: {
Expand All @@ -47,7 +47,7 @@ await setup({
},
},
'/wildcard/hidden/**': {
index: false,
robots: false,
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions test/integration/multi/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/integration/single/changeApiUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ await setup({
rootDir: resolve('../../fixtures/basic'),
nuxtConfig: {
sitemap: {
dynamicUrlsApiEndpoint: '/__sitemap',
sources: ['/__sitemap'],
},
},
})
Expand Down
40 changes: 0 additions & 40 deletions test/integration/single/inferStaticPagesAsRoutes.test.ts

This file was deleted.

4 changes: 2 additions & 2 deletions test/integration/single/routeRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ await setup({
redirect: '/defaults',
},
'/hidden': {
index: false,
robots: false,
},
'/defaults': {
sitemap: {
Expand All @@ -37,7 +37,7 @@ await setup({
},
},
'/wildcard/hidden/**': {
index: false,
robots: false,
},
},
},
Expand Down
6 changes: 3 additions & 3 deletions test/integration/single/routeRulesTrailingSlash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ await setup({
},
routeRules: {
'/hidden': {
index: false,
robots: false,
},
'/hidden/': {
index: false,
robots: false,
},
'/defaults': {
sitemap: {
Expand All @@ -34,7 +34,7 @@ await setup({
},
},
'/wildcard/hidden/**': {
index: false,
robots: false,
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion test/integration/single/trailingSlashes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ await setup({
},
sitemap: {
// test from endpoint as well
dynamicUrlsApiEndpoint: '/__sitemap',
sources: ['/__sitemap'],
},
},
})
Expand Down

0 comments on commit eb8c8c2

Please sign in to comment.