Skip to content
Merged
Show file tree
Hide file tree
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
139 changes: 129 additions & 10 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ overrides:
cssnano-utils: 8.1.0
nuxt-site-config: https://pkg.pr.new/harlan-zw/nuxt-site-config/nuxt-site-config@b8c8a6978ce818d77ecc50c679d412e748fdbdcb
nuxt-site-config-kit: https://pkg.pr.new/harlan-zw/nuxt-site-config/nuxt-site-config-kit@b8c8a6978ce818d77ecc50c679d412e748fdbdcb
nuxtseo-shared: https://pkg.pr.new/harlan-zw/nuxt-seo/nuxtseo-shared@226c091a0744b7286ef721ac035eed53856bfaa5
postcss-calc: 11.2.2
postcss-colormin: 9.0.6
postcss-convert-values: 9.0.7
Expand Down Expand Up @@ -150,7 +149,7 @@ catalog:
nuxt: ^4.6.0
nuxt-site-config: ^5.0.0
nuxtseo-layer-devtools: ^5.3.16
nuxtseo-shared: ^6.0.0
nuxtseo-shared: ^6.0.3
radix3: ^1.1.2
sirv: ^3.0.2
std-env: ^4.3.0
Expand Down
6 changes: 6 additions & 0 deletions src/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ _robotsPatternMap?: Map<string, PatternMapValue>`,
getContents: () => `// Generated by nuxt-robots
import type { HookRobotsConfigContext, HookRobotsTxtContext, RobotsValue, RobotsContext, PatternMapValue } from '@nuxtjs/robots'

declare module '@nuxt/schema' {
interface AppRouteRulesExtensions {
${routeRules}
}
}

${nitroTypes}

export {}
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/nuxt5/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export default defineNuxtConfig({
debug: true,
},
routeRules: {
'/api/route-rules': {
robots: { index: false, 'max-snippet': 120 },
},
'/private': {
robots: false,
},
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures/nuxt5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "module",
"packageManager": "pnpm@12.8.1",
"scripts": {
"test": "nuxt cleanup && nuxt prepare && vue-tsc --noEmit -p .nuxt/tsconfig.app.json && vue-tsc --noEmit -p .nuxt/tsconfig.server.json && nuxt build && node test.mjs"
"test": "nuxt cleanup && nuxt prepare && vue-tsc --noEmit -p .nuxt/tsconfig.app.json && vue-tsc --noEmit -p .nuxt/tsconfig.node.json && vue-tsc --noEmit -p .nuxt/tsconfig.server.json && nuxt build && node test.mjs"
},
"dependencies": {
"@nuxtjs/robots": "link:../../..",
Expand All @@ -15,6 +15,7 @@
"vue-router": "^5.3.1"
},
"devDependencies": {
"@types/node": "^26.1.2",
"typescript": "6.0.3",
"vue-tsc": "^3.3.12"
}
Expand Down
190 changes: 72 additions & 118 deletions test/fixtures/nuxt5/pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/fixtures/nuxt5/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ overrides:
nuxt-site-config: https://pkg.pr.new/harlan-zw/nuxt-site-config/nuxt-site-config@40698727ca424460013f3534af9005e36728d669
nuxt-site-config-kit: https://pkg.pr.new/harlan-zw/nuxt-site-config/nuxt-site-config-kit@40698727ca424460013f3534af9005e36728d669
site-config-stack: https://pkg.pr.new/harlan-zw/nuxt-site-config/site-config-stack@40698727ca424460013f3534af9005e36728d669
nuxtseo-shared: https://pkg.pr.new/harlan-zw/nuxt-seo/nuxtseo-shared@113287e3fb44472264dd56fc90fb695ff8a9f6dd
nuxtseo-shared: ^6.0.3
onlyBuiltDependencies:
- "@firebase/util"
- "@parcel/watcher"
Expand Down
15 changes: 15 additions & 0 deletions test/fixtures/nuxt5/server/api/route-rules.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { RobotsRouteRuleConfig } from '@nuxtjs/robots'
import type { AppRouteRules } from 'nuxt/server'
import { defineEventHandler, getRouteRules } from 'nuxt/server'

const routeConfig = {
robots: { index: false, 'max-snippet': 120 },
} satisfies AppRouteRules

export default defineEventHandler((event) => {
const robots: RobotsRouteRuleConfig['robots'] = getRouteRules(event).robots
return {
config: routeConfig.robots,
resolved: robots,
}
})
10 changes: 10 additions & 0 deletions test/fixtures/nuxt5/test-route-rules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import assert from 'node:assert/strict'

export async function assertRouteRules(origin: string) {
const response = await fetch(`${origin}/api/route-rules`)
assert.equal(response.status, 200)
assert.deepEqual(await response.json(), {
config: { index: false, 'max-snippet': 120 },
resolved: { index: false, 'max-snippet': 120 },
})
}
2 changes: 2 additions & 0 deletions test/fixtures/nuxt5/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { spawn } from 'node:child_process'
import { once } from 'node:events'
import { readFile } from 'node:fs/promises'
import { createServer } from 'node:net'
import { assertRouteRules } from './test-route-rules.ts'

const portServer = createServer()
portServer.listen(0, '127.0.0.1')
Expand Down Expand Up @@ -37,6 +38,7 @@ async function waitForServer() {

try {
const robots = await (await waitForServer()).text()
await assertRouteRules(origin)
assert.match(robots, /User-agent: \*/)
const response = await fetch(origin, { headers: { 'user-agent': 'Googlebot/2.1 (+http://www.google.com/bot.html)' } })
assert.equal(response.status, 200)
Expand Down
Loading