From 96eb7a6ae0cb6f4039cb2587d16ea3030e97a86e Mon Sep 17 00:00:00 2001 From: harlan Date: Fri, 20 Dec 2024 23:05:59 +1100 Subject: [PATCH 01/10] feat: `content:parsed` hook --- docs/content/docs/7.advanced/5.hooks.md | 20 +++++++++++++ src/types/module.ts | 7 +++++ src/utils/content/index.ts | 4 ++- test/unit/hooks.test.ts | 39 +++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 docs/content/docs/7.advanced/5.hooks.md create mode 100644 test/unit/hooks.test.ts diff --git a/docs/content/docs/7.advanced/5.hooks.md b/docs/content/docs/7.advanced/5.hooks.md new file mode 100644 index 000000000..a4b5921e1 --- /dev/null +++ b/docs/content/docs/7.advanced/5.hooks.md @@ -0,0 +1,20 @@ +--- +title: Hooks +description: Modify your content using Nuxt build time hooks +navigation: + title: Hooks +--- + +## `content:parsed`{lang="ts"} + +This hook is called after the content is parsed and before it is saved to the database. + +```ts +export default defineNuxtConfig({ + hooks: { + 'content:parsed'(ctx) { + // { content: CollectionItemBase, collection: ResolvedCollection } + } + } +}) +``` diff --git a/src/types/module.ts b/src/types/module.ts index bca4ac232..5e72f4deb 100644 --- a/src/types/module.ts +++ b/src/types/module.ts @@ -3,6 +3,7 @@ import type { ListenOptions } from 'listhen' import type { GitInfo } from '../utils/git' import type { MarkdownPlugin } from './content' import type { PathMetaOptions } from './path-meta' +import type { CollectionItemBase, DataCollectionItemBase, PageCollectionItemBase, ResolvedCollection } from './collection' export interface D1DatabaseConfig { type: 'd1' @@ -187,3 +188,9 @@ export interface PublicRuntimeConfig { iframeMessagingAllowedOrigins?: string } } + +export type ContentParsedHook = { content: CollectionItemBase | DataCollectionItemBase | PageCollectionItemBase, collection: ResolvedCollection } + +export interface ModuleHooks { + 'content:parsed': (hook: ContentParsedHook) => void | Promise +} diff --git a/src/utils/content/index.ts b/src/utils/content/index.ts index 410199bcd..844842817 100644 --- a/src/utils/content/index.ts +++ b/src/utils/content/index.ts @@ -160,6 +160,8 @@ export async function createParser(collection: ResolvedCollection, nuxt?: Nuxt) result.seo.description = result.seo.description || result.description } - return result + const hookCtx = { content: result, collection } + await nuxt?.callHook?.('content:parsed', hookCtx) + return hookCtx.content } } diff --git a/test/unit/hooks.test.ts b/test/unit/hooks.test.ts new file mode 100644 index 000000000..91bedfcbe --- /dev/null +++ b/test/unit/hooks.test.ts @@ -0,0 +1,39 @@ +import { describe, expect, it } from 'vitest' +import { z } from 'zod' +import { defineCollection } from '../../src/utils' +import { resolveCollection } from '../../src/utils/collection' +import type { ContentParsedHook } from '../../src/types' +import { parseContent } from '../utils/content' + +describe('Hooks', () => { + const collection = resolveCollection('hookTest', defineCollection({ + type: 'data', + source: 'content/**', + schema: z.object({ + body: z.any(), + foo: z.any(), + }), + }))! + it('content:parsed', async () => { + let hookCtx: ContentParsedHook + const nuxtMock = { + callHook(hook: string, ctx: ContentParsedHook) { + if (hook === 'content:parsed') { + // augment + ctx.content.bar = 'foo' + hookCtx = ctx + } + }, + } + const parsed = await parseContent('content/index.md', `--- +foo: 'bar' +--- + + # Hello World +`, collection, nuxtMock) + expect(hookCtx.collection.name).toEqual('hookTest') + expect(parsed.id).toEqual('content/index.md') + expect(parsed.foo).toEqual('bar') + expect(parsed.bar).toEqual('foo') + }) +}) From c0f977d67633cad778e9fb25fafafa89e4b399f4 Mon Sep 17 00:00:00 2001 From: harlan Date: Fri, 20 Dec 2024 23:22:51 +1100 Subject: [PATCH 02/10] chore: prefer `collection:parsedFile` --- docs/content/docs/7.advanced/5.hooks.md | 4 ++-- src/types/module.ts | 2 +- src/utils/content/index.ts | 2 +- test/unit/hooks.test.ts | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/content/docs/7.advanced/5.hooks.md b/docs/content/docs/7.advanced/5.hooks.md index a4b5921e1..1a3093b30 100644 --- a/docs/content/docs/7.advanced/5.hooks.md +++ b/docs/content/docs/7.advanced/5.hooks.md @@ -5,14 +5,14 @@ navigation: title: Hooks --- -## `content:parsed`{lang="ts"} +## `collection:parsedFile`{lang="ts"} This hook is called after the content is parsed and before it is saved to the database. ```ts export default defineNuxtConfig({ hooks: { - 'content:parsed'(ctx) { + 'collection:parsedFile'(ctx) { // { content: CollectionItemBase, collection: ResolvedCollection } } } diff --git a/src/types/module.ts b/src/types/module.ts index 5e72f4deb..d138873f2 100644 --- a/src/types/module.ts +++ b/src/types/module.ts @@ -192,5 +192,5 @@ export interface PublicRuntimeConfig { export type ContentParsedHook = { content: CollectionItemBase | DataCollectionItemBase | PageCollectionItemBase, collection: ResolvedCollection } export interface ModuleHooks { - 'content:parsed': (hook: ContentParsedHook) => void | Promise + 'collection:parsedFile': (hook: ContentParsedHook) => void | Promise } diff --git a/src/utils/content/index.ts b/src/utils/content/index.ts index 844842817..ae5cf73d6 100644 --- a/src/utils/content/index.ts +++ b/src/utils/content/index.ts @@ -161,7 +161,7 @@ export async function createParser(collection: ResolvedCollection, nuxt?: Nuxt) } const hookCtx = { content: result, collection } - await nuxt?.callHook?.('content:parsed', hookCtx) + await nuxt?.callHook?.('collection:parsedFile', hookCtx) return hookCtx.content } } diff --git a/test/unit/hooks.test.ts b/test/unit/hooks.test.ts index 91bedfcbe..73c7c55a6 100644 --- a/test/unit/hooks.test.ts +++ b/test/unit/hooks.test.ts @@ -14,11 +14,11 @@ describe('Hooks', () => { foo: z.any(), }), }))! - it('content:parsed', async () => { + it('collection:parsedFile', async () => { let hookCtx: ContentParsedHook const nuxtMock = { callHook(hook: string, ctx: ContentParsedHook) { - if (hook === 'content:parsed') { + if (hook === 'collection:parsedFile') { // augment ctx.content.bar = 'foo' hookCtx = ctx From 122b2aab8884ca0abf0bbe5d9297432eb064b280 Mon Sep 17 00:00:00 2001 From: harlan Date: Sat, 21 Dec 2024 02:14:40 +1100 Subject: [PATCH 03/10] chore: use original hook names --- docs/content/docs/7.advanced/5.hooks.md | 39 +++++++++++++++++++++++-- src/types/module.ts | 21 ++++++++++--- src/utils/collection.ts | 3 +- src/utils/content/index.ts | 23 ++++++++++----- test/unit/hooks.test.ts | 29 ++++++++++++++---- 5 files changed, 94 insertions(+), 21 deletions(-) diff --git a/docs/content/docs/7.advanced/5.hooks.md b/docs/content/docs/7.advanced/5.hooks.md index 1a3093b30..d4aedea14 100644 --- a/docs/content/docs/7.advanced/5.hooks.md +++ b/docs/content/docs/7.advanced/5.hooks.md @@ -5,15 +5,48 @@ navigation: title: Hooks --- -## `collection:parsedFile`{lang="ts"} +## `content:file:beforeParse`{lang="ts"} + +This hook is called before the content is parsed. + +It can be used to modify the raw content from a `file` before it is transformed +or modify the transform options. + +```ts +export interface FileBeforeParseHook { + collection: ResolvedCollection + file: ContentFile + parserOptions: TransformContentOptions +} +``` + +```ts +export default defineNuxtConfig({ + hooks: { + 'content:file:beforeParse'(ctx) { + // ... + } + } +}) +``` + +## `content:file:afterParse`{lang="ts"} This hook is called after the content is parsed and before it is saved to the database. +```ts +export interface FileAfterParseHook { + collection: ResolvedCollection + file: ContentFile + content: ParsedContentFile +} +``` + ```ts export default defineNuxtConfig({ hooks: { - 'collection:parsedFile'(ctx) { - // { content: CollectionItemBase, collection: ResolvedCollection } + 'content:file:afterParse'(ctx) { + // ... } } }) diff --git a/src/types/module.ts b/src/types/module.ts index d138873f2..9180c2127 100644 --- a/src/types/module.ts +++ b/src/types/module.ts @@ -1,9 +1,9 @@ import type { BuiltinLanguage as ShikiLang, BuiltinTheme as ShikiTheme, LanguageRegistration, ThemeRegistrationAny, ThemeRegistrationRaw } from 'shiki' import type { ListenOptions } from 'listhen' import type { GitInfo } from '../utils/git' -import type { MarkdownPlugin } from './content' +import type { ContentFile, MarkdownPlugin, TransformContentOptions } from './content' import type { PathMetaOptions } from './path-meta' -import type { CollectionItemBase, DataCollectionItemBase, PageCollectionItemBase, ResolvedCollection } from './collection' +import type { ResolvedCollection } from './collection' export interface D1DatabaseConfig { type: 'd1' @@ -189,8 +189,21 @@ export interface PublicRuntimeConfig { } } -export type ContentParsedHook = { content: CollectionItemBase | DataCollectionItemBase | PageCollectionItemBase, collection: ResolvedCollection } +// TODO improve types +export type ParsedContentFile = Record + +export interface FileBeforeParseHook { + collection: ResolvedCollection + file: ContentFile + parserOptions: TransformContentOptions +} +export interface FileAfterParseHook { + collection: ResolvedCollection + file: ContentFile + content: ParsedContentFile +} export interface ModuleHooks { - 'collection:parsedFile': (hook: ContentParsedHook) => void | Promise + 'content:file:beforeParse': (hook: FileBeforeParseHook) => void | Promise + 'content:file:afterParse': (hook: FileAfterParseHook) => void | Promise } diff --git a/src/utils/collection.ts b/src/utils/collection.ts index 4ca5b4baa..63a322490 100644 --- a/src/utils/collection.ts +++ b/src/utils/collection.ts @@ -6,6 +6,7 @@ import { metaSchema, pageSchema } from './schema' import type { ZodFieldType } from './zod' import { getUnderlyingType, ZodToSqlFieldTypes, z, getUnderlyingTypeName } from './zod' import { logger } from './dev' +import type { ParsedContentFile } from '~/src/types' const JSON_FIELDS_TYPES = ['ZodObject', 'ZodArray', 'ZodRecord', 'ZodIntersection', 'ZodUnion', 'ZodAny'] @@ -98,7 +99,7 @@ function resolveSource(source: string | CollectionSource | CollectionSource[] | } // Convert collection data to SQL insert statement -export function generateCollectionInsert(collection: ResolvedCollection, data: Record): string[] { +export function generateCollectionInsert(collection: ResolvedCollection, data: ParsedContentFile): string[] { const fields: string[] = [] const values: Array = [] const sortedKeys = getOrderedSchemaKeys((collection.extendedSchema).shape) diff --git a/src/utils/content/index.ts b/src/utils/content/index.ts index ae5cf73d6..48a9269f9 100644 --- a/src/utils/content/index.ts +++ b/src/utils/content/index.ts @@ -6,8 +6,10 @@ import type { Nuxt } from '@nuxt/schema' import { defu } from 'defu' import { createOnigurumaEngine } from 'shiki/engine/oniguruma' import { visit } from 'unist-util-visit' -import type { ResolvedCollection } from '../../types/collection' -import type { ModuleOptions } from '../../types/module' +import type { + ResolvedCollection, +} from '../../types/collection' +import type { FileAfterParseHook, FileBeforeParseHook, ModuleOptions, ParsedContentFile } from '../../types/module' import { transformContent } from './transformers' import type { ContentFile } from '~/src/types' @@ -127,17 +129,21 @@ export async function createParser(collection: ResolvedCollection, nuxt?: Nuxt) }, } - return async function parse(file: ContentFile) { + return async function parse(file: ContentFile): Promise { if (file.path && !file.dirname) { file.dirname = dirname(file.path) } + const beforeParseCtx: FileBeforeParseHook = { file, collection, parserOptions } + // @ts-expect-error runtime type + await nuxt?.callHook?.('content:file:beforeParse', beforeParseCtx) + const { file: hookedFile, collection: hookedCollection } = beforeParseCtx - const parsedContent = await transformContent(file, parserOptions) + const parsedContent = await transformContent(hookedFile, beforeParseCtx.parserOptions) const { id: id, ...parsedContentFields } = parsedContent const result = { id } as typeof collection.extendedSchema._type const meta = {} as Record - const collectionKeys = Object.keys(collection.extendedSchema.shape) + const collectionKeys = Object.keys(hookedCollection.extendedSchema.shape) for (const key of Object.keys(parsedContentFields)) { if (collectionKeys.includes(key)) { result[key] = parsedContent[key] @@ -160,8 +166,9 @@ export async function createParser(collection: ResolvedCollection, nuxt?: Nuxt) result.seo.description = result.seo.description || result.description } - const hookCtx = { content: result, collection } - await nuxt?.callHook?.('collection:parsedFile', hookCtx) - return hookCtx.content + const afterParseCtx: FileAfterParseHook = { file: hookedFile, content: result, collection } + // @ts-expect-error runtime type + await nuxt?.callHook?.('content:file:afterParse', afterParseCtx) + return afterParseCtx.content } } diff --git a/test/unit/hooks.test.ts b/test/unit/hooks.test.ts index 73c7c55a6..064a0ed0f 100644 --- a/test/unit/hooks.test.ts +++ b/test/unit/hooks.test.ts @@ -2,8 +2,8 @@ import { describe, expect, it } from 'vitest' import { z } from 'zod' import { defineCollection } from '../../src/utils' import { resolveCollection } from '../../src/utils/collection' -import type { ContentParsedHook } from '../../src/types' import { parseContent } from '../utils/content' +import type { FileAfterParseHook, FileBeforeParseHook } from '../../src/types' describe('Hooks', () => { const collection = resolveCollection('hookTest', defineCollection({ @@ -14,11 +14,30 @@ describe('Hooks', () => { foo: z.any(), }), }))! - it('collection:parsedFile', async () => { - let hookCtx: ContentParsedHook + it('content:file:beforeParse', async () => { + let hookCtx: FileBeforeParseHook const nuxtMock = { - callHook(hook: string, ctx: ContentParsedHook) { - if (hook === 'collection:parsedFile') { + callHook(hook: string, ctx: FileBeforeParseHook) { + if (hook === 'content:file:beforeParse') { + ctx.file.body = ctx.file.body.replace('replace-me', 'bar') + hookCtx = ctx + } + }, + } + const content = await parseContent('content/index.md', `--- +foo: 'replace-me' +--- + + # Hello World +`, collection, nuxtMock) + expect(hookCtx.file.id).toEqual('content/index.md') + expect(content.foo).toEqual('bar') + }) + it('content:file:afterParse', async () => { + let hookCtx: FileAfterParseHook + const nuxtMock = { + callHook(hook: string, ctx: FileAfterParseHook) { + if (hook === 'content:file:afterParse') { // augment ctx.content.bar = 'foo' hookCtx = ctx From cf95c7ddc3559db391676da6dba6ef82f4ceb8fa Mon Sep 17 00:00:00 2001 From: harlan Date: Sat, 21 Dec 2024 02:38:06 +1100 Subject: [PATCH 04/10] chore: tidy up --- src/utils/collection.ts | 2 +- src/utils/content/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/collection.ts b/src/utils/collection.ts index 63a322490..ad2211681 100644 --- a/src/utils/collection.ts +++ b/src/utils/collection.ts @@ -6,7 +6,7 @@ import { metaSchema, pageSchema } from './schema' import type { ZodFieldType } from './zod' import { getUnderlyingType, ZodToSqlFieldTypes, z, getUnderlyingTypeName } from './zod' import { logger } from './dev' -import type { ParsedContentFile } from '~/src/types' +import type { ParsedContentFile } from '../types' const JSON_FIELDS_TYPES = ['ZodObject', 'ZodArray', 'ZodRecord', 'ZodIntersection', 'ZodUnion', 'ZodAny'] diff --git a/src/utils/content/index.ts b/src/utils/content/index.ts index 48a9269f9..469e3b144 100644 --- a/src/utils/content/index.ts +++ b/src/utils/content/index.ts @@ -129,7 +129,7 @@ export async function createParser(collection: ResolvedCollection, nuxt?: Nuxt) }, } - return async function parse(file: ContentFile): Promise { + return async function parse(file: ContentFile) { if (file.path && !file.dirname) { file.dirname = dirname(file.path) } From 2aaea3eee4bcd7eb6ffd97db068f708fb4e8a02b Mon Sep 17 00:00:00 2001 From: harlan Date: Sat, 21 Dec 2024 02:40:09 +1100 Subject: [PATCH 05/10] chore: tidy up --- src/utils/collection.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/collection.ts b/src/utils/collection.ts index ad2211681..fdbb74052 100644 --- a/src/utils/collection.ts +++ b/src/utils/collection.ts @@ -1,12 +1,12 @@ import type { ZodObject, ZodOptionalDef, ZodRawShape, ZodStringDef, ZodType } from 'zod' import type { Collection, ResolvedCollection, CollectionSource, DefinedCollection, ResolvedCollectionSource } from '../types/collection' import { getOrderedSchemaKeys } from '../runtime/internal/schema' +import type { ParsedContentFile } from '../types' import { defineLocalSource, defineGitHubSource } from './source' import { metaSchema, pageSchema } from './schema' import type { ZodFieldType } from './zod' import { getUnderlyingType, ZodToSqlFieldTypes, z, getUnderlyingTypeName } from './zod' import { logger } from './dev' -import type { ParsedContentFile } from '../types' const JSON_FIELDS_TYPES = ['ZodObject', 'ZodArray', 'ZodRecord', 'ZodIntersection', 'ZodUnion', 'ZodAny'] From d5536305c7189f85b00b5d409ac8e890fb658bb7 Mon Sep 17 00:00:00 2001 From: harlan Date: Sat, 21 Dec 2024 02:49:08 +1100 Subject: [PATCH 06/10] chore: tidy up --- src/utils/content/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/content/index.ts b/src/utils/content/index.ts index 469e3b144..34e5749c0 100644 --- a/src/utils/content/index.ts +++ b/src/utils/content/index.ts @@ -9,7 +9,7 @@ import { visit } from 'unist-util-visit' import type { ResolvedCollection, } from '../../types/collection' -import type { FileAfterParseHook, FileBeforeParseHook, ModuleOptions, ParsedContentFile } from '../../types/module' +import type { FileAfterParseHook, FileBeforeParseHook, ModuleOptions } from '../../types/module' import { transformContent } from './transformers' import type { ContentFile } from '~/src/types' From a2894bfb7781a2d88b49023b9b7a4ca11e764bd1 Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Tue, 24 Dec 2024 13:20:22 +1100 Subject: [PATCH 07/10] Update docs/content/docs/7.advanced/5.hooks.md Co-authored-by: Farnabaz --- docs/content/docs/7.advanced/5.hooks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/docs/7.advanced/5.hooks.md b/docs/content/docs/7.advanced/5.hooks.md index d4aedea14..8ef89c815 100644 --- a/docs/content/docs/7.advanced/5.hooks.md +++ b/docs/content/docs/7.advanced/5.hooks.md @@ -23,7 +23,7 @@ export interface FileBeforeParseHook { ```ts export default defineNuxtConfig({ hooks: { - 'content:file:beforeParse'(ctx) { + 'content:file:beforeParse'(ctx: FileBeforeParseHook) { // ... } } From 9d6a45752c4d9b8d3b7d161b2b72e82e016c39e8 Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Tue, 24 Dec 2024 13:20:31 +1100 Subject: [PATCH 08/10] Update docs/content/docs/7.advanced/5.hooks.md Co-authored-by: Farnabaz --- docs/content/docs/7.advanced/5.hooks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/content/docs/7.advanced/5.hooks.md b/docs/content/docs/7.advanced/5.hooks.md index 8ef89c815..efa7de101 100644 --- a/docs/content/docs/7.advanced/5.hooks.md +++ b/docs/content/docs/7.advanced/5.hooks.md @@ -45,7 +45,7 @@ export interface FileAfterParseHook { ```ts export default defineNuxtConfig({ hooks: { - 'content:file:afterParse'(ctx) { + 'content:file:afterParse'(ctx: FileAfterParseHook) { // ... } } From 7c82ec143509fbee8afaffb68e26e8bc0291371a Mon Sep 17 00:00:00 2001 From: Harlan Wilton Date: Tue, 24 Dec 2024 13:22:28 +1100 Subject: [PATCH 09/10] Update src/utils/content/index.ts Co-authored-by: Farnabaz --- src/utils/content/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/content/index.ts b/src/utils/content/index.ts index 34e5749c0..1533c495f 100644 --- a/src/utils/content/index.ts +++ b/src/utils/content/index.ts @@ -143,7 +143,7 @@ export async function createParser(collection: ResolvedCollection, nuxt?: Nuxt) const result = { id } as typeof collection.extendedSchema._type const meta = {} as Record - const collectionKeys = Object.keys(hookedCollection.extendedSchema.shape) + const collectionKeys = Object.keys(collection.extendedSchema.shape) for (const key of Object.keys(parsedContentFields)) { if (collectionKeys.includes(key)) { result[key] = parsedContent[key] From 6d0c400ad9422107a07b060cdbc3f7df17839cd7 Mon Sep 17 00:00:00 2001 From: harlan Date: Tue, 24 Dec 2024 13:26:50 +1100 Subject: [PATCH 10/10] chore: tidy up --- docs/content/docs/7.advanced/5.hooks.md | 16 ++-------------- src/types/module.ts | 4 ++-- src/utils/content/index.ts | 2 +- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/docs/content/docs/7.advanced/5.hooks.md b/docs/content/docs/7.advanced/5.hooks.md index efa7de101..e224b8516 100644 --- a/docs/content/docs/7.advanced/5.hooks.md +++ b/docs/content/docs/7.advanced/5.hooks.md @@ -13,14 +13,8 @@ It can be used to modify the raw content from a `file` before it is transformed or modify the transform options. ```ts -export interface FileBeforeParseHook { - collection: ResolvedCollection - file: ContentFile - parserOptions: TransformContentOptions -} -``` +import type { FileBeforeParseHook } from '@nuxt/content' -```ts export default defineNuxtConfig({ hooks: { 'content:file:beforeParse'(ctx: FileBeforeParseHook) { @@ -35,14 +29,8 @@ export default defineNuxtConfig({ This hook is called after the content is parsed and before it is saved to the database. ```ts -export interface FileAfterParseHook { - collection: ResolvedCollection - file: ContentFile - content: ParsedContentFile -} -``` +import type { FileAfterParseHook } from '@nuxt/content' -```ts export default defineNuxtConfig({ hooks: { 'content:file:afterParse'(ctx: FileAfterParseHook) { diff --git a/src/types/module.ts b/src/types/module.ts index 9180c2127..cca32b10d 100644 --- a/src/types/module.ts +++ b/src/types/module.ts @@ -193,12 +193,12 @@ export interface PublicRuntimeConfig { export type ParsedContentFile = Record export interface FileBeforeParseHook { - collection: ResolvedCollection + collection: Readonly file: ContentFile parserOptions: TransformContentOptions } export interface FileAfterParseHook { - collection: ResolvedCollection + collection: Readonly file: ContentFile content: ParsedContentFile } diff --git a/src/utils/content/index.ts b/src/utils/content/index.ts index 1533c495f..7643840b6 100644 --- a/src/utils/content/index.ts +++ b/src/utils/content/index.ts @@ -136,7 +136,7 @@ export async function createParser(collection: ResolvedCollection, nuxt?: Nuxt) const beforeParseCtx: FileBeforeParseHook = { file, collection, parserOptions } // @ts-expect-error runtime type await nuxt?.callHook?.('content:file:beforeParse', beforeParseCtx) - const { file: hookedFile, collection: hookedCollection } = beforeParseCtx + const { file: hookedFile } = beforeParseCtx const parsedContent = await transformContent(hookedFile, beforeParseCtx.parserOptions) const { id: id, ...parsedContentFields } = parsedContent