Skip to content

Commit dfd8a16

Browse files
committed
Fix three global.data caveats doc issues
- Cache p.vars in try/catch example to avoid double-invoking the getter - Broaden the .vars throw caveat to cover all init failures, not just vars module errors - Correct the raw content caveat: markdown pages do not expose content via vars.content; point to pageFile.filepath for raw source and renderInnerPage() for rendered HTML
1 parent e8390da commit dfd8a16

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,19 +1069,20 @@ const date = page.vars.date
10691069

10701070
For large sites with hundreds of pages, caching the result once per page reduces build time noticeably.
10711071

1072-
**`page.vars` can throw.** If a page vars module has a syntax error, a missing dependency, or a runtime error, accessing `.vars` will throw. Wrap accesses in `try/catch` when iterating all pages so one broken page does not abort the whole function:
1072+
**`page.vars` can throw.** If a page failed to initialize (often due to page vars module syntax errors, missing dependencies, or runtime errors), accessing `.vars` will throw. Wrap accesses in `try/catch` when iterating all pages so one broken page does not abort the whole function:
10731073

10741074
```js
10751075
const posts = pages.filter(p => {
10761076
try {
1077-
return p.vars.layout === 'article' && p.vars.date
1077+
const vars = p.vars
1078+
return vars.layout === 'article' && vars.date
10781079
} catch {
10791080
return false
10801081
}
10811082
})
10821083
```
10831084

1084-
**`page.vars.content` is raw source, not rendered HTML.** For markdown pages, `vars.content` is the raw markdown string read from the file. To get rendered HTML, call `page.renderInnerPage({ pages })`.
1085+
**Raw markdown source is not exposed as `page.vars.content` by default.** For markdown pages, `page.vars` contains front matter-derived values such as `title`, but does not automatically include the raw markdown body as `content`. If you need the raw source, read it from `page.pageInfo.pageFile.filepath`. To get rendered HTML, call `page.renderInnerPage({ pages })`.
10851086

10861087
**`renderInnerPage()` is available.** `global.data.js` receives fully initialized `PageData` instances, so you can call `renderInnerPage()` here. See [Accessing rendered page content](#accessing-rendered-page-content) for usage and performance guidance.
10871088

0 commit comments

Comments
 (0)