mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
feat: expose frontmatter on (undocumented) routes key
This commit is contained in:
parent
c8f5fa35c4
commit
ece5feef02
3 changed files with 18 additions and 9 deletions
|
@ -719,6 +719,8 @@ export interface ComponentInstance {
|
||||||
default: AstroComponentFactory;
|
default: AstroComponentFactory;
|
||||||
css?: string[];
|
css?: string[];
|
||||||
getStaticPaths?: (options: GetStaticPathsOptions) => GetStaticPathsResult;
|
getStaticPaths?: (options: GetStaticPathsOptions) => GetStaticPathsResult;
|
||||||
|
// supplied by .md files
|
||||||
|
frontmatter?: Record<string, any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MarkdownInstance<T extends Record<string, any>> {
|
export interface MarkdownInstance<T extends Record<string, any>> {
|
||||||
|
|
|
@ -123,13 +123,10 @@ class AstroBuilder {
|
||||||
|
|
||||||
// Filter pages by using conditions based on their frontmatter.
|
// Filter pages by using conditions based on their frontmatter.
|
||||||
Object.entries(allPages).forEach(([page, data]) => {
|
Object.entries(allPages).forEach(([page, data]) => {
|
||||||
if ('frontmatter' in data.preload[1]) {
|
const [, componentData] = data.preload;
|
||||||
// TODO: add better type inference to data.preload[1]
|
if (Boolean(componentData.frontmatter?.draft) && !this.config.markdown.drafts) {
|
||||||
const frontmatter = (data.preload[1] as any).frontmatter;
|
debug('build', timerMessage(`Skipping draft page ${page}`, this.timer.loadStart));
|
||||||
if (Boolean(frontmatter.draft) && !this.config.markdown.drafts) {
|
delete allPages[page];
|
||||||
debug('build', timerMessage(`Skipping draft page ${page}`, this.timer.loadStart));
|
|
||||||
delete allPages[page];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -176,7 +173,17 @@ class AstroBuilder {
|
||||||
config: this.config,
|
config: this.config,
|
||||||
buildConfig,
|
buildConfig,
|
||||||
pages: pageNames,
|
pages: pageNames,
|
||||||
routes: Object.values(allPages).map((pd) => pd.route),
|
routes: Object.values(allPages).map((pageData) => {
|
||||||
|
const {
|
||||||
|
route,
|
||||||
|
preload: [, componentData],
|
||||||
|
} = pageData;
|
||||||
|
if (componentData.frontmatter) {
|
||||||
|
return { ...route, frontmatter: componentData.frontmatter };
|
||||||
|
} else {
|
||||||
|
return route;
|
||||||
|
}
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.logging.level && levels[this.logging.level] <= levels['info']) {
|
if (this.logging.level && levels[this.logging.level] <= levels['info']) {
|
||||||
|
|
|
@ -144,7 +144,7 @@ export async function runHookBuildDone({
|
||||||
config: AstroConfig;
|
config: AstroConfig;
|
||||||
buildConfig: BuildConfig;
|
buildConfig: BuildConfig;
|
||||||
pages: string[];
|
pages: string[];
|
||||||
routes: RouteData[];
|
routes: RouteData[] & { frontmatter?: Record<string, any> };
|
||||||
}) {
|
}) {
|
||||||
const dir = isBuildingToSSR(config) ? buildConfig.client : config.outDir;
|
const dir = isBuildingToSSR(config) ? buildConfig.client : config.outDir;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue