Skip to content

Commit 49b3ef0

Browse files
committed
Fix renderInnerPage availability note, cache key inconsistency, add pMap concurrency
- Availability: renderInnerPage/renderFullPage are also callable from page functions and layouts, not just templates and global.data.js - Cache key: use page.pageInfo.path consistently (the read side previously used the undefined 'post.path') - Concurrency: switch the pre-render example from Promise.all to pMap with concurrency:4 to avoid unbounded parallelism on large sites
1 parent f12a49f commit 49b3ef0

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -958,18 +958,20 @@ Any `PageData` instance exposes two methods for accessing rendered output:
958958
- `await page.renderInnerPage({ pages })` returns the page content as rendered by its builder (markdown converted to HTML, for example) without a layout wrapper applied.
959959
- `await page.renderFullPage({ pages })` returns the complete page output with its layout applied.
960960

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.
961+
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.
962962

963963
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:
964964

965965
```js
966+
import pMap from 'p-map'
967+
966968
const renderCache = new Map()
967-
await Promise.all(allPosts.map(async (page) => {
969+
await pMap(allPosts, async (page) => {
968970
renderCache.set(page.pageInfo.path, await page.renderInnerPage({ pages }))
969-
}))
971+
}, { concurrency: 4 })
970972

971973
// later, when building output:
972-
const html = renderCache.get(post.path) ?? ''
974+
const html = renderCache.get(page.pageInfo.path) ?? ''
973975
```
974976
975977
## Global Assets

0 commit comments

Comments
 (0)