Truncate metatitle and url when > 70 characters

Closes #4301
This commit is contained in:
Jason Williams 2014-10-17 16:18:52 +00:00
parent a2b7fe718b
commit b6951ac9a2
2 changed files with 21 additions and 4 deletions

View File

@ -102,7 +102,15 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
seoTitle: Ember.computed('titleScratch', 'metaTitleScratch', function () {
var metaTitle = this.get('metaTitleScratch') || '';
return metaTitle.length > 0 ? metaTitle : this.get('titleScratch');
metaTitle = metaTitle.length > 0 ? metaTitle : this.get('titleScratch');
if (metaTitle.length > 70) {
metaTitle = metaTitle.substring(0, 70).trim();
metaTitle = Ember.Handlebars.Utils.escapeExpression(metaTitle);
metaTitle = new Ember.Handlebars.SafeString(metaTitle + '…');
}
return metaTitle;
}),
seoDescription: Ember.computed('scratch', 'metaDescriptionScratch', function () {
@ -139,8 +147,17 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
return placeholder;
}),
seoSlug: Ember.computed('slug', 'slugPlaceholder', function () {
return this.get('slug') ? this.get('slug') : this.get('slugPlaceholder');
seoURL: Ember.computed('slug', 'slugPlaceholder', function () {
var blogUrl = this.get('config').blogUrl,
seoSlug = this.get('slug') ? this.get('slug') : this.get('slugPlaceholder'),
seoURL = blogUrl + '/' + seoSlug + '/';
if (seoURL.length > 70) {
seoURL = seoURL.substring(0, 70).trim();
seoURL = new Ember.Handlebars.SafeString(seoURL + '…');
}
return seoURL;
}),
// observe titleScratch, keeping the post's slug in sync

View File

@ -92,7 +92,7 @@
<label>Search Engine Result Preview</label>
<div class="seo-preview">
<div class="seo-preview-title">{{seoTitle}}</div>
<div class="seo-preview-link">{{gh-blog-url}}/{{seoSlug}}{{#if seoSlug}}/{{/if}}</div>
<div class="seo-preview-link">{{seoURL}}</div>
<div class="seo-preview-description">{{seoDescription}}</div>
</div>
</div>