useContentHead()
Configuring your <head>
tag from your content has never been easier!
useContentHead()
is a composable providing a binding between your content data and useHead
.
It is already implemented for you in both <ContentDoc />
component and the default documentDriven
page.
Parameters
These parameters can be used from the Front-Matter section of your pages.
Key | Type | Default | Description |
---|---|---|---|
head | Object | A useHead compatible object | |
title | String | Will be used as the default value for head.title | |
head.title | String | Parsed title | Sets the <title> tag |
description | String | Will be used as the default value for head.description | |
head.description | String | Parsed description | Sets the <meta name="description"> tag |
image | String | Object | Will be used as the default value for head.image | |
image.src | String | The source of the image | |
image.alt | String | The alt description of the image | |
image.xxx | String | Any og:image:xxx compatible attribute | |
head.image | String | Object | Overrides the <meta property="og:image"> |
At the exception of title
, description
and image
, the head
object behaves exactly the same in Front-Matter as it would in useHead({ ... })
composable.
You can specify any value that is writeable in yaml
format.
example-usage.md
---title: 'My Page Title'description: 'What a lovely page.'image: src: '/assets/image.jpg' alt: 'An image showcasing My Page.' width: 400 height: 300head: meta: - name: 'keywords' content: 'nuxt, vue, content' - name: 'robots' content: 'index, follow' - name: 'author' content: 'NuxtLabs' - name: 'copyright' content: '© 2022 NuxtLabs'---
Usage
useContentHead()
is available everywhere in your app where useHead
would be.
It takes two arguments:
document
: A document data (of any type)to
: A route path- Default:
useRoute()
- Default:
with documentDriven
<script setup lang="ts">const { page } = useContent()useContentHead(page)</script>
Table of Contents