mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Merge pull request #1819 from hswolff/quick-edit-post-redirect
Adds ability to quickly get to post’s edit page
This commit is contained in:
commit
74217e72c4
4 changed files with 160 additions and 15 deletions
|
@ -82,6 +82,13 @@ frontendControllers = {
|
|||
post = promises[1];
|
||||
|
||||
function render() {
|
||||
// If we're ready to render the page
|
||||
// but the last param is 'edit' then we'll
|
||||
// actually kick you to the edit page.
|
||||
if (req.params[2] && req.params[2] === 'edit') {
|
||||
return res.redirect(config.paths().subdir + '/ghost/editor/' + post.id + '/');
|
||||
}
|
||||
|
||||
filters.doFilter('prePostsRender', post).then(function (post) {
|
||||
api.settings.read('activeTheme').then(function (activeTheme) {
|
||||
var paths = config.paths().availableThemes[activeTheme.value],
|
||||
|
@ -125,6 +132,10 @@ frontendControllers = {
|
|||
return next(e);
|
||||
});
|
||||
},
|
||||
'edit': function (req, res, next) {
|
||||
req.params[2] = 'edit';
|
||||
return frontendControllers.single(req, res, next);
|
||||
},
|
||||
'rss': function (req, res, next) {
|
||||
// Initialize RSS
|
||||
var siteUrl = config().url,
|
||||
|
|
|
@ -13,6 +13,8 @@ module.exports = function (server) {
|
|||
// Examples:
|
||||
// Given `/plain-slug/` the req.params would be [undefined, 'plain-slug']
|
||||
// Given `/2012/12/24/plain-slug/` the req.params would be ['2012/12/24/', 'plain-slug']
|
||||
// Given `/plain-slug/edit/` the req.params would be [undefined, 'plain-slug', 'edit']
|
||||
server.get(/^\/([0-9]{4}\/[0-9]{2}\/[0-9]{2}\/)?([^\/.]*)\/$/, frontend.single);
|
||||
server.get(/^\/([0-9]{4}\/[0-9]{2}\/[0-9]{2}\/)?([^\/.]*)\/edit\/$/, frontend.edit);
|
||||
server.get('/', frontend.homepage);
|
||||
};
|
|
@ -88,8 +88,6 @@ describe('Frontend Routing', function () {
|
|||
// get today's date
|
||||
var date = moment().format("YYYY/MM/DD");
|
||||
|
||||
console.log('date', date);
|
||||
|
||||
request.get('/' + date + '/welcome-to-ghost/')
|
||||
.expect('Cache-Control', cacheRules.hour)
|
||||
.expect(404)
|
||||
|
|
|
@ -14,7 +14,8 @@ describe('Frontend Controller', function () {
|
|||
|
||||
var ghost,
|
||||
sandbox,
|
||||
apiSettingsStub;
|
||||
apiSettingsStub,
|
||||
adminEditPagePath = '/ghost/editor/';
|
||||
|
||||
beforeEach(function () {
|
||||
sandbox = sinon.sandbox.create();
|
||||
|
@ -36,7 +37,8 @@ describe('Frontend Controller', function () {
|
|||
'title': 'Test static page',
|
||||
'slug': 'test-static-page',
|
||||
'markdown': 'Test static page content',
|
||||
'page': 1
|
||||
'page': 1,
|
||||
'published_at': new Date('2013/12/30').getTime()
|
||||
},
|
||||
mockPost = {
|
||||
'status': 'published',
|
||||
|
@ -44,7 +46,8 @@ describe('Frontend Controller', function () {
|
|||
'title': 'Test normal post',
|
||||
'slug': 'test-normal-post',
|
||||
'markdown': 'The test normal post content',
|
||||
'page': 0
|
||||
'page': 0,
|
||||
'published_at': new Date('2014/1/2').getTime()
|
||||
};
|
||||
|
||||
beforeEach(function () {
|
||||
|
@ -61,6 +64,7 @@ describe('Frontend Controller', function () {
|
|||
|
||||
sandbox.stub(config, 'paths', function () {
|
||||
return {
|
||||
'subdir': '',
|
||||
'availableThemes': {
|
||||
'casper': {
|
||||
'assets': null,
|
||||
|
@ -83,7 +87,7 @@ describe('Frontend Controller', function () {
|
|||
|
||||
it('can render a static page', function (done) {
|
||||
var req = {
|
||||
params: [undefined, 'test-static-page']
|
||||
params: [undefined, mockStaticPost.slug]
|
||||
},
|
||||
res = {
|
||||
render: function (view, context) {
|
||||
|
@ -98,7 +102,7 @@ describe('Frontend Controller', function () {
|
|||
|
||||
it('will NOT render a static page accessed as a date url', function (done) {
|
||||
var req = {
|
||||
params: ['2012/12/30/', 'test-static-page']
|
||||
params: ['2012/12/30/', mockStaticPost.slug]
|
||||
},
|
||||
res = {
|
||||
render: sinon.spy()
|
||||
|
@ -112,7 +116,7 @@ describe('Frontend Controller', function () {
|
|||
|
||||
it('can render a normal post', function (done) {
|
||||
var req = {
|
||||
params: [undefined, 'test-normal-post']
|
||||
params: [undefined, mockPost.slug]
|
||||
},
|
||||
res = {
|
||||
render: function (view, context) {
|
||||
|
@ -128,7 +132,7 @@ describe('Frontend Controller', function () {
|
|||
|
||||
it('will NOT render a normal post accessed as a date url', function (done) {
|
||||
var req = {
|
||||
params: ['2012/12/30/', 'test-normal-post']
|
||||
params: ['2012/12/30/', mockPost.slug]
|
||||
},
|
||||
res = {
|
||||
render: sinon.spy()
|
||||
|
@ -139,6 +143,71 @@ describe('Frontend Controller', function () {
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
// Handle Edit append
|
||||
it('will redirect to admin edit page for a normal post', function (done) {
|
||||
var req = {
|
||||
params: [undefined, mockPost.slug, 'edit']
|
||||
},
|
||||
res = {
|
||||
render: sinon.spy(),
|
||||
redirect: function(arg) {
|
||||
res.render.called.should.be.false;
|
||||
arg.should.eql(adminEditPagePath + mockPost.id + '/');
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
frontend.single(req, res, null);
|
||||
});
|
||||
|
||||
it('will NOT redirect to admin edit page for a normal post accessed as a date url', function (done) {
|
||||
var req = {
|
||||
params: ['2012/12/30/', mockPost.slug, 'edit']
|
||||
},
|
||||
res = {
|
||||
render: sinon.spy(),
|
||||
redirect: sinon.spy()
|
||||
};
|
||||
|
||||
frontend.single(req, res, function () {
|
||||
res.render.called.should.be.false;
|
||||
res.redirect.called.should.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('will redirect to admin edit page for a static page accessed as a slug', function (done) {
|
||||
var req = {
|
||||
params: [undefined, mockStaticPost.slug, 'edit']
|
||||
},
|
||||
res = {
|
||||
render: sinon.spy(),
|
||||
redirect: function(arg) {
|
||||
res.render.called.should.be.false;
|
||||
arg.should.eql(adminEditPagePath + mockStaticPost.id + '/');
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
frontend.single(req, res, null);
|
||||
});
|
||||
|
||||
it('will NOT redirect to admin edit page for a static page accessed as a date url', function (done) {
|
||||
var req = {
|
||||
params: ['2012/12/30/', mockStaticPost.slug, 'edit']
|
||||
},
|
||||
res = {
|
||||
render: sinon.spy(),
|
||||
redirect: sinon.spy()
|
||||
};
|
||||
|
||||
frontend.single(req, res, function () {
|
||||
res.render.called.should.be.false;
|
||||
res.redirect.called.should.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('permalink set to date', function () {
|
||||
|
@ -150,7 +219,7 @@ describe('Frontend Controller', function () {
|
|||
|
||||
it('can render a static page', function (done) {
|
||||
var req = {
|
||||
params: [undefined, 'test-static-page']
|
||||
params: [undefined, mockStaticPost.slug]
|
||||
},
|
||||
res = {
|
||||
render: function (view, context) {
|
||||
|
@ -178,9 +247,9 @@ describe('Frontend Controller', function () {
|
|||
});
|
||||
|
||||
it('can render a normal post', function (done) {
|
||||
var date = moment().format('YYYY/MM/DD/'),
|
||||
var date = moment(mockPost.published_at).format('YYYY/MM/DD/'),
|
||||
req = {
|
||||
params: [date, 'test-normal-post']
|
||||
params: [date, mockPost.slug]
|
||||
},
|
||||
res = {
|
||||
render: function (view, context) {
|
||||
|
@ -195,9 +264,9 @@ describe('Frontend Controller', function () {
|
|||
});
|
||||
|
||||
it('will NOT render a normal post with the wrong date', function (done) {
|
||||
var date = moment().subtract('days', 1).format('YYYY/MM/DD/'),
|
||||
var date = moment(mockPost.published_at).subtract('days', 1).format('YYYY/MM/DD/'),
|
||||
req = {
|
||||
params: [date, 'test-normal-post']
|
||||
params: [date, mockPost.slug]
|
||||
},
|
||||
res = {
|
||||
render: sinon.spy()
|
||||
|
@ -211,7 +280,7 @@ describe('Frontend Controller', function () {
|
|||
|
||||
it('will NOT render a normal post accessed as a slug url', function (done) {
|
||||
var req = {
|
||||
params: [undefined, 'test-normal-post']
|
||||
params: [undefined, mockPost.slug]
|
||||
},
|
||||
res = {
|
||||
render: sinon.spy()
|
||||
|
@ -222,6 +291,71 @@ describe('Frontend Controller', function () {
|
|||
done();
|
||||
});
|
||||
});
|
||||
|
||||
// Handle Edit append
|
||||
it('will redirect to admin edit page for a normal post', function (done) {
|
||||
var req = {
|
||||
params: [moment(mockPost.published_at).format('YYYY/MM/DD/'), mockPost.slug, 'edit']
|
||||
},
|
||||
res = {
|
||||
render: sinon.spy(),
|
||||
redirect: function (arg) {
|
||||
res.render.called.should.be.false;
|
||||
arg.should.eql(adminEditPagePath + mockPost.id + '/');
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
frontend.single(req, res, null);
|
||||
});
|
||||
|
||||
it('will NOT redirect to admin edit page for a normal post accessed as a slug url', function (done) {
|
||||
var req = {
|
||||
params: [undefined, mockPost.slug, 'edit']
|
||||
},
|
||||
res = {
|
||||
render: sinon.spy(),
|
||||
redirect: sinon.spy()
|
||||
};
|
||||
|
||||
frontend.single(req, res, function () {
|
||||
res.render.called.should.be.false;
|
||||
res.redirect.called.should.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('will redirect to admin edit page for a static page accessed as a slug url', function (done) {
|
||||
var req = {
|
||||
params: [undefined, mockStaticPost.slug, 'edit']
|
||||
},
|
||||
res = {
|
||||
render: sinon.spy(),
|
||||
redirect: function (arg) {
|
||||
res.render.called.should.be.false;
|
||||
arg.should.eql(adminEditPagePath + mockStaticPost.id + '/');
|
||||
done();
|
||||
}
|
||||
};
|
||||
|
||||
frontend.single(req, res, null);
|
||||
});
|
||||
|
||||
it('will NOT redirect to admin edit page for a static page accessed as a date url', function (done) {
|
||||
var req = {
|
||||
params: ['2012/12/30/', mockStaticPost.slug, 'edit']
|
||||
},
|
||||
res = {
|
||||
render: sinon.spy(),
|
||||
redirect: sinon.spy()
|
||||
};
|
||||
|
||||
frontend.single(req, res, function () {
|
||||
res.render.called.should.be.false;
|
||||
res.redirect.called.should.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Reference in a new issue