Skip to content

Is there a way to use excerpts for meta description? #228

Answered by ElMassimo
dankimio asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, but currently the most robust option to do that is a bit verbose:

<script setup lang="ts">
const { page } = $(usePage())

const description = $computed(() => page.excerpt)
</script>

<template>
  <Head>
    <meta name="description" :content="description"/>
    <meta property="og:description" :content="description"/>
    <meta property="twitter:description" :content="description"/>
  </Head>
</template>

In some cases, you might be able to get away with:

<script setup lang="ts">
const { frontmatter, page } = $(usePage())

frontmatter.description = page.excerpt
</script>

Try building the site and check the results.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dankimio
Comment options

Answer selected by dankimio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants