diff options
Diffstat (limited to 'packages/integrations/markdoc/src/index.ts')
-rw-r--r-- | packages/integrations/markdoc/src/index.ts | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/packages/integrations/markdoc/src/index.ts b/packages/integrations/markdoc/src/index.ts index 0486a44b5..ef50768fe 100644 --- a/packages/integrations/markdoc/src/index.ts +++ b/packages/integrations/markdoc/src/index.ts @@ -11,6 +11,7 @@ import { bold, red, yellow } from 'kleur/colors'; import type * as rollup from 'rollup'; import { loadMarkdocConfig, type MarkdocConfigResult } from './load-config.js'; import { setupConfig } from './runtime.js'; +import path from 'node:path'; type SetupHookParams = HookParameters<'astro:config:setup'> & { // `contentEntryType` is not a public API @@ -61,10 +62,13 @@ export default function markdocIntegration(legacyConfig?: any): AstroIntegration addContentEntryType({ extensions: ['.mdoc'], getEntryInfo, - async getRenderModule({ entry, viteId }) { + async getRenderModule({ contents, fileUrl, viteId }) { + const entry = getEntryInfo({ contents, fileUrl }); const ast = Markdoc.parse(entry.body); const pluginContext = this; - const markdocConfig = await setupConfig(userMarkdocConfig, entry); + const markdocConfig = await setupConfig(userMarkdocConfig); + + const filePath = fileURLToPath(fileUrl); const validationErrors = Markdoc.validate(ast, markdocConfig).filter((e) => { return ( @@ -77,10 +81,11 @@ export default function markdocIntegration(legacyConfig?: any): AstroIntegration }); if (validationErrors.length) { // Heuristic: take number of newlines for `rawData` and add 2 for the `---` fences - const frontmatterBlockOffset = entry._internal.rawData.split('\n').length + 2; + const frontmatterBlockOffset = entry.rawData.split('\n').length + 2; + const rootRelativePath = path.relative(fileURLToPath(astroConfig.root), filePath); throw new MarkdocError({ message: [ - `**${String(entry.collection)} → ${String(entry.id)}** contains invalid content:`, + `**${String(rootRelativePath)}** contains invalid content:`, ...validationErrors.map((e) => `- ${e.error.message}`), ].join('\n'), location: { @@ -96,7 +101,7 @@ export default function markdocIntegration(legacyConfig?: any): AstroIntegration await emitOptimizedImages(ast.children, { astroConfig, pluginContext, - filePath: entry._internal.filePath, + filePath, }); } |