feat(markdown): Improved types (#3191)

* feat(markdown): Improved types

* More MarkdownMetadata
This commit is contained in:
Juan Martín Seery 2022-04-24 20:13:33 -03:00 committed by GitHub
parent 205c499a3e
commit 205d1f07f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 6 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Added better types to importing Markdown

View file

@ -11,3 +11,16 @@ type Astro = import('astro').AstroGlobal;
declare const Astro: Readonly<Astro>;
declare const Fragment: any;
declare module '*.md' {
type MD = import('astro').MarkdownInstance<Record<string, any>>;
export const frontmatter: MD['frontmatter'];
export const file: MD['file'];
export const url: MD['url'];
export const getHeaders: MD['getHeaders'];
export const Content: MD['Content'];
const load: MD['default'];
export default load;
}

View file

@ -725,7 +725,13 @@ export interface MarkdownInstance<T extends Record<string, any>> {
file: string;
url: string | undefined;
Content: AstroComponentFactory;
getHeaders(): Promise<{ depth: number; slug: string; text: string }[]>;
getHeaders(): Promise<MarkdownHeader[]>;
default: () => Promise<{
metadata: MarkdownMetadata;
frontmatter: MarkdownContent;
$$metadata: Metadata;
default: AstroComponentFactory;
}>;
}
export type GetHydrateCallback = () => Promise<
@ -767,18 +773,35 @@ export interface ManifestData {
routes: RouteData[];
}
export interface MarkdownHeader {
depth: number;
slug: string;
text: string;
}
export interface MarkdownMetadata {
headers: MarkdownHeader[];
source: string;
html: string;
}
export interface MarkdownParserResponse {
frontmatter: {
[key: string]: any;
};
metadata: {
headers: any[];
source: string;
html: string;
};
metadata: MarkdownMetadata;
code: string;
}
/**
* The `content` prop given to a Layout
* https://docs.astro.build/guides/markdown-content/#markdown-layouts
*/
export interface MarkdownContent {
[key: string]: any;
astro: MarkdownMetadata;
}
/**
* paginate() Options
* Docs: https://docs.astro.build/guides/pagination/#calling-the-paginate-function