mirror of
https://github.com/TryGhost/Ghost.git
synced 2023-12-13 21:00:40 +01:00
Add view post link on published and updated posts
closes #1756 - adds a post url link to 'post updated' and 'post published' in editor - adds join function in ghost paths - adds a '/' detection to makeRoute method - adds test for join function
This commit is contained in:
parent
4c3d548bb3
commit
53d12a9659
5 changed files with 89 additions and 8 deletions
|
@ -182,8 +182,12 @@ EditorControllerMixin = Ember.Mixin.create(MarkerManager, {
|
|||
},
|
||||
|
||||
showSaveNotification: function (prevStatus, status, delay) {
|
||||
var message = this.messageMap.success.post[prevStatus][status];
|
||||
var message = this.messageMap.success.post[prevStatus][status],
|
||||
path = this.get('ghostPaths.url').join(this.get('config.blogUrl'), this.get('url'));
|
||||
|
||||
if (status === 'published') {
|
||||
message += ' <a href="' + path + '">View Post</a>';
|
||||
}
|
||||
this.notifications.showSuccess(message, {delayed: delay});
|
||||
},
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ var Post = DS.Model.extend(NProgressSaveMixin, ValidationEngine, {
|
|||
published_at: DS.attr('moment-date'),
|
||||
published_by: DS.belongsTo('user', {async: true}),
|
||||
tags: DS.hasMany('tag', {embedded: 'always'}),
|
||||
url: DS.attr('string'),
|
||||
|
||||
// Computed post properties
|
||||
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
var makeRoute = function (root, args) {
|
||||
var parts = Array.prototype.slice.call(args, 0).join('/'),
|
||||
route = [root, parts].join('/');
|
||||
var slashAtStart,
|
||||
slashAtEnd,
|
||||
parts,
|
||||
route;
|
||||
|
||||
if (route.slice(-1) !== '/') {
|
||||
route += '/';
|
||||
}
|
||||
slashAtStart = /^\//;
|
||||
slashAtEnd = /\/$/;
|
||||
route = root.replace(slashAtEnd, '');
|
||||
parts = Array.prototype.slice.call(args, 0);
|
||||
|
||||
return route;
|
||||
parts.forEach(function (part) {
|
||||
route = [route, part.replace(slashAtStart, '').replace(slashAtEnd, '')].join('/');
|
||||
});
|
||||
return route += '/';
|
||||
};
|
||||
|
||||
function ghostPaths() {
|
||||
|
@ -34,6 +40,16 @@ function ghostPaths() {
|
|||
return makeRoute(apiRoot, arguments);
|
||||
},
|
||||
|
||||
join: function () {
|
||||
if (arguments.length > 1) {
|
||||
return makeRoute(arguments[0], Array.prototype.slice.call(arguments, 1));
|
||||
} else if (arguments.length === 1) {
|
||||
var arg = arguments[0];
|
||||
return arg.slice(-1) === '/' ? arg : arg + '/';
|
||||
}
|
||||
return '/';
|
||||
},
|
||||
|
||||
asset: assetUrl
|
||||
}
|
||||
};
|
||||
|
|
|
@ -17,7 +17,7 @@ function getValidKeys() {
|
|||
environment: process.env.NODE_ENV,
|
||||
database: config.database.client,
|
||||
mail: _.isObject(config.mail) ? config.mail.transport : '',
|
||||
blogUrl: config.url,
|
||||
blogUrl: config.url.replace(/\/$/, ''),
|
||||
blogTitle: config.theme.title
|
||||
};
|
||||
|
||||
|
|
60
core/test/client/unit/utils/ghost-paths_test.js
Normal file
60
core/test/client/unit/utils/ghost-paths_test.js
Normal file
|
@ -0,0 +1,60 @@
|
|||
/* jshint expr:true */
|
||||
|
||||
import ghostPaths from 'ghost/utils/ghost-paths';
|
||||
|
||||
describe('ghost-paths', function () {
|
||||
describe('join', function () {
|
||||
var join = ghostPaths().url.join;
|
||||
|
||||
it('should join two or more paths, normalizing slashes', function () {
|
||||
var path;
|
||||
|
||||
path = join('/one/', '/two/');
|
||||
expect(path).to.equal('/one/two/');
|
||||
|
||||
path = join('/one', '/two/');
|
||||
expect(path).to.equal('/one/two/');
|
||||
|
||||
path = join('/one/', 'two/');
|
||||
expect(path).to.equal('/one/two/');
|
||||
|
||||
path = join('/one/', 'two/', '/three/');
|
||||
expect(path).to.equal('/one/two/three/');
|
||||
|
||||
path = join('/one/', 'two', 'three/');
|
||||
expect(path).to.equal('/one/two/three/');
|
||||
});
|
||||
|
||||
it('should not change the slash at the beginning', function () {
|
||||
var path;
|
||||
|
||||
path = join('one/');
|
||||
expect(path).to.equal('one/');
|
||||
path = join('one/', 'two');
|
||||
expect(path).to.equal('one/two/');
|
||||
path = join('/one/', 'two');
|
||||
expect(path).to.equal('/one/two/');
|
||||
path = join('one/', 'two', 'three');
|
||||
expect(path).to.equal('one/two/three/');
|
||||
path = join('/one/', 'two', 'three');
|
||||
expect(path).to.equal('/one/two/three/');
|
||||
});
|
||||
|
||||
it('should always return a slash at the end', function () {
|
||||
var path;
|
||||
|
||||
path = join();
|
||||
expect(path).to.equal('/');
|
||||
path = join('');
|
||||
expect(path).to.equal('/');
|
||||
path = join('one');
|
||||
expect(path).to.equal('one/');
|
||||
path = join('one/');
|
||||
expect(path).to.equal('one/');
|
||||
path = join('one', 'two');
|
||||
expect(path).to.equal('one/two/');
|
||||
path = join('one', 'two/');
|
||||
expect(path).to.equal('one/two/');
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue