Skip to content

Commit 9a62a38

Browse files
committed
Change slug and date placeholders to values
Closes #4121
1 parent 4067bfe commit 9a62a38

File tree

2 files changed

+21
-32
lines changed

2 files changed

+21
-32
lines changed

core/client/controllers/post-settings-menu.js

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,18 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
6767
.extend(Ember.PromiseProxyMixin)
6868
.create(deferred);
6969
}),
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 () {
7572
var pubDate = this.get('published_at');
7673
if (pubDate) {
7774
return formatDate(pubDate);
7875
}
7976
return formatDate(moment());
8077
}),
81-
publishedAtValue: boundOneWay('published_at', formatDate),
8278

8379
slugValue: boundOneWay('slug'),
84-
//Lazy load the slug generator for slugPlaceholder
80+
81+
//Lazy load the slug generator
8582
slugGenerator: Ember.computed(function () {
8683
return SlugGenerator.create({
8784
ghostPaths: this.get('ghostPaths'),
@@ -160,10 +157,15 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
160157
return placeholder;
161158
}),
162159

163-
seoURL: Ember.computed('slug', 'slugPlaceholder', function () {
160+
seoURL: Ember.computed('slug', function () {
164161
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+
}
167169

168170
if (seoURL.length > 70) {
169171
seoURL = seoURL.substring(0, 70).trim();
@@ -180,33 +182,20 @@ var PostSettingsMenuController = Ember.ObjectController.extend({
180182
this.addObserver('titleScratch', this, 'titleObserver');
181183
}
182184
}.observes('model'),
185+
183186
titleObserver: function () {
184-
var debounceId;
187+
var debounceId,
188+
title = this.get('title'),
189+
slug = this.get('slug');
185190

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)' && /^untitled(-\d+){0,1}$/.test(slug)) {
189194
debounceId = Ember.run.debounce(this, 'generateAndSetSlug', ['slug'], 700);
190195
}
191196

192197
this.set('debounceId', debounceId);
193198
},
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-
}),
210199

211200
showErrors: function (errors) {
212201
errors = Ember.isArray(errors) ? errors : [errors];

core/client/templates/post-settings-menu.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
<div class="form-group">
1313
<label for="url">Post URL</label>
1414
<span class="input-icon icon-link">
15-
{{gh-input class="post-setting-slug" id="url" value=slugValue name="post-setting-slug" focus-out="updateSlug" placeholder=slugPlaceholder selectOnClick="true" stopEnterKeyDownPropagation="true"}}
15+
{{gh-input class="post-setting-slug" id="url" value=slugValue name="post-setting-slug" focus-out="updateSlug" selectOnClick="true" stopEnterKeyDownPropagation="true"}}
1616
</span>
1717
</div>
1818

1919
<div class="form-group">
2020
<label for="post-setting-date">Publish Date</label>
2121
<span class="input-icon icon-calendar">
22-
{{gh-input class="post-setting-date" id="post-setting-date" value=publishedAtValue name="post-setting-date" focus-out="setPublishedAt" placeholder=publishedAtPlaceholder stopEnterKeyDownPropagation="true"}}
22+
{{gh-input class="post-setting-date" id="post-setting-date" value=publishedAtValue name="post-setting-date" focus-out="setPublishedAt" stopEnterKeyDownPropagation="true"}}
2323
</span>
2424
</div>
2525

0 commit comments

Comments
 (0)