diff options
author | 2023-05-30 16:18:20 -0400 | |
---|---|---|
committer | 2023-05-30 16:18:20 -0400 | |
commit | bef3a75dbc48d584daff9f7f3d5a8937b0356170 (patch) | |
tree | 536921af91ee7864192369e39be6f99eed134741 /packages/integrations/markdoc/src/index.ts | |
parent | c7897f20a9d6e04f9cdee9a0f7e48e59adf1e59a (diff) | |
download | astro-bef3a75dbc48d584daff9f7f3d5a8937b0356170.tar.gz astro-bef3a75dbc48d584daff9f7f3d5a8937b0356170.tar.zst astro-bef3a75dbc48d584daff9f7f3d5a8937b0356170.zip |
Markdoc - remove `$entry` variable (#7244)
* refactor: remove entry prop from `getRenderModule()`
* refactor: remove `$entry` from markdoc
* test: update entry-prop -> variables test
* refactor: unify `getEntryConfigByExt`
* chore: clean up shared content / data get logic
* docs: update `$entry` recommendation
* chore: rename entry-prop -> variables
* chore: changeset
* chore: missed a spot
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, }); } |