Skip to content

Commit

Permalink
chore: Update SEO metadata in app and blog components
Browse files Browse the repository at this point in the history
  • Loading branch information
d0rich committed Sep 6, 2024
1 parent 167fbab commit c01c9c8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
3 changes: 1 addition & 2 deletions apps/d0rich.me/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ useSeoMeta({
ogDescription: description,
author: 'Nikolai Dorofeev',
generator: 'Nuxt 3',
// colorScheme: 'dark',
ogSiteName: 'd0rich',
ogSiteName: 'd0rich.me',
ogImage: 'https://d0rich.me/og/image.jpg',
ogUrl: computed(() => 'https://d0rich.me' + route.path),
twitterCard: 'summary_large_image',
Expand Down
31 changes: 23 additions & 8 deletions apps/d0rich.me/components/AsyncSafeSeoWithOg.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<script setup lang="ts">
defineProps<{
import { joinURL } from 'ufo'
const props = defineProps<{
title?: string
ogTitle?: string
description?: string
image?: string
}>()
const imageHref = computed(() => {
if (!props.image) return undefined
return joinURL('https://d0rich.me', props.image)
})
</script>

<template>
Expand All @@ -18,12 +25,20 @@ defineProps<{
:content="ogTitle || title"
/>
<Meta v-if="title" property="twitter:title" :content="title" />
<Meta v-if="description" name="description" :content="description" />
<Meta v-if="description" property="og:description" :content="description" />
<Meta
v-if="description"
property="twitter:description"
:content="description"
/>

<template v-if="description">
<Meta name="description" :content="description" />
<Meta property="og:description" :content="description" />
<Meta property="twitter:description" :content="description" />
</template>

<template v-if="image">
<Meta property="og:image" :content="imageHref" />
<Meta property="twitter:image" :content="imageHref" />
<Meta property="tg:cover" :content="imageHref" />
</template>

<Link rel="author" href="https://d0rich.me" />
<Meta property="tg:channel" content="@d0rich" />
</Head>
</template>
25 changes: 22 additions & 3 deletions apps/d0rich.me/pages/blog/[...slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Disqus } from 'vue-disqus'
import type { MarkdownParsedContent } from '@nuxt/content/dist/runtime/types'
interface Document extends MarkdownParsedContent {
date?: Date
date?: string
image?: string
}
const slug = clearSlug(useRoute().params.slug as string[])
Expand Down Expand Up @@ -53,16 +54,34 @@ const linkToBlog = computed(() => {
Math.floor((position.value ?? 1) / (itemsOnPage - 1) + 1)
)
})
const docDate = computed(() => {
if (!doc.value?.date) return undefined
return new Date(doc.value.date)
})
</script>

<template>
<div v-if="doc" class="pb-[50vh] pt-10">
<AsyncSafeSeoWithOg :title="doc.title" :description="doc.description" />
<AsyncSafeSeoWithOg
:title="doc.title"
:description="doc.description"
:image="doc.image"
/>
<Head>
<Meta
v-if="docDate"
property="tg:published_date"
:content="String(Math.floor(docDate.getTime() / 1000))"
/>
</Head>
<div class="blog-article blog-fonts">
<nav class="mb-10">
<DBigBangButton text="< Back" :to="addTrailingSlash(linkToBlog)" />
</nav>
<time v-if="doc.date">{{ dateToDayMonthYear(doc.date) }}</time>
<time v-if="docDate" :datetime="docDate.toISOString()">
{{ dateToDayMonthYear(doc.date) }}
</time>
</div>
<ContentRenderer
:value="doc"
Expand Down

0 comments on commit c01c9c8

Please sign in to comment.