Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions site/app/composables/usePageSeo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const DEFAULT_DESCRIPTION =
'AutoFixture makes unit tests more productive by creating anonymous test data for .NET.'

const DEFAULT_OG_IMAGE = '/og-image.png'

type PageSeoOptions = {
title?: MaybeRefOrGetter<string | undefined>
description?: MaybeRefOrGetter<string | undefined>
image?: MaybeRefOrGetter<string | undefined>
}

export function usePageSeo(options: PageSeoOptions = {}) {
const route = useRoute()
const { public: { siteUrl } } = useRuntimeConfig()

const title = computed(() => toValue(options.title) ?? 'AutoFixture')
const description = computed(() => toValue(options.description) ?? DEFAULT_DESCRIPTION)
const image = computed(() => `${siteUrl}${toValue(options.image) ?? DEFAULT_OG_IMAGE}`)
const url = computed(() => `${siteUrl}${route.path}`)

useHead({
title,
meta: computed(() => [
{ name: 'description', content: description.value },
{ property: 'og:title', content: title.value },
{ property: 'og:description', content: description.value },
{ property: 'og:image', content: image.value },
{ property: 'og:url', content: url.value },
{ property: 'og:type', content: 'website' },
{ property: 'og:site_name', content: 'AutoFixture' },
{ name: 'twitter:card', content: 'summary_large_image' },
{ name: 'twitter:title', content: title.value },
{ name: 'twitter:description', content: description.value },
{ name: 'twitter:image', content: image.value },
]),
})
}
3 changes: 2 additions & 1 deletion site/app/pages/api/[...slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ if (!page.value) {
const pageTitle = computed(() => page.value?.title ?? 'API')
const tocLinks = computed(() => page.value?.tocLinks ?? [])

useSeoMeta({
usePageSeo({
title: () => pageTitle.value,
description: () => `AutoFixture API reference — ${pageTitle.value}`,
})
</script>

Expand Down
6 changes: 3 additions & 3 deletions site/app/pages/docs/[...slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const { data: surround } = await useAsyncData(
() => queryCollectionItemSurroundings('docs', docsPath.value),
)

useSeoMeta({
title: page.value.title,
description: page.value.description,
usePageSeo({
title: () => page.value?.title,
description: () => page.value?.description,
})

const tocLinks = computed(() => page.value?.body?.toc?.links ?? [])
Expand Down
2 changes: 1 addition & 1 deletion site/app/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
const { defaultApiPath } = useApiCatalog()

useSeoMeta({
usePageSeo({
title: 'AutoFixture',
description:
'AutoFixture makes unit tests more productive by creating anonymous test data for .NET.',
Expand Down
25 changes: 21 additions & 4 deletions site/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ function readApiPrerenderRoutes() {
}
}

const siteUrl = 'https://autofixture.com'
const siteDescription =
'AutoFixture makes unit tests more productive by creating anonymous test data for .NET.'
const ogImage = `${siteUrl}/og-image.png`

export default defineNuxtConfig({
runtimeConfig: {
public: {
siteUrl,
},
},
modules: [
'@nuxt/ui',
'@nuxt/content',
Expand All @@ -37,10 +47,17 @@ export default defineNuxtConfig({
head: {
title: 'AutoFixture',
meta: [
{
name: 'description',
content: 'AutoFixture makes unit tests more productive by creating anonymous test data for .NET.',
},
{ name: 'description', content: siteDescription },
{ property: 'og:site_name', content: 'AutoFixture' },
{ property: 'og:type', content: 'website' },
{ property: 'og:title', content: 'AutoFixture' },
{ property: 'og:description', content: siteDescription },
{ property: 'og:image', content: ogImage },
{ property: 'og:url', content: `${siteUrl}/` },
{ name: 'twitter:card', content: 'summary_large_image' },
{ name: 'twitter:title', content: 'AutoFixture' },
{ name: 'twitter:description', content: siteDescription },
{ name: 'twitter:image', content: ogImage },
],
link: [
{ rel: 'icon', type: 'image/svg+xml', href: '/favicon.svg' },
Expand Down
Binary file added site/public/og-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions site/public/og-image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.