Skip to content
Open
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
2 changes: 1 addition & 1 deletion examples/hybrid-v4-pure/server/content.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createNuxtContent } from '@nuxt/content/content'
import { createNuxtContent } from '@nuxt/content/server'
import fs from 'comark-content/sources/fs'

export const content = createNuxtContent({
Expand Down
10 changes: 7 additions & 3 deletions migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Nuxt Content 4 is built on [comark-content](https://content.comark.dev). Several
| `server/cms.ts` | `server/content.ts` |
| `export const cms` | `export const content` |
| auto-imported `cms` | auto-imported `content` |
| `@nuxt/content/cms` | `@nuxt/content/content` |
| `@nuxt/content/cms` | `@nuxt/content/server` |

## `<ContentRenderer>` is now `<ContentDocument>`

Expand All @@ -45,7 +45,7 @@ Compared to v3's `<ContentRenderer>`:

```ts
// server/content.ts
import { createNuxtContent } from '@nuxt/content/content'
import { createNuxtContent } from '@nuxt/content/server'
import fs from 'comark-content/sources/fs'
import media from 'comark-content/plugins/media'

Expand All @@ -67,6 +67,10 @@ export const content = createNuxtContent({
})
```

### v3 server composables

`queryCollection`, `queryCollectionNavigation`, `queryCollectionItemSurroundings` and `queryCollectionSearchSections` are auto-imported while `content.compatibilityVersion` is `3`. To import them by hand, use `@nuxt/content/v3/server`: `@nuxt/content/server` now exports `createNuxtContent()`.

### Sources provided by a layer

A layer's `server/content.ts` is used when the project has none: the project's file comes first, then each layer's by priority. Without any `server/content.ts`, the v3 `content.config.ts` files of every layer are merged as before. With `content.compatibilityVersion: 4`, `content.config.ts` files are ignored, with a warning.
Expand Down Expand Up @@ -128,7 +132,7 @@ To change their options, register your own plugin with the same name under `mark

```ts
// server/content.ts
import { createNuxtContent } from '@nuxt/content/content'
import { createNuxtContent } from '@nuxt/content/server'
import fs from 'comark-content/sources/fs'
import toc from 'comark/plugins/toc'

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"import": "./dist/module.mjs"
},
"./v3": "./dist/runtime/v3/index.js",
"./content": "./dist/runtime/server/content.js",
"./v3/server": "./dist/runtime/v3/composables.server.js",
"./app": "./dist/runtime/client-content/app.js",
"./utils": "./dist/runtime/utils/index.js",
"./server": "./dist/runtime/v3/composables.server.js"
"./server": "./dist/runtime/server/content.js"
},
"main": "./dist/module.mjs",
"typesVersions": {
Expand Down
3 changes: 2 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export default defineNuxtModule<ModuleOptions>({

// Point the entries' imports at the runtime: the package exports target `dist/runtime/*.js`, which a stubbed build doesn't emit.
nuxt.options.nitro.alias = defu(nuxt.options.nitro.alias, {
'@nuxt/content/content': resolve('./runtime/server/content'),
'@nuxt/content/server': resolve('./runtime/server/content'),
'@nuxt/content/v3/server': resolve('./runtime/v3/composables.server'),
})
nuxt.options.alias['@nuxt/content/app'] = resolve('./runtime/client-content/app')

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/client-content/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface NuxtAppContentOptions {

/**
* Create the `content` the app reads, in `app/content.ts`. The browser counterpart of
* `createNuxtContent()` from `@nuxt/content/content`, for `compatibilityVersion: 4` in hybrid mode.
* `createNuxtContent()` from `@nuxt/content/server`, for `compatibilityVersion: 4` in hybrid mode.
*/
export function createNuxtContent(options: NuxtAppContentOptions = {}): ContentClient {
if (import.meta.server) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type ImportContentOptions = {
toc?: ResolvedTocOptions
/** Heading tags resolved from `content.renderer.anchorLinks`. */
anchorLinks?: string[]
/** This module's `@nuxt/content/content` entry, so it resolves without going through `dist` (stubbed builds). */
/** This module's `@nuxt/content/server` entry, so it resolves without going through `dist` (stubbed builds). */
contentEntryPath?: string
}

Expand All @@ -31,7 +31,7 @@ function createContentJiti(rootDir: string, options: ImportContentOptions) {
fsCache: false,
alias: {
...(options.highlightPath ? { '#content/highlight': options.highlightPath } : {}),
...(options.contentEntryPath ? { '@nuxt/content/content': options.contentEntryPath } : {}),
...(options.contentEntryPath ? { '@nuxt/content/server': options.contentEntryPath } : {}),
},
transform: (opts) => {
const source = opts.source
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/app-content/server/content.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createNuxtContent } from '@nuxt/content/content'
import { createNuxtContent } from '@nuxt/content/server'
import fs from 'comark-content/sources/fs'

export const content = createNuxtContent({
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/layer-sources/docs-layer/server/content.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { existsSync } from 'node:fs'
import { join } from 'node:path'
import type { JsonSchema } from 'comark-content'
import { createNuxtContent } from '@nuxt/content/content'
import { createNuxtContent } from '@nuxt/content/server'
import fs from 'comark-content/sources/fs'
import json from 'comark-content/plugins/json'
import yaml from 'comark-content/plugins/yaml'
Expand Down
2 changes: 2 additions & 0 deletions test/fixtures/v3-page-defaults/server/api/pages.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { queryCollection } from '@nuxt/content/v3/server'

// What v3 pages expose for `useSeoMeta(page.seo)` and listings.
export default defineEventHandler(async (event) => {
const pages = await queryCollection(event, 'content').all()
Expand Down
Loading