@@ -107,6 +107,32 @@ import { createTempContext } from "../core/temp.ts";
107107
108108import { onCleanup } from "../core/cleanup.ts" ;
109109import { once } from "../core/once.ts" ;
110+ import { Zod } from "../resources/types/zod/schema-types.ts" ;
111+
112+ const mergeExtensionMetadata = async (
113+ context : ProjectContext ,
114+ pOptions : RenderOptions ,
115+ ) => {
116+ // this will mutate context.config.project to merge
117+ // in any project metadata from extensions
118+ if ( context . config ) {
119+ const extensions = await pOptions . services . extension . extensions (
120+ undefined ,
121+ context . config ,
122+ context . isSingleFile ? undefined : context . dir ,
123+ { builtIn : false } ,
124+ ) ;
125+ const projectMetadata = extensions . filter ( ( extension ) =>
126+ extension . contributes . metadata ?. project
127+ ) . map ( ( extension ) => {
128+ return Zod . ProjectConfig . parse ( extension . contributes . metadata ! . project ) ;
129+ } ) ;
130+ context . config . project = mergeProjectMetadata (
131+ context . config . project ,
132+ ...projectMetadata ,
133+ ) ;
134+ }
135+ } ;
110136
111137export async function projectContext (
112138 path : string ,
@@ -145,6 +171,16 @@ export async function projectContext(
145171 }
146172 } ;
147173
174+ const returnResult = async (
175+ context : ProjectContext ,
176+ ) => {
177+ if ( renderOptions ) {
178+ await mergeExtensionMetadata ( context , renderOptions ) ;
179+ }
180+ onCleanup ( context . cleanup ) ;
181+ return context ;
182+ } ;
183+
148184 while ( true ) {
149185 // use the current resolver
150186 const resolver = configResolvers [ 0 ] ;
@@ -362,8 +398,7 @@ export async function projectContext(
362398 config : configFiles ,
363399 configResources : projectConfigResources ( dir , projectConfig , type ) ,
364400 } ;
365- onCleanup ( result . cleanup ) ;
366- return result ;
401+ return await returnResult ( result ) ;
367402 } else {
368403 debug ( `projectContext: Found Quarto project in ${ dir } ` ) ;
369404 const temp = createTempContext ( {
@@ -431,8 +466,7 @@ export async function projectContext(
431466 config : configFiles ,
432467 configResources : projectConfigResources ( dir , projectConfig ) ,
433468 } ;
434- onCleanup ( result . cleanup ) ;
435- return result ;
469+ return await returnResult ( result ) ;
436470 }
437471 } else {
438472 const nextDir = dirname ( dir ) ;
@@ -511,8 +545,7 @@ export async function projectContext(
511545 context . files . input = [ input ] ;
512546 }
513547 debug ( `projectContext: Found Quarto project in ${ originalDir } ` ) ;
514- onCleanup ( context . cleanup ) ;
515- return context ;
548+ return await returnResult ( context ) ;
516549 } else {
517550 return undefined ;
518551 }
0 commit comments