fix: markdoc.config loading
This commit is contained in:
parent
2decb70344
commit
37426a10bc
1 changed files with 6 additions and 4 deletions
|
@ -24,7 +24,7 @@ export default function markdoc(partialOptions: {} = {}): AstroIntegration {
|
||||||
'astro:config:setup': async ({ updateConfig, config, addContentEntryType, command }: any) => {
|
'astro:config:setup': async ({ updateConfig, config, addContentEntryType, command }: any) => {
|
||||||
addContentEntryType(contentEntryType);
|
addContentEntryType(contentEntryType);
|
||||||
console.log('Markdoc working!');
|
console.log('Markdoc working!');
|
||||||
const markdocConfigUrl = new URL('./markdoc.config.ts', config.srcDir);
|
const markdocConfigUrl = new URL('./markdoc.config', config.srcDir);
|
||||||
|
|
||||||
const viteConfig: InlineConfig = {
|
const viteConfig: InlineConfig = {
|
||||||
plugins: [
|
plugins: [
|
||||||
|
@ -35,13 +35,15 @@ export default function markdoc(partialOptions: {} = {}): AstroIntegration {
|
||||||
return `import { jsx as h } from 'astro/jsx-runtime';\nimport { Markdoc } from '@astrojs/markdoc';\nimport { Renderer } from '@astrojs/markdoc/components';\nexport const body = ${JSON.stringify(
|
return `import { jsx as h } from 'astro/jsx-runtime';\nimport { Markdoc } from '@astrojs/markdoc';\nimport { Renderer } from '@astrojs/markdoc/components';\nexport const body = ${JSON.stringify(
|
||||||
code
|
code
|
||||||
)};\nexport function getParsed() { return Markdoc.parse(body); }\nexport async function getTransformed(inlineConfig) {
|
)};\nexport function getParsed() { return Markdoc.parse(body); }\nexport async function getTransformed(inlineConfig) {
|
||||||
let config = inlineConfig ?? {};
|
let config = inlineConfig;
|
||||||
if (!config) {
|
if (!config) {
|
||||||
try {
|
try {
|
||||||
const importedConfig = await import(${JSON.stringify(markdocConfigUrl.pathname)});
|
const importedConfig = await import(${JSON.stringify(markdocConfigUrl.pathname)});
|
||||||
console.log({ importedConfig })
|
console.log({importedConfig})
|
||||||
config = importedConfig.default.transform;
|
config = importedConfig.default.transform;
|
||||||
} catch {}
|
} catch {
|
||||||
|
config = {};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Markdoc.transform(getParsed(), config) }\nexport async function Content ({ transformConfig, components }) { return h(Renderer, { content: await getTransformed(transformConfig), components }); }\nContent[Symbol.for('astro.needsHeadRendering')] = true;`;
|
return Markdoc.transform(getParsed(), config) }\nexport async function Content ({ transformConfig, components }) { return h(Renderer, { content: await getTransformed(transformConfig), components }); }\nContent[Symbol.for('astro.needsHeadRendering')] = true;`;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue