astro/packages/integrations/markdoc/src/index.ts
2023-02-14 09:28:09 -05:00

27 lines
707 B
TypeScript

import type { AstroIntegration } from 'astro';
import type { InlineConfig } from 'vite';
export default function markdoc(partialOptions: {} = {}): AstroIntegration {
return {
name: '@astrojs/markdoc',
hooks: {
'astro:config:setup': async ({ updateConfig, config, addPageExtension, command }: any) => {
addPageExtension('.mdoc');
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 });
},
},
};
}