Skip to content

Commit

Permalink
JSON LD Structured Data (#52)
Browse files Browse the repository at this point in the history
* fix alt type issue

* add public logo

* schema org module

* json-ld first pass

* playwright not needed

* add person schema to team page

* tweak resource schema

* fix catchall route schema

* fix image url

* add author url to resource page

---------

Co-authored-by: rijkvanzanten <[email protected]>
  • Loading branch information
bryantgillespie and rijkvanzanten authored Sep 18, 2023
1 parent 4b52f45 commit fd51cf5
Show file tree
Hide file tree
Showing 9 changed files with 277 additions and 101 deletions.
15 changes: 15 additions & 0 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ useServerHead({
},
],
});
useSchemaOrg([
defineOrganization({
name: 'Directus',
logo: '/images/logo-dark.svg',
sameAs: [
'https://hub.docker.com/r/directus/directus',
'https://twitter.com/directus',
'https://github.com/directus',
'https://www.youtube.com/c/DirectusVideos',
'https://www.linkedin.com/company/directus-io',
'https://www.npmjs.com/package/directus',
],
}),
]);
</script>

<template>
Expand Down
7 changes: 7 additions & 0 deletions components/Block/Accordion.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ const { data: block } = useAsyncData(props.uuid, () =>
})
)
);
useSchemaOrg([
defineQuestion({
name: unref(block)?.title,
/* @TODO Get the content of the first block to use as an answer */
}),
]);
</script>

<template>
Expand Down
22 changes: 21 additions & 1 deletion components/ResourcePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const { data: resource } = await useAsyncData(
);
if (!unref(resource)) {
throw createError({ statusCode: 404, statusMessage: 'resource Not Found', fatal: true });
throw createError({ statusCode: 404, statusMessage: 'Resource Not Found', fatal: true });
}
useHead({
Expand Down Expand Up @@ -100,6 +100,26 @@ const showFeaturedImage = computed(() => {
return true;
});
useSchemaOrg([
defineArticle({
headline: unref(resource)?.seo?.title ?? unref(resource)?.title ?? undefined,
image: unref(resource)?.image?.id
? `https://marketing.directus.app/assets/${unref(resource)?.image?.id}`
: undefined,
datePublished: unref(resource)?.date_published ?? undefined,
description: unref(resource)?.seo?.meta_description ?? unref(resource)?.summary ?? undefined,
author: [
{
name: unref(resource)?.author?.name ?? '',
url: unref(resource)?.author?.slug ? `https://directus.io/team/${unref(resource)?.author?.slug}` : undefined,
image: unref(resource)?.author?.image
? `https://marketing.directus.app/assets/${unref(resource)?.author?.image}`
: undefined,
},
],
}),
]);
const randIndex = (length: number) => Math.floor(Math.random() * length);
const related = computed(() => {
Expand Down
5 changes: 5 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export default defineNuxtConfig({
},
},

schemaOrg: {
host: 'https://directus.io',
},

typescript: {
typeCheck: true,
},
Expand Down Expand Up @@ -91,6 +95,7 @@ export default defineNuxtConfig({
'nuxt-simple-sitemap', // https://nuxtseo.com/sitemap/getting-started/how-it-works
'floating-vue/nuxt',
'@zadigetvoltaire/nuxt-gtm',
'nuxt-schema-org',
],

vite: {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-vue": "9.14.1",
"nuxt": "3.6.5",
"nuxt-schema-org": "2.2.0",
"nuxt-simple-sitemap": "3.2.5",
"prettier": "2.8.8",
"sass": "1.64.1",
Expand Down
8 changes: 8 additions & 0 deletions pages/[...permalink].vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ useServerSeoMeta({
ogTitle: computed(() => unref(page)?.seo?.title ?? unref(page)?.title ?? null),
ogDescription: computed(() => unref(page)?.seo?.meta_description ?? null),
});
useSchemaOrg([
defineWebPage({
url: `https://directus.io${path}`,
name: unref(page)?.seo?.title ?? unref(page)?.title ?? undefined,
description: unref(page)?.seo?.meta_description ?? undefined,
}),
]);
</script>

<template>
Expand Down
10 changes: 10 additions & 0 deletions pages/team/[slug].vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ useServerSeoMeta({
ogDescription: computed(() => unref(person)?.bio ?? null),
});
useSchemaOrg([
definePerson({
url: `https://directus.io/team/${unref(person)?.slug}`,
name: unref(person)?.name ?? undefined,
description: unref(person)?.bio ?? undefined,
image: unref(person)?.image?.id ? `https://marketing.directus.app/assets/${unref(person)?.image?.id}` : undefined,
sameAs: unref(person)?.links?.map((link: { services: string; url: string }) => link.url) ?? undefined,
}),
]);
const resources = computed(() =>
unref(person)?.resources?.sort((a, b) => (a.date_published! > b.date_published! ? -1 : 1))
);
Expand Down
Loading

0 comments on commit fd51cf5

Please sign in to comment.