Display meta tags (for Facebook, Twitter, etc.)

Social media, here we come!
This commit is contained in:
Hippo 2020-04-26 22:24:12 +05:30
parent bd90d5168a
commit 4c42364083

View file

@ -86,8 +86,46 @@ export default {
} else {
bodyAttrs = "page-template"
}
let baseUrl = this.$static.metadata.siteUrl||this.$static.metadata.ghost.url
let meta = [
{ property: 'og:site_name', content: 'Snipette' },
{ property: 'og:type', content: 'article' },
{ property: 'og:title', content: this.thisPost.title },
{ property: 'og:description', content: this.thisPost.description },
{ property: 'og:url', content: baseUrl + this.thisPost.path },
{ property: 'og:image', content: changeUrls(this.thisPost.image) },
{ property: 'article:published_time', content: this.thisPost.date },
]
for (var i=0; i<this.thisPost.tags.length; i++) {
meta.push({ property: 'article:tag', content: this.thisPost.tags[i].title })
}
if (Admin.social_media && Admin.social_media.facebook) {
meta.push({ property: 'article:publisher', content: 'https://www.facebook.com/' + Admin.social_media.facebook })
}
meta = meta.concat([
{ property: 'twitter:card', content: 'summary_large_image' },
{ property: 'twitter:title', content: this.thisPost.title },
{ property: 'twitter:description', content: this.thisPost.description },
{ property: 'twitter:url', content: baseUrl + this.thisPost.path },
{ property: 'twitter:image', content: changeUrls(this.thisPost.image) },
{ property: 'twitter:label1', content: 'Written by' },
{ property: 'twitter:data1', content: this.thisPost.authors[0].name },
{ property: 'twitter:label2', content: 'Filed under' },
{ property: 'twitter:data2', content: this.thisPost.tags.map((t)=>{return t.title}).join(',') },
])
if (Admin.social_media && Admin.social_media.twitter) {
meta.push({ property: 'twitter:site', content: '@' + Admin.social_media.twitter })
}
return {
title: this.$page.post ? this.$page.post.title : this.$page.page.title,
meta: meta,
bodyAttrs: {
class: bodyAttrs
}
@ -184,6 +222,7 @@ export default {
<static-query>
query Metadata {
metadata {
siteUrl
ghost {
title
url