feat(markdown): Improved types (#3191)
* feat(markdown): Improved types * More MarkdownMetadata
This commit is contained in:
parent
205c499a3e
commit
205d1f07f1
3 changed files with 47 additions and 6 deletions
5
.changeset/cool-experts-shake.md
Normal file
5
.changeset/cool-experts-shake.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Added better types to importing Markdown
|
13
packages/astro/env.d.ts
vendored
13
packages/astro/env.d.ts
vendored
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue