Skip to content
Open
Changes from 2 commits
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
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,29 @@ 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, in `global.data.js`, inside page functions, and inside layouts.
Comment thread
bcomnes marked this conversation as resolved.

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
import pMap from 'p-map'

const renderCache = new Map()
await pMap(allPosts, async (page) => {
renderCache.set(page.pageInfo.path, await page.renderInnerPage({ pages }))
}, { concurrency: 4 })

// later, when building output:
const html = renderCache.get(page.pageInfo.path) ?? ''
```

## 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