feat: get markdoc contents

This commit is contained in:
bholmesdev 2023-02-06 11:21:17 -05:00
parent 1d8c73d2c5
commit e2b4f95dfd

View file

@ -1,4 +1,5 @@
import type { AstroIntegration } from 'astro'; import type { AstroIntegration } from 'astro';
import type { InlineConfig } from 'vite';
export default function markdoc(partialOptions: {} = {}): AstroIntegration { export default function markdoc(partialOptions: {} = {}): AstroIntegration {
return { return {
@ -7,6 +8,19 @@ export default function markdoc(partialOptions: {} = {}): AstroIntegration {
'astro:config:setup': async ({ updateConfig, config, addPageExtension, command }: any) => { 'astro:config:setup': async ({ updateConfig, config, addPageExtension, command }: any) => {
addPageExtension('.mdoc'); addPageExtension('.mdoc');
console.log('Markdoc working!'); console.log('Markdoc working!');
const viteConfig: InlineConfig = {
plugins: [
{
name: '@astrojs/markdoc',
async transform(code, id) {
if (!id.endsWith('.mdoc')) return;
return `export const body = ${JSON.stringify(code)}`;
},
},
],
};
updateConfig({ vite: viteConfig });
}, },
}, },
}; };