2021-01-27 01:49:05 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
|
|
|
|
export default class ModalPostPreviewSocialComponent extends Component {
|
|
|
|
@service config;
|
|
|
|
@service settings;
|
|
|
|
|
|
|
|
get _fallbackDescription() {
|
|
|
|
return this.args.post.customExcerpt ||
|
|
|
|
this.serpDescription ||
|
|
|
|
this.settings.get('description');
|
|
|
|
}
|
|
|
|
|
|
|
|
// SERP
|
|
|
|
|
|
|
|
get serpTitle() {
|
|
|
|
return this.args.post.metaTitle || this.args.post.title || '(Untitled)';
|
|
|
|
}
|
|
|
|
|
2021-02-01 12:13:23 +03:00
|
|
|
get serpURL() {
|
|
|
|
const blogUrl = this.config.get('blogUrl');
|
|
|
|
const seoSlug = this.args.post.slug || '';
|
|
|
|
const canonicalUrl = this.args.post.canonicalUrl || '';
|
|
|
|
|
|
|
|
if (canonicalUrl) {
|
|
|
|
if (canonicalUrl.match(/^\//)) {
|
|
|
|
return `${blogUrl}${canonicalUrl}`;
|
|
|
|
} else {
|
|
|
|
return canonicalUrl;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const seoURL = `${blogUrl}/${seoSlug}`;
|
|
|
|
|
|
|
|
// only append a slash to the URL if the slug exists
|
|
|
|
if (seoSlug) {
|
|
|
|
return `${seoURL}/`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return seoURL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-27 01:49:05 +03:00
|
|
|
get serpDescription() {
|
2021-02-01 12:23:10 +03:00
|
|
|
return this.args.post.metaDescription || this.args.post.excerpt;
|
2021-01-27 01:49:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Facebook
|
|
|
|
|
|
|
|
get facebookTitle() {
|
|
|
|
return this.args.post.ogTitle || this.serpTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
get facebookDescription() {
|
|
|
|
return this.args.post.ogDescription || this._fallbackDescription;
|
|
|
|
}
|
|
|
|
|
2021-01-28 16:57:14 +03:00
|
|
|
get facebookImage() {
|
2021-02-02 18:53:53 +03:00
|
|
|
return this.args.post.ogImage || this.args.post.featureImage;
|
2021-01-28 16:57:14 +03:00
|
|
|
}
|
|
|
|
|
2021-01-27 01:49:05 +03:00
|
|
|
// Twitter
|
|
|
|
|
|
|
|
get twitterTitle() {
|
|
|
|
return this.args.post.twitterTitle || this.serpTitle;
|
|
|
|
}
|
|
|
|
|
|
|
|
get twitterDescription() {
|
|
|
|
return this.args.post.twitterDescription || this._fallbackDescription;
|
|
|
|
}
|
2021-01-28 16:57:14 +03:00
|
|
|
|
|
|
|
get twitterImage() {
|
2021-02-02 18:53:53 +03:00
|
|
|
return this.args.post.twitterImage || this.args.post.featureImage;
|
2021-01-28 16:57:14 +03:00
|
|
|
}
|
2021-01-27 01:49:05 +03:00
|
|
|
}
|