Skip to content

Commit

Permalink
feat(blog): article structured data (#644)
Browse files Browse the repository at this point in the history
* feat(blog): article structured data

resolves #643

* fix(blog-post): remove date item spread

* feat(blog-post): add structured data description

Co-authored-by: Damien Robinson <damien.robinson@xcommedia.com.au>
  • Loading branch information
shadow81627 and damienrobinson committed Sep 30, 2020
1 parent 3e9151a commit 4692578
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion pages/blog/_slug.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default {
async asyncData({ $content, route, error }) {
try {
const item = await $content('blog', route.params.slug).fetch();
return { item, ...item };
return { item };
} catch {
error({ statusCode: 404 });
}
Expand Down Expand Up @@ -93,8 +93,14 @@ export default {
formatDate(date) {
return dayjs(date).format('MMMM D, YYYY');
},
image: require.context(
`~/assets/img?resize&size=1200&format=jpg`,
true,
/\.(png|jpe?g).*$/,
),
},
head() {
const image = this.image(`${this.item.image || './blog.jpg'}`);
return {
title: this.item.title,
meta: [
Expand All @@ -112,6 +118,25 @@ export default {
},
{ hid: 'og:type', property: 'og:type', content: 'article' },
],
script: [
{
json: {
'@context': 'https://schema.org',
'@type': 'Article',
headline: this.item.title,
description: this.item.description,
image: {
'@type': 'ImageObject',
url: `${this.$config.BASE_URL}${image.src}`,
width: image.width,
height: image.height,
},
datePublished: this.item.date,
dateModified: this.item.date,
},
type: 'application/ld+json',
},
],
};
},
};
Expand Down

1 comment on commit 4692578

@vercel
Copy link

@vercel vercel bot commented on 4692578 Sep 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.