🐛 Fixed broken structured data previews

closes https://github.com/TryGhost/Ghost/issues/11385

- Updates og and twitter description to use correct fallbacks for posts/pages
- Updates og and twitter description to use correct fallback for tags
- Updates og and twitter title to use correct name format for tags
This commit is contained in:
Rish 2020-07-14 16:44:02 +05:30 committed by Rishabh Garg
parent 63ea14327a
commit a38d7ddb19
2 changed files with 8 additions and 5 deletions

View File

@ -40,10 +40,10 @@ export default Component.extend(SettingsMenuMixin, {
twitterTitleScratch: alias('post.twitterTitleScratch'), twitterTitleScratch: alias('post.twitterTitleScratch'),
slugValue: boundOneWay('post.slug'), slugValue: boundOneWay('post.slug'),
facebookDescription: or('ogDescriptionScratch', 'customExcerptScratch', 'seoDescription'), facebookDescription: or('ogDescriptionScratch', 'customExcerptScratch', 'seoDescription', 'post.excerpt', 'settings.description', ''),
facebookImage: or('post.ogImage', 'post.featureImage'), facebookImage: or('post.ogImage', 'post.featureImage'),
facebookTitle: or('ogTitleScratch', 'seoTitle'), facebookTitle: or('ogTitleScratch', 'seoTitle'),
twitterDescription: or('twitterDescriptionScratch', 'customExcerptScratch', 'seoDescription'), twitterDescription: or('twitterDescriptionScratch', 'customExcerptScratch', 'seoDescription', 'post.excerpt', 'settings.description', ''),
twitterImage: or('post.twitterImage', 'post.featureImage'), twitterImage: or('post.twitterImage', 'post.featureImage'),
twitterTitle: or('twitterTitleScratch', 'seoTitle'), twitterTitle: or('twitterTitleScratch', 'seoTitle'),

View File

@ -11,6 +11,7 @@ const {Handlebars} = Ember;
export default Component.extend({ export default Component.extend({
feature: service(), feature: service(),
config: service(), config: service(),
settings: service(),
tag: null, tag: null,
scratchTag: null, scratchTag: null,
@ -19,11 +20,11 @@ export default Component.extend({
setProperty: () => {}, setProperty: () => {},
twitterTitle: or('scratchTag.twitterTitle', 'seoTitle'), twitterTitle: or('scratchTag.twitterTitle', 'seoTitle'),
twitterDescription: or('scratchTag.twitterDescription', 'seoDescription'), twitterDescription: or('scratchTag.twitterDescription', 'seoDescription', 'settings.metaDescription', ''),
twitterImage: or('tag.twitterImage', 'tag.featureImage'), twitterImage: or('tag.twitterImage', 'tag.featureImage'),
facebookTitle: or('scratchTag.ogTitle', 'seoTitle'), facebookTitle: or('scratchTag.ogTitle', 'seoTitle'),
facebookDescription: or('scratchTag.ogDescription', 'seoDescription'), facebookDescription: or('scratchTag.ogDescription', 'seoDescription', 'settings.metaDescription', ''),
facebookImage: or('tag.ogImage', 'tag.featureImage'), facebookImage: or('tag.ogImage', 'tag.featureImage'),
accentColor: computed('tag.accentColor', function () { accentColor: computed('tag.accentColor', function () {
@ -48,7 +49,9 @@ export default Component.extend({
}), }),
seoTitle: computed('scratchTag.{name,metaTitle}', function () { seoTitle: computed('scratchTag.{name,metaTitle}', function () {
let metaTitle = this.scratchTag.metaTitle || this.scratchTag.name; const settingsTitle = this.get('settings.title') || '';
const tagName = settingsTitle ? `${this.scratchTag.name} - ${settingsTitle}` : this.scratchTag.name;
let metaTitle = this.scratchTag.metaTitle || tagName;
if (metaTitle && metaTitle.length > 70) { if (metaTitle && metaTitle.length > 70) {
metaTitle = metaTitle.substring(0, 70).trim(); metaTitle = metaTitle.substring(0, 70).trim();