Skip to content

Commit 98029a1

Browse files
committed
feat: update Open Graph and Twitter image URLs for better SEO handling
1 parent f5ed3c5 commit 98029a1

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

app/app.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ useHead({
1919
2020
useSeoMeta({
2121
titleTemplate: '%s - Alexandre Nédélec',
22-
ogImage: '/images/social-card.png',
23-
twitterImage: '/images/social-card.png',
22+
ogImage: '/social-card.png',
23+
twitterImage: '/social-card.png',
2424
twitterCard: 'summary_large_image'
2525
})
2626

app/pages/goodies/[slug].vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script setup lang="ts">
2+
import { joinURL } from 'ufo'
3+
24
const route = useRoute()
35
46
const { data: goodie } = await useAsyncData(route.path, () => queryCollection('goodies').path(route.path).first())
@@ -22,9 +24,12 @@ useSeoMeta({
2224
ogDescription: description
2325
})
2426
27+
// OG Image: use goodie cover image if available, otherwise generate one
2528
if (goodie.value.image?.src) {
26-
defineOgImage({
27-
url: goodie.value.image.src
29+
const site = useSiteConfig()
30+
useSeoMeta({
31+
ogImage: joinURL(site.url, goodie.value.image.src),
32+
twitterImage: joinURL(site.url, goodie.value.image.src)
2833
})
2934
} else {
3035
defineOgImageComponent('Saas', {

app/pages/posts/[slug].vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<script setup lang="ts">
2+
import { joinURL } from 'ufo'
3+
24
const route = useRoute()
35
46
const { data: post } = await useAsyncData(route.path, () => queryCollection('posts').path(route.path).first())
@@ -38,9 +40,12 @@ useSchemaOrg([
3840
})
3941
])
4042
43+
// OG Image: use post cover image if available, otherwise generate one
4144
if (post.value.image?.src) {
42-
defineOgImage({
43-
url: post.value.image.src
45+
const site = useSiteConfig()
46+
useSeoMeta({
47+
ogImage: joinURL(site.url, post.value.image.src),
48+
twitterImage: joinURL(site.url, post.value.image.src)
4449
})
4550
} else {
4651
defineOgImageComponent('Saas', {
@@ -54,7 +59,7 @@ if (post.value.image?.src) {
5459
<NuxtImg
5560
v-if="post.image?.src"
5661
:src="post.image.src"
57-
:alt="post.image.alt || post.title"
62+
:alt="post.title"
5863
class="post-cover-image w-full rounded-lg shadow-lg mb-8"
5964
/>
6065

0 commit comments

Comments
 (0)