feat: layout section

This commit is contained in:
Andrey Yolkin 2023-08-30 00:23:48 +03:00
parent fd8507df93
commit c1db6321a8

View File

@ -1490,6 +1490,75 @@ export default defineNuxtModule({
::
## Layout
[source code](https://github.com/nuxt/nuxt/blob/main/packages/kit/src/layout.ts)
### `addLayout`
Register template as layout and add it to the layouts array.
#### Type
```ts
function addLayout (layout: NuxtTemplate, name: string): void
interface NuxtTemplate {
src?: string
filename?: string
dst?: string
options?: Record<string, any>
getContents?: (data: Record<string, any>) => string | Promise<string>
write?: boolean
}
```
#### Parameters
##### `layout`
**Type**: `NuxtTemplate`
**Required**: `true`
A template object with the following properties:
- `src` (optional)
**Type**: `string`
Path to the template. If `src` is not provided, `getContents` must be provided instead.
- `filename` (optional)
**Type**: `string`
Filename of the template. If `filename` is not provided, it will be generated from the `src` path. In this case, the `src` option is required.
- `dst` (optional)
**Type**: `string`
Path to the destination file. If `dst` is not provided, it will be generated from the `filename` path and nuxt `buildDir` option.
- `options` (optional)
**Type**: `Options`
Options to pass to the template.
- `getContents` (optional)
**Type**: `(data: Options) => string | Promise<string>`
A function that will be called with the `options` object. It should return a string or a promise that resolves to a string. If `src` is provided, this function will be ignored.
- `write` (optional)
**Type**: `boolean`
If set to `true`, the template will be written to the destination file. Otherwise, the template will be used only in virtual filesystem.
## Plugins
[source code](https://github.com/nuxt/nuxt/blob/main/packages/kit/src/plugin.ts)