@@ -19,8 +19,10 @@ import pretty from 'pretty'
1919 * @async
2020 * @function
2121 * @template T - The type of variables for the layout
22+ * @template [U=any] U - The return type of the page function (defaults to any)
23+ * @template [V=string] V - The return type of the layout function (defaults to string)
2224 * @param {string } layoutPath - The string path to the layout ESM module.
23- * @returns {Promise<LayoutFunction<T>> } The resolved layout exported as default from the module.
25+ * @returns {Promise<LayoutFunction<T, U, V >> } The resolved layout exported as default from the module.
2426 */
2527export async function resolveLayout ( layoutPath ) {
2628 const { default : layout } = await import ( layoutPath )
@@ -32,41 +34,47 @@ export async function resolveLayout (layoutPath) {
3234 * Callback for rendering a layout.
3335 *
3436 * @template T - The type of variables passed to the layout function
37+ * @template [U=any] U - The return type of the page function (defaults to any)
38+ * @template [V=string] V - The return type of the layout function (defaults to string)
3539 * @callback LayoutFunction
3640 * @param {object } params - The parameters for the layout.
3741 * @param {T } params.vars - All default, global, layout, page, and builder vars shallow merged.
3842 * @param {string[] } [params.scripts] - Array of script URLs to include.
3943 * @param {string[] } [params.styles] - Array of stylesheet URLs to include.
4044 * @param {any } params.children - The children content, either as a string or a render function.
4145 * @param {PageInfo } params.page - Info about the current page
42- * @param {PageData<T>[] } params.pages - An array of info about every page
46+ * @param {PageData<T, U, V >[] } params.pages - An array of info about every page
4347 * @param {Object<string, string> } [params.workers] - Map of worker names to their output paths
44- * @returns {Promise<string > | string } The rendered HTML string .
48+ * @returns {Promise<V > | V } The rendered content .
4549 */
4650
4751/**
4852 * postVars functions Can be used to generate page vars but access all page data
4953 *
5054 * @async
5155 * @template {Record<string, any>} T - The type of variables for the page
56+ * @template [U=any] U - The return type of the page function (defaults to any)
57+ * @template [V=string] V - The return type of the layout function (defaults to string)
5258 * @callback PostVarsFunction
5359 * @param {object } params - The parameters for the pageLayout.
5460 * @param {T } params.vars - All default, global, layout, page, and builder vars shallow merged.
5561 * @param {string[] } [params.scripts] - Array of script URLs to include.
5662 * @param {string[] } [params.styles] - Array of stylesheet URLs to include.
5763 * @param {PageInfo } params.page - Info about the current page
58- * @param {PageData<T>[] } params.pages - An array of info about every page
64+ * @param {PageData<T, U, V >[] } params.pages - An array of info about every page
5965 * @param {Object<string, string> } [params.workers] - Map of worker names to their output paths
6066 * @returns {Promise<T> } The rendered postVars
6167 */
6268
6369/**
6470 * Represents the data for a page.
6571 * @template {Record<string, any>} T - The type of variables for the page data
72+ * @template [U=any] U - The return type of the page function (defaults to any)
73+ * @template [V=string] V - The return type of the layout function (defaults to string)
6674 */
6775export class PageData {
6876 /** @type {PageInfo } */ pageInfo
69- /** @type {ResolvedLayout<T> | null | undefined } */ layout
77+ /** @type {ResolvedLayout<T, U, V > | null | undefined } */ layout
7078 /** @type {object } */ globalVars
7179 /** @type {object? } */ pageVars = null
7280 /** @type {function? } */ postVars = null
@@ -139,7 +147,7 @@ export class PageData {
139147 }
140148
141149 /**
142- * @type {PostVarsFunction<T> }
150+ * @type {PostVarsFunction<T, U, V > }
143151 */
144152 async #renderPostVars ( { vars, styles, scripts, pages, page, workers } ) {
145153 if ( ! this . #initialized) throw new Error ( 'Initialize PageData before accessing renderPostVars' )
@@ -163,7 +171,7 @@ export class PageData {
163171 /**
164172 * [init description]
165173 * @param {object } params - Parameters required to initialize
166- * @param {Record<string,ResolvedLayout<T>> } params.layouts - The array of ResolvedLayouts
174+ * @param {Record<string,ResolvedLayout<T, U, V >> } params.layouts - The array of ResolvedLayouts
167175 */
168176 async init ( { layouts } ) {
169177 if ( this . #initialized) return
@@ -232,7 +240,7 @@ export class PageData {
232240 /**
233241 * Render the inner contents of a page.
234242 * @param {object } params The params required to render the page
235- * @param {PageData<T>[] } params.pages An array of initialized PageDatas.
243+ * @param {PageData<T, U, V >[] } params.pages An array of initialized PageDatas.
236244 */
237245 async renderInnerPage ( { pages } ) {
238246 if ( ! this . #initialized) throw new Error ( 'Must be initialized before rendering inner pages' )
@@ -248,7 +256,7 @@ export class PageData {
248256 /**
249257 * Render the full contents of a page with its layout
250258 * @param {object } params The params required to render the page
251- * @param {PageData<T>[] } params.pages An array of initialized PageDatas.
259+ * @param {PageData<T, U, V >[] } params.pages An array of initialized PageDatas.
252260 */
253261 async renderFullPage ( { pages } ) {
254262 if ( ! this . #initialized) throw new Error ( 'Must be initialized before rendering full pages' )
0 commit comments