feat: content prop types for markdoc!
This commit is contained in:
parent
576b481adb
commit
8e3f4ca430
2 changed files with 36 additions and 13 deletions
|
@ -5,6 +5,11 @@ import { parseFrontmatter } from './utils.js';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
|
|
||||||
|
export default function markdoc(): AstroIntegration {
|
||||||
|
return {
|
||||||
|
name: '@astrojs/markdoc',
|
||||||
|
hooks: {
|
||||||
|
'astro:config:setup': async ({ updateConfig, config, addContentEntryType, command }: any) => {
|
||||||
const contentEntryType = {
|
const contentEntryType = {
|
||||||
extensions: ['.mdoc'],
|
extensions: ['.mdoc'],
|
||||||
async getEntryInfo({ fileUrl, contents }: { fileUrl: URL; contents: string }) {
|
async getEntryInfo({ fileUrl, contents }: { fileUrl: URL; contents: string }) {
|
||||||
|
@ -16,13 +21,11 @@ const contentEntryType = {
|
||||||
rawData: parsed.matter,
|
rawData: parsed.matter,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
contentModuleTypes: await fs.promises.readFile(
|
||||||
|
new URL('../template/content-module-types.d.ts', import.meta.url),
|
||||||
|
'utf-8'
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function markdoc(): AstroIntegration {
|
|
||||||
return {
|
|
||||||
name: '@astrojs/markdoc',
|
|
||||||
hooks: {
|
|
||||||
'astro:config:setup': async ({ updateConfig, config, addContentEntryType, command }: any) => {
|
|
||||||
addContentEntryType(contentEntryType);
|
addContentEntryType(contentEntryType);
|
||||||
|
|
||||||
const markdocConfigUrl = new URL('./markdoc.config', config.srcDir);
|
const markdocConfigUrl = new URL('./markdoc.config', config.srcDir);
|
||||||
|
|
20
packages/integrations/markdoc/template/content-module-types.d.ts
vendored
Normal file
20
packages/integrations/markdoc/template/content-module-types.d.ts
vendored
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
declare module 'astro:content' {
|
||||||
|
type ComponentRenderer =
|
||||||
|
| import('astro').ComponentInstance['default']
|
||||||
|
| {
|
||||||
|
component: import('astro').ComponentInstance['default'];
|
||||||
|
props?(params: {
|
||||||
|
attributes: Record<string, any>;
|
||||||
|
getTreeNode(): import('@markdoc/markdoc').Tag;
|
||||||
|
}): Record<string, any>;
|
||||||
|
};
|
||||||
|
|
||||||
|
interface Render {
|
||||||
|
'.mdoc': Promise<{
|
||||||
|
Content(props: {
|
||||||
|
config?: import('@markdoc/markdoc').Config;
|
||||||
|
components?: Record<string, ComponentRenderer>;
|
||||||
|
}): import('astro').MarkdownInstance<{}>['Content'];
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue