@@ -67,21 +67,18 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
67
67
. extend ( Ember . PromiseProxyMixin )
68
68
. create ( deferred ) ;
69
69
} ) ,
70
- /**
71
- * The placeholder is the published date of the post,
72
- * or the current date if the pubdate has not been set.
73
- */
74
- publishedAtPlaceholder : Ember . computed ( 'publishedAtValue' , function ( ) {
70
+
71
+ publishedAtValue : Ember . computed ( 'published_at' , function ( ) {
75
72
var pubDate = this . get ( 'published_at' ) ;
76
73
if ( pubDate ) {
77
74
return formatDate ( pubDate ) ;
78
75
}
79
76
return formatDate ( moment ( ) ) ;
80
77
} ) ,
81
- publishedAtValue : boundOneWay ( 'published_at' , formatDate ) ,
82
78
83
79
slugValue : boundOneWay ( 'slug' ) ,
84
- //Lazy load the slug generator for slugPlaceholder
80
+
81
+ //Lazy load the slug generator
85
82
slugGenerator : Ember . computed ( function ( ) {
86
83
return SlugGenerator . create ( {
87
84
ghostPaths : this . get ( 'ghostPaths' ) ,
@@ -160,10 +157,15 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
160
157
return placeholder ;
161
158
} ) ,
162
159
163
- seoURL : Ember . computed ( 'slug' , 'slugPlaceholder' , function ( ) {
160
+ seoURL : Ember . computed ( 'slug' , function ( ) {
164
161
var blogUrl = this . get ( 'config' ) . blogUrl ,
165
- seoSlug = this . get ( 'slug' ) ? this . get ( 'slug' ) : this . get ( 'slugPlaceholder' ) ,
166
- seoURL = blogUrl + '/' + seoSlug + '/' ;
162
+ seoSlug = this . get ( 'slug' ) ? this . get ( 'slug' ) : '' ,
163
+ seoURL = blogUrl + '/' + seoSlug ;
164
+
165
+ // only append a slash to the URL if the slug exists
166
+ if ( seoSlug ) {
167
+ seoURL += '/' ;
168
+ }
167
169
168
170
if ( seoURL . length > 70 ) {
169
171
seoURL = seoURL . substring ( 0 , 70 ) . trim ( ) ;
@@ -180,33 +182,20 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
180
182
this . addObserver ( 'titleScratch' , this , 'titleObserver' ) ;
181
183
}
182
184
} . observes ( 'model' ) ,
185
+
183
186
titleObserver : function ( ) {
184
- var debounceId ;
187
+ var debounceId ,
188
+ title = this . get ( 'title' ) ,
189
+ slug = this . get ( 'slug' ) ;
185
190
186
- if ( this . get ( 'isNew' ) && ! this . get ( ' title' ) ) {
187
- debounceId = Ember . run . debounce ( this , 'generateAndSetSlug' , [ 'slugPlaceholder' ] , 700 ) ;
188
- } else if ( this . get ( 'title ' ) === '(Untitled)' ) {
191
+ // generate a slug if a post is new and doesn't have a title yet or
192
+ // if the title is still '(Untitled)' and the slug is unaltered.
193
+ if ( ( this . get ( 'isNew ' ) && ! title ) || title === '(Untitled)' && / ^ u n t i t l e d ( - \d + ) { 0 , 1 } $ / . test ( slug ) ) {
189
194
debounceId = Ember . run . debounce ( this , 'generateAndSetSlug' , [ 'slug' ] , 700 ) ;
190
195
}
191
196
192
197
this . set ( 'debounceId' , debounceId ) ;
193
198
} ,
194
- slugPlaceholder : Ember . computed ( function ( key , value ) {
195
- var slug = this . get ( 'slug' ) ;
196
-
197
- //If the post has a slug, that's its placeholder.
198
- if ( slug ) {
199
- return slug ;
200
- }
201
-
202
- //Otherwise, it's whatever value was set by the
203
- // slugGenerator (below)
204
- if ( arguments . length > 1 ) {
205
- return value ;
206
- }
207
- //The title will stand in until the actual slug has been generated
208
- return this . get ( 'titleScratch' ) ;
209
- } ) ,
210
199
211
200
showErrors : function ( errors ) {
212
201
errors = Ember . isArray ( errors ) ? errors : [ errors ] ;
0 commit comments