mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
✨ Added @site.signup_url
data property for themes (#12893)
refs https://github.com/TryGhost/Team/issues/579 - when members signup is enabled returns `#/portal` otherwise returns feedly subscription URL - allows for themes to have subscription buttons without condititionals, eg `<a href="{{@site.signup_url}}">Subscribe</a>`
This commit is contained in:
parent
4fa4dc8034
commit
074e8b1292
2 changed files with 56 additions and 29 deletions
|
@ -90,6 +90,14 @@ function getSiteData(req) {
|
|||
// @TODO: it would be nicer if this was proper middleware somehow...
|
||||
siteData = preview.handle(req, siteData);
|
||||
|
||||
// theme-only computed property added to @site
|
||||
if (settingsCache.get('members_signup_access') === 'none') {
|
||||
const escapedUrl = encodeURIComponent(urlUtils.urlFor({relativeUrl: '/rss/'}, true));
|
||||
siteData.signup_url = `https://feedly.com/i/subscription/feed/${escapedUrl}`;
|
||||
} else {
|
||||
siteData.signup_url = '#/portal';
|
||||
}
|
||||
|
||||
return siteData;
|
||||
}
|
||||
|
||||
|
@ -152,10 +160,10 @@ function updateLocalTemplateOptions(req, res, next) {
|
|||
} : null;
|
||||
|
||||
hbs.updateLocalTemplateOptions(res.locals, _.merge({}, localTemplateOptions, {
|
||||
// @TODO: remove blog if we drop v2 (Ghost 4.0)
|
||||
data: {
|
||||
member: member,
|
||||
site: siteData,
|
||||
// @deprecated: a gscan warning for @blog was added before 3.0 which replaced it with @site
|
||||
blog: siteData
|
||||
}
|
||||
}));
|
||||
|
|
|
@ -111,34 +111,6 @@ describe('Themes middleware', function () {
|
|||
});
|
||||
});
|
||||
|
||||
it('calls updateTemplateOptions with correct data', function (done) {
|
||||
const themeDataExpectedProps = ['posts_per_page', 'image_sizes'];
|
||||
|
||||
executeMiddleware(middleware, req, res, function next(err) {
|
||||
should.not.exist(err);
|
||||
|
||||
hbs.updateTemplateOptions.calledOnce.should.be.true();
|
||||
const templateOptions = hbs.updateTemplateOptions.firstCall.args[0];
|
||||
const data = templateOptions.data;
|
||||
|
||||
data.should.be.an.Object().with.properties('site', 'labs', 'config');
|
||||
|
||||
// Check Theme Config
|
||||
data.config.should.be.an.Object()
|
||||
.with.properties(themeDataExpectedProps)
|
||||
.and.size(themeDataExpectedProps.length);
|
||||
// posts per page should be set according to the stub
|
||||
data.config.posts_per_page.should.eql(2);
|
||||
|
||||
// Check labs config
|
||||
should.deepEqual(data.labs, fakeLabsData);
|
||||
|
||||
should.equal(data.site, fakeSiteData);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('Sets res.locals.secure to the value of req.secure', function (done) {
|
||||
req.secure = Math.random() < 0.5;
|
||||
|
||||
|
@ -151,6 +123,53 @@ describe('Themes middleware', function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe('updateTemplateOptions', function () {
|
||||
it('is called with correct data', function (done) {
|
||||
const themeDataExpectedProps = ['posts_per_page', 'image_sizes'];
|
||||
|
||||
executeMiddleware(middleware, req, res, function next(err) {
|
||||
should.not.exist(err);
|
||||
|
||||
hbs.updateTemplateOptions.calledOnce.should.be.true();
|
||||
const templateOptions = hbs.updateTemplateOptions.firstCall.args[0];
|
||||
const data = templateOptions.data;
|
||||
|
||||
data.should.be.an.Object().with.properties('site', 'labs', 'config');
|
||||
|
||||
// Check Theme Config
|
||||
data.config.should.be.an.Object()
|
||||
.with.properties(themeDataExpectedProps)
|
||||
.and.size(themeDataExpectedProps.length);
|
||||
// posts per page should be set according to the stub
|
||||
data.config.posts_per_page.should.eql(2);
|
||||
|
||||
// Check labs config
|
||||
should.deepEqual(data.labs, fakeLabsData);
|
||||
|
||||
should.equal(data.site, fakeSiteData);
|
||||
should.exist(data.site.signup_url);
|
||||
data.site.signup_url.should.equal('#/portal');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('switches @site.signup_url to RSS when signup is disabled', function (done) {
|
||||
settingsCache.get
|
||||
.withArgs('members_signup_access').returns('none');
|
||||
|
||||
executeMiddleware(middleware, req, res, function next(err) {
|
||||
const templateOptions = hbs.updateTemplateOptions.firstCall.args[0];
|
||||
const data = templateOptions.data;
|
||||
|
||||
should.exist(data.site.signup_url);
|
||||
data.site.signup_url.should.equal('https://feedly.com/i/subscription/feed/http%3A%2F%2F127.0.0.1%3A2369%2Frss%2F');
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Preview Mode', function () {
|
||||
it('calls updateTemplateOptions with correct data when one parameter is set', function (done) {
|
||||
const previewString = 'c=%23000fff';
|
||||
|
|
Loading…
Add table
Reference in a new issue