Skip to content

Commit f1a64ce

Browse files
committed
docs: update & improve /meta
1 parent 399160e commit f1a64ce

2 files changed

Lines changed: 57 additions & 13 deletions

File tree

docs/pages/markdown/+Page.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export default {
163163
eager: true,
164164
env: {
165165
server: true,
166-
// Instead of `client: true`, we use onCreateGlobalContext() with passToClient to
166+
// Instead of `client: true`, we use +onCreateGlobalContext with +passToClient to
167167
// be able to determine exactly what metadata is sent to the client-side.
168168
client: false
169169
}

docs/pages/meta/+Page.mdx

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ type Meta = {
1212
client?: boolean
1313
server?: boolean
1414
config?: boolean
15+
production?: boolean
1516
}
1617
cumulative?: boolean
17-
global?: boolean | ((value: unknown, info: { isGlobalLocation: boolean }) => boolean)
1818
eager?: boolean
19+
global?: boolean | ((value: unknown, info: { isGlobalLocation: boolean }) => boolean)
1920
effect?: ((config: { configValue: unknown configDefinedAt: string }) => Config | undefined)
21+
vite?: boolean
2022
isDefinedByPeerDependency?: true
2123
}
2224
```
@@ -26,12 +28,13 @@ type Meta = {
2628
The `meta` setting is an advanced feature. Instead of using `meta`, consider using <Link href="/file-env" noBreadcrumb={true} /> or <Link href="/extensions">Vike Extensions</Link> (they use `meta` on your behalf).
2729
</Advanced>
2830
29-
The `meta` settings enables you to create:
31+
The `meta` setting enables you to create:
3032
- **New settings**.
3133
- <Link href="#example-dataendpointurl" doNotInferSectionTitle />
3234
- <Link href="#example-sql" doNotInferSectionTitle />
3335
- <Link href="#example-title-and-description" doNotInferSectionTitle />
3436
- <Link href="#example-layout" doNotInferSectionTitle />
37+
- <Link href="#example-metadata" doNotInferSectionTitle />
3538
- **New hooks**.
3639
- Example: `+onInit` or `+onBeforeFetchingData`
3740
- **Modifying the environment of existing hooks**.
@@ -86,6 +89,7 @@ async function data(pageContext: PageContextServer) {
8689
}
8790
```
8891

92+
8993
## Example: `+sql`
9094

9195
Similarly to the previous example, another common use case is to enable pages to define their data requirements as SQL queries.
@@ -383,6 +387,33 @@ async function onRenderClient(pageContext: PageContextClient) {
383387
```
384388

385389

390+
## Example: `+metadata`
391+
392+
Another common use case is defining page metadata.
393+
394+
```ts
395+
// /pages/+config.ts
396+
397+
import type { Config } from 'vike/types'
398+
399+
export default {
400+
meta: {
401+
// Create +metadata setting
402+
metadata: {
403+
// Make +metadata available to all pages
404+
eager: true,
405+
env: {
406+
server: true,
407+
client: true
408+
}
409+
}
410+
}
411+
} satisfies Config
412+
```
413+
414+
See more examples at <Link href="/markdown#metadata" />.
415+
416+
386417
## Example: modify `+data` env
387418

388419
You can use `meta` to change the environment in which built-in hooks are loaded. For example, you can change the environment of the <Link href="/data">`data()` hook</Link> from `{ server: true, client: false }` to `{ server: true, client: true }`.
@@ -457,22 +488,31 @@ import type { Config } from 'vike/types'
457488

458489
export default {
459490
meta: {
460-
someSettingOrHook: {
461-
// [Required] Defines the environment in which the config value is loaded.
491+
someConfig: {
492+
// [Required] Defines the environment in which the config value is loaded
462493
env: {
463-
// Load the config value on the server. [Required]
494+
// [Required] Load config value on the server
464495
server: true,
465-
// Load the config value on the client. [Required]
496+
// [Required] Load config value on the client
466497
client: true,
467-
// Load the config value at config-time (when Vike loads +config.ts files). [Optional]
468-
config: false // default value
498+
// [Optional] Load config value at config-time (when Vike loads +config.ts files)
499+
config: false, // default value
500+
// [Optional] Load config value only in prod/dev (`true`/`false` => only prod/dev)
501+
production: undefined // default value
469502
},
470503

471-
// [Optional] Whether config values should be merged (instead of overridden).
504+
// [Optional] Whether config values should be merged (instead of overridden)
472505
cumulative: false, // default value
473506

474-
// [Optional] Function called when the config value is loaded at config-time.
475-
// Requires `env.config` to be `true`.
507+
// [Optional] Whether all config values should be loaded at initialization. This
508+
// means that all values of all pages are always available.
509+
eager: false, // default value
510+
511+
// [Optional] Whether the config value must be defined globally (not per-page)
512+
global: false, // default value
513+
514+
// [Optional] Function called when the config value is loaded at config-time. Note
515+
// that `effect()` requires `env.config` to be `true`.
476516
effect({ configDefinedAt, configValue }) {
477517
if (someCondition) {
478518
// This config object is merged with the current one.
@@ -485,7 +525,11 @@ export default {
485525
}
486526
}
487527
}
488-
}
528+
},
529+
530+
// [Optional] Whether the config value affects Vite's configuration and therefore
531+
// whether a change during dev (HMR) should trigger Vite to reload its config.
532+
vite: false // default value
489533
}
490534
}
491535
} satisfies Config

0 commit comments

Comments
 (0)