Skip to content

Commit d632b5e

Browse files
committedJan 20, 2025·
fix(content): export util from @nuxtjs/robots/content
1 parent 1a70b9f commit d632b5e

File tree

8 files changed

+55
-28
lines changed

8 files changed

+55
-28
lines changed
 

Diff for: ‎build.config.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { defineBuildConfig } from 'unbuild'
2+
3+
export default defineBuildConfig({
4+
declaration: true,
5+
rollup: {
6+
emitCJS: true,
7+
},
8+
entries: [
9+
{ input: 'src/content', name: 'content' },
10+
],
11+
externals: [
12+
'h3',
13+
'std-env',
14+
'nitropack',
15+
'consola',
16+
'@nuxt/content',
17+
'zod'
18+
],
19+
})

Diff for: ‎content.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './dist/content'

Diff for: ‎docs/content/2.guides/3.content.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ In Nuxt Content v3 we need to use the `asRobotsCollection()`{lang="ts"} function
1313
to be able to use the `robots` frontmatter key.
1414

1515
```ts [content.config.ts]
16-
import { defineCollection, defineContentConfig, z } from '@nuxt/content'
17-
import { asRobotsCollection } from '@nuxtjs/robots'
16+
import { defineCollection, defineContentConfig } from '@nuxt/content'
17+
import { asRobotsCollection } from '@nuxtjs/robots/content'
1818

1919
export default defineContentConfig({
2020
collections: {
@@ -39,6 +39,7 @@ const route = useRoute()
3939
const { data: page } = await useAsyncData(`page-${route.path}`, () => {
4040
return queryCollection('content').path(route.path).first()
4141
})
42+
// Ensure the SEO meta tags are rendered
4243
useSeoMeta(page.value.seo)
4344
</script>
4445
```

Diff for: ‎package.json

+18-8
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,29 @@
3636
"./dist/runtime/util": {
3737
"types": "./dist/runtime/util.d.ts",
3838
"import": "./dist/runtime/util.js"
39+
},
40+
"./content": {
41+
"types": "./dist/content.d.ts",
42+
"import": "./dist/content.mjs",
43+
"require": "./dist/content.cjs"
3944
}
4045
},
4146
"main": "./dist/module.cjs",
4247
"types": "./dist/types.d.ts",
48+
"typesVersions": {
49+
"*": {
50+
"content": [
51+
"dist/content"
52+
],
53+
"utils": [
54+
"dist/utils"
55+
]
56+
}
57+
},
4358
"files": [
44-
"dist"
59+
"content.d.ts",
60+
"dist",
61+
"util.d.ts"
4562
],
4663
"scripts": {
4764
"lint": "eslint . --fix",
@@ -100,12 +117,5 @@
100117
},
101118
"resolutions": {
102119
"typescript": "5.6.3"
103-
},
104-
"build": {
105-
"externals": [
106-
"h3",
107-
"consola",
108-
"@nuxt/content"
109-
]
110120
}
111121
}

Diff for: ‎src/content.ts

+12-15
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1+
import type { Collection } from '@nuxt/content'
2+
import type { TypeOf, ZodRawShape } from 'zod'
13
import { z } from '@nuxt/content'
24

3-
export function asRobotsCollection(collection: any) {
4-
if (collection.type !== 'page') {
5-
return
6-
}
7-
if (!collection.schema) {
8-
collection.schema = z.object({
9-
robots: z.union([z.string(), z.boolean()]).optional(),
10-
})
11-
}
12-
else {
13-
collection.schema = collection.schema.extend({
14-
robots: z.union([z.string(), z.boolean()]).optional(),
15-
})
5+
export const schema = z.object({
6+
robots: z.union([z.string(), z.boolean()]).optional(),
7+
})
8+
9+
export type RobotSchema = TypeOf<typeof schema>
10+
11+
export function asRobotsCollection<T extends ZodRawShape>(collection: Collection<T>): Collection<T> {
12+
if (collection.type === 'page') {
13+
// @ts-expect-error untyped
14+
collection.schema = collection.schema ? collection.schema.extend(schema) : schema
1615
}
17-
collection._integrations = collection._integrations || []
18-
collection._integrations.push('robots')
1916
return collection
2017
}

Diff for: ‎src/module.ts

-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ export interface ModulePublicRuntimeConfig {
169169
['nuxt-robots']: ResolvedModuleOptions
170170
}
171171

172-
export * from './content'
173-
174172
export default defineNuxtModule<ModuleOptions>({
175173
meta: {
176174
name: '@nuxtjs/robots',

Diff for: ‎test/fixtures/content-v3/content.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defineCollection, defineContentConfig, z } from '@nuxt/content'
2-
import { asRobotsCollection } from '../../../src/module'
2+
import { asRobotsCollection } from '../../../src/content'
33

44
export default defineContentConfig({
55
collections: {

Diff for: ‎util.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './dist/runtime/util'

0 commit comments

Comments
 (0)
Please sign in to comment.