Skip to content

Commit f12a49f

Browse files
committed
document renderInnerPage and renderFullPage API
1 parent 5134ccc commit f12a49f

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,27 @@ const feedsTemplate: TemplateAsyncIterator<TemplateVars> = async function * ({
951951
export default feedsTemplate
952952
```
953953

954+
### Accessing rendered page content
955+
956+
Any `PageData` instance exposes two methods for accessing rendered output:
957+
958+
- `await page.renderInnerPage({ pages })` returns the page content as rendered by its builder (markdown converted to HTML, for example) without a layout wrapper applied.
959+
- `await page.renderFullPage({ pages })` returns the complete page output with its layout applied.
960+
961+
Both methods are async and require the full `pages` array. They are available inside templates and in `global.data.js`. They are not available inside page functions or layouts.
962+
963+
For templates that render many pages, pre-render in parallel and cache results to avoid doing the same work twice when producing several output files from one template:
964+
965+
```js
966+
const renderCache = new Map()
967+
await Promise.all(allPosts.map(async (page) => {
968+
renderCache.set(page.pageInfo.path, await page.renderInnerPage({ pages }))
969+
}))
970+
971+
// later, when building output:
972+
const html = renderCache.get(post.path) ?? ''
973+
```
974+
954975
## Global Assets
955976
956977
There are a few important (and optional) global assets that live anywhere in the `src` directory. If duplicate named files that match the global asset file name pattern are found, a build error will occur until the duplicate file error is resolved.

0 commit comments

Comments
 (0)