Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,27 @@ const feedsTemplate: TemplateAsyncIterator<TemplateVars> = async function * ({
export default feedsTemplate
```

### Accessing rendered page content

Any `PageData` instance exposes two methods for accessing rendered output:

- `await page.renderInnerPage({ pages })` returns the page content as rendered by its builder (markdown converted to HTML, for example) without a layout wrapper applied.
Comment thread
bcomnes marked this conversation as resolved.
Outdated
- `await page.renderFullPage({ pages })` returns the complete page output with its layout applied.

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.
Comment thread
bcomnes marked this conversation as resolved.
Outdated

Comment thread
bcomnes marked this conversation as resolved.
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:

```js
const renderCache = new Map()
await Promise.all(allPosts.map(async (page) => {
renderCache.set(page.pageInfo.path, await page.renderInnerPage({ pages }))
}))
Comment thread
bcomnes marked this conversation as resolved.
Outdated

// later, when building output:
const html = renderCache.get(post.path) ?? ''
Comment thread
bcomnes marked this conversation as resolved.
Outdated
```

## Global Assets

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.
Expand Down
Loading