Skip to content

Commit 5364d4f

Browse files
authored
Merge pull request #451 from stefanprobst/fix/frontmatter-body-field
fix: handle frontmatter `body` field in mdx
2 parents 6984b2b + eee50e8 commit 5364d4f

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

packages/@contentlayer/source-files/src/fetchData/mapping/field-mdx.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ import { getFromDocumentContext } from '../DocumentContext.js'
99

1010
export const makeMdxField = ({
1111
mdxString,
12-
fieldDef,
1312
options,
1413
contentDirPath,
14+
isDocumentBodyField,
1515
}: {
1616
mdxString: string
17-
fieldDef: core.FieldDef
1817
options: core.PluginOptions
1918
contentDirPath: AbsolutePosixFilePath
19+
isDocumentBodyField: boolean
2020
}): T.Effect<HasDocumentContext & OT.HasTracer, core.UnexpectedMDXError, core.MDX> =>
2121
T.gen(function* ($) {
22-
const isBodyField = fieldDef.name === options.fieldOptions.bodyFieldName
22+
// const isDocumentBodyField = fieldDef.name === options.fieldOptions.bodyFieldName
2323
const rawDocumentData = yield* $(getFromDocumentContext('rawDocumentData'))
2424
// NOTE for the body field, we're passing the entire document file contents to MDX (e.g. in case some remark/rehype plugins need access to the frontmatter)
2525
// TODO we should come up with a better way to do this
26-
if (isBodyField) {
26+
if (isDocumentBodyField) {
2727
const rawContent = yield* $(getFromDocumentContext('rawContent'))
2828
if (rawContent.kind !== 'mdx' && rawContent.kind !== 'markdown') return utils.assertNever(rawContent)
2929

packages/@contentlayer/source-files/src/fetchData/mapping/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ const getDataForFieldDef = ({
287287
}
288288
case 'mdx': {
289289
const mdxString = yield* $(parseFieldDataEff('mdx'))
290-
return yield* $(makeMdxField({ mdxString, contentDirPath, fieldDef, options }))
290+
const isDocumentBodyField = isRootDocument && fieldDef.name === options.fieldOptions.bodyFieldName
291+
return yield* $(makeMdxField({ mdxString, contentDirPath, options, isDocumentBodyField }))
291292
}
292293
case 'image':
293294
const imageData = yield* $(parseFieldDataEff('image'))
@@ -402,7 +403,7 @@ const getDataForListItem = ({
402403
}
403404
case 'mdx': {
404405
const mdxString = yield* $(parseFieldDataEff('mdx'))
405-
return yield* $(makeMdxField({ mdxString, contentDirPath, fieldDef, options }))
406+
return yield* $(makeMdxField({ mdxString, contentDirPath, options, isDocumentBodyField: false }))
406407
}
407408
case 'image':
408409
const imageData = yield* $(parseFieldDataEff('image'))

0 commit comments

Comments
 (0)