Merge pull request #4302 from jaswilli/issue-4301

Truncate with ellipsis when metatitle > 70 chars
This commit is contained in:
Hannah Wolfe 2014-10-18 01:07:31 +03:00
commit 78788dfaea
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>