Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: update seo and meta page #19697

Merged
merged 2 commits into from Mar 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 22 additions & 15 deletions docs/1.getting-started/5.seo-meta.md
Expand Up @@ -82,23 +82,21 @@ useServerSeoMeta({

**Reactive example:**

When inserting tags that are reactive, for example, from an API request, you should use the computed getter syntax, the same as `useHead`.
When inserting tags that are reactive, you should use the computed getter syntax (`() => value`):

```vue [app.vue]
<script setup lang="ts">
const { data } = useFetch('/api/example')
const title = ref('My title')

useServerSeoMeta({
ogTitle: () => `${data.value?.title} - My Site`,
description: () => data.value?.description,
ogDescription: () => data.value?.description,
useSeoMeta({
title,
description: () => `description: ${title.value}`
})
</script>
```

Read more on the [`useSeoMeta`](https://unhead.harlanzw.com/guide/composables/use-seo-meta) composable.


## Components

Nuxt provides `<Title>`, `<Base>`, `<NoScript>`, `<Style>`, `<Meta>`, `<Link>`, `<Body>`, `<Html>` and `<Head>` components so that you can interact directly with your metadata within your component's template.
Expand Down Expand Up @@ -153,32 +151,42 @@ See [@unhead/schema](https://github.com/unjs/unhead/blob/main/packages/schema/sr

### Reactivity

Reactivity is supported on all properties, as computed, computed getter refs and reactive.
Reactivity is supported on all properties, as computed, getters and reactive.

It's recommended to use computed getters (`() => {}`) over computed (`computed(() => {})`).
It's recommended to use getters (`() => value`) over computed (`computed(() => value)`).

::code-group

```vue [useHead]
<script setup lang="ts">
const desc = ref('My amazing site.')
const description = ref('My amazing site.')

useHead({
meta: [
{ name: 'description', content: desc }
{ name: 'description', content: description }
],
})
</script>
```

```vue [useSeoMeta]
<script setup lang="ts">
const desc = ref('My amazing site.')

useSeoMeta({
description
})
</script>
```

```vue [Components]
<script setup>
const desc = ref('My amazing site.')
const description = ref('My amazing site.')
</script>

<template>
<div>
<Meta name="description" :content="desc" />
<Meta name="description" :content="description" />
</div>
</template>
```
Expand Down Expand Up @@ -257,8 +265,7 @@ useHead({
</script>
```

::LinkExample{link="/docs/examples/composables/use-head"}
::
:LinkExample{link="/docs/examples/composables/use-head"}

:ReadMore{link="/docs/guide/directory-structure/pages/#page-metadata"}

Expand Down