aboutsummaryrefslogtreecommitdiff
path: root/packages/integrations/markdoc/src/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/markdoc/src/index.ts')
-rw-r--r--packages/integrations/markdoc/src/index.ts49
1 files changed, 49 insertions, 0 deletions
diff --git a/packages/integrations/markdoc/src/index.ts b/packages/integrations/markdoc/src/index.ts
new file mode 100644
index 000000000..d328d4a8d
--- /dev/null
+++ b/packages/integrations/markdoc/src/index.ts
@@ -0,0 +1,49 @@
+import type { AstroConfig, AstroIntegration, ContentEntryType, HookParameters } from 'astro';
+import { getContentEntryType } from './content-entry-type.js';
+import {
+ type MarkdocConfigResult,
+ SUPPORTED_MARKDOC_CONFIG_FILES,
+ loadMarkdocConfig,
+} from './load-config.js';
+import type { MarkdocIntegrationOptions } from './options.js';
+
+type SetupHookParams = HookParameters<'astro:config:setup'> & {
+ // `contentEntryType` is not a public API
+ // Add type defs here
+ addContentEntryType: (contentEntryType: ContentEntryType) => void;
+};
+
+export default function markdocIntegration(options?: MarkdocIntegrationOptions): AstroIntegration {
+ let markdocConfigResult: MarkdocConfigResult | undefined;
+ let astroConfig: AstroConfig;
+ return {
+ name: '@astrojs/markdoc',
+ hooks: {
+ 'astro:config:setup': async (params) => {
+ const { updateConfig, addContentEntryType } = params as SetupHookParams;
+ astroConfig = params.config;
+
+ markdocConfigResult = await loadMarkdocConfig(astroConfig);
+
+ addContentEntryType(
+ await getContentEntryType({ markdocConfigResult, astroConfig, options }),
+ );
+
+ updateConfig({
+ vite: {
+ ssr: {
+ external: ['@astrojs/markdoc/prism', '@astrojs/markdoc/shiki'],
+ },
+ },
+ });
+ },
+ 'astro:server:setup': async ({ server }) => {
+ server.watcher.on('all', (_event, entry) => {
+ if (SUPPORTED_MARKDOC_CONFIG_FILES.some((f) => entry.endsWith(f))) {
+ server.restart();
+ }
+ });
+ },
+ },
+ };
+}