mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
✨ Added newsletter design settings (#12352)
refs https://github.com/TryGhost/Ghost/issues/12355 - Adds new default settings for newsletter customisations - `newsletter_show_badge`, `newsletter_show_header` and `newsletter_body_font_category` - Adds migrations to update group for new settings - Add migration to update settings based on existing config value for newsletter settings - Passes new newsletter settings to newsletter template and updates design based on them - Fix tests
This commit is contained in:
parent
7640fa3bee
commit
215bfd0a7a
11 changed files with 142 additions and 16 deletions
|
@ -10,7 +10,8 @@ const groupTypeMapping = {
|
|||
members: 'members',
|
||||
private: 'private',
|
||||
portal: 'portal',
|
||||
email: 'bulk_email'
|
||||
email: 'bulk_email',
|
||||
newsletter: 'newsletter'
|
||||
};
|
||||
|
||||
const mapGroupToType = (group) => {
|
||||
|
|
|
@ -10,7 +10,8 @@ const groupTypeMapping = {
|
|||
members: 'members',
|
||||
private: 'private',
|
||||
portal: 'portal',
|
||||
email: 'bulk_email'
|
||||
email: 'bulk_email',
|
||||
newsletter: 'newsletter'
|
||||
};
|
||||
|
||||
const mapGroupToType = (group) => {
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
const logging = require('../../../../../shared/logging');
|
||||
const {createTransactionalMigration} = require('../../utils');
|
||||
|
||||
module.exports = createTransactionalMigration(
|
||||
|
||||
async function up(connection) {
|
||||
logging.info('Updating newsletter settings - newsletter_show_badge, newsletter_show_header, newsletter_body_font_category - to newsletter group');
|
||||
await connection('settings')
|
||||
.whereIn('key', ['newsletter_show_badge', 'newsletter_show_header', 'newsletter_body_font_category'])
|
||||
.update({
|
||||
group: 'newsletter'
|
||||
});
|
||||
},
|
||||
|
||||
async function down() {}
|
||||
);
|
|
@ -0,0 +1,48 @@
|
|||
const {createTransactionalMigration} = require('../../utils');
|
||||
const config = require('../../../../../shared/config');
|
||||
const logging = require('../../../../../shared/logging');
|
||||
|
||||
module.exports = createTransactionalMigration(
|
||||
async function up(connection) {
|
||||
const emailTemplateConfig = config.get('members:emailTemplate');
|
||||
|
||||
logging.info('Updating newsletter_show_header setting from members.emailTemplate.showSiteHeader config');
|
||||
await connection('settings')
|
||||
.update({
|
||||
value: emailTemplateConfig.showSiteHeader ? 'true' : 'false'
|
||||
})
|
||||
.where({
|
||||
key: 'newsletter_show_header'
|
||||
});
|
||||
|
||||
logging.info('Updating newsletter_show_badge setting from members.emailTemplate.showPoweredBy config');
|
||||
await connection('settings')
|
||||
.update({
|
||||
value: emailTemplateConfig.showPoweredBy ? 'true' : 'false'
|
||||
})
|
||||
.where({
|
||||
key: 'newsletter_show_badge'
|
||||
});
|
||||
},
|
||||
|
||||
async function down(connection) {
|
||||
logging.info('Updating newsletter_show_header setting to default "true"');
|
||||
await connection('settings')
|
||||
.update({
|
||||
value: 'true'
|
||||
})
|
||||
.where({
|
||||
key: 'newsletter_show_header'
|
||||
});
|
||||
|
||||
logging.info('Updating newsletter_show_badge setting to default "false"');
|
||||
await connection('settings')
|
||||
.update({
|
||||
value: 'false'
|
||||
})
|
||||
.where({
|
||||
key: 'newsletter_show_badge'
|
||||
});
|
||||
}
|
||||
);
|
||||
|
|
@ -383,5 +383,46 @@
|
|||
"defaultValue": "[]",
|
||||
"type": "array"
|
||||
}
|
||||
},
|
||||
"newsletter": {
|
||||
"newsletter_show_badge": {
|
||||
"defaultValue": "false",
|
||||
"validations": {
|
||||
"isEmpty": false,
|
||||
"isIn": [
|
||||
[
|
||||
"true",
|
||||
"false"
|
||||
]
|
||||
]
|
||||
},
|
||||
"type": "boolean"
|
||||
},
|
||||
"newsletter_show_header": {
|
||||
"defaultValue": "true",
|
||||
"validations": {
|
||||
"isEmpty": false,
|
||||
"isIn": [
|
||||
[
|
||||
"true",
|
||||
"false"
|
||||
]
|
||||
]
|
||||
},
|
||||
"type": "boolean"
|
||||
},
|
||||
"newsletter_body_font_category": {
|
||||
"defaultValue": "sans_serif",
|
||||
"validations": {
|
||||
"isEmpty": false,
|
||||
"isIn": [
|
||||
[
|
||||
"serif",
|
||||
"sans_serif"
|
||||
]
|
||||
]
|
||||
},
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
const _ = require('lodash');
|
||||
const juice = require('juice');
|
||||
const template = require('./template');
|
||||
const config = require('../../../shared/config');
|
||||
const settingsCache = require('../../services/settings/cache');
|
||||
const urlUtils = require('../../../shared/url-utils');
|
||||
const moment = require('moment-timezone');
|
||||
|
@ -153,8 +152,12 @@ const serialize = async (postModel, options = {isBrowserPreview: false}) => {
|
|||
uppercaseHeadings: false
|
||||
});
|
||||
|
||||
const templateConfig = config.get('members:emailTemplate');
|
||||
let htmlTemplate = template({post, site: getSite(), templateConfig});
|
||||
const templateSettings = {
|
||||
showSiteHeader: settingsCache.get('newsletter_show_header'),
|
||||
bodyFontCategory: settingsCache.get('newsletter_body_font_category'),
|
||||
showBadge: settingsCache.get('newsletter_show_badge')
|
||||
};
|
||||
let htmlTemplate = template({post, site: getSite(), templateSettings});
|
||||
if (options.isBrowserPreview) {
|
||||
const previewUnsubscribeUrl = createUnsubscribeUrl();
|
||||
htmlTemplate = htmlTemplate.replace('%recipient.unsubscribe_url%', previewUnsubscribeUrl);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* eslint indent: warn, no-irregular-whitespace: warn */
|
||||
module.exports = ({post, site, templateConfig}) => {
|
||||
module.exports = ({post, site, templateSettings}) => {
|
||||
const date = new Date();
|
||||
return `<!doctype html>
|
||||
<html>
|
||||
|
@ -346,6 +346,15 @@ figure blockquote p {
|
|||
border-bottom: 1px solid #e5eff5;
|
||||
}
|
||||
|
||||
.post-content-sans-serif {
|
||||
max-width: 600px !important;
|
||||
font-size: 17px;
|
||||
line-height: 1.5em;
|
||||
color: #23323D;
|
||||
padding-bottom: 20px;
|
||||
border-bottom: 1px solid #e5eff5;
|
||||
}
|
||||
|
||||
.post-content a {
|
||||
color: #08121A;
|
||||
text-decoration: underline;
|
||||
|
@ -815,7 +824,7 @@ figure blockquote p {
|
|||
}
|
||||
|
||||
|
||||
${ templateConfig.showPoweredBy ? `
|
||||
${ templateSettings.showBadge ? `
|
||||
.footer-powered {
|
||||
text-align: center;
|
||||
padding-bottom: 40px;
|
||||
|
@ -858,7 +867,7 @@ ${ templateConfig.showPoweredBy ? `
|
|||
<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%">
|
||||
|
||||
|
||||
${ templateConfig.showSiteHeader ? `
|
||||
${ templateSettings.showSiteHeader ? `
|
||||
<tr>
|
||||
<td class="site-info" width="100%" align="center">
|
||||
<table role="presentation" border="0" cellpadding="0" cellspacing="0">
|
||||
|
@ -898,11 +907,10 @@ ${ templateConfig.showPoweredBy ? `
|
|||
</tr>
|
||||
` : ``}
|
||||
<tr>
|
||||
<td class="post-content">
|
||||
<td class="${(templateSettings.bodyFontCategory === 'sans_serif') ? `post-content-sans-serif` : `post-content` }">
|
||||
<!-- POST CONTENT START -->
|
||||
${post.html}
|
||||
<!-- POST CONTENT END -->
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
@ -918,7 +926,7 @@ ${ templateConfig.showPoweredBy ? `
|
|||
<td class="footer">${site.title} © ${date.getFullYear()} – <a href="%recipient.unsubscribe_url%">Unsubscribe</a></td>
|
||||
</tr>
|
||||
|
||||
${ templateConfig.showPoweredBy ? `
|
||||
${ templateSettings.showBadge ? `
|
||||
<tr>
|
||||
<td class="footer-powered"><a href="https://ghost.org/"><img src="https://static.ghost.org/v3.0.0/images/powered.png" border="0" width="142" height="30" class="gh-powered" alt="Publish with Ghost"></a></td>
|
||||
</tr>
|
||||
|
|
|
@ -65,7 +65,10 @@ const defaultSettingsKeyTypes = [
|
|||
{key: 'shared_views', type: 'blog'},
|
||||
{key: 'active_timezone', type: 'blog'},
|
||||
{key: 'default_locale', type: 'blog'},
|
||||
{key: 'accent_color', type: 'blog'}
|
||||
{key: 'accent_color', type: 'blog'},
|
||||
{key: 'newsletter_show_badge', type: 'newsletter'},
|
||||
{key: 'newsletter_show_header', type: 'newsletter'},
|
||||
{key: 'newsletter_body_font_category', type: 'newsletter'}
|
||||
];
|
||||
|
||||
describe('Settings API (canary)', function () {
|
||||
|
@ -99,7 +102,6 @@ describe('Settings API (canary)', function () {
|
|||
|
||||
jsonResponse.settings.should.be.an.Object();
|
||||
const settings = jsonResponse.settings;
|
||||
|
||||
should.equal(settings.length, defaultSettingsKeyTypes.length);
|
||||
for (const defaultSetting of defaultSettingsKeyTypes) {
|
||||
should.exist(settings.find((setting) => {
|
||||
|
|
|
@ -63,7 +63,10 @@ const defaultSettingsKeyTypes = [
|
|||
{key: 'ghost_head', type: 'blog'},
|
||||
{key: 'ghost_foot', type: 'blog'},
|
||||
{key: 'active_timezone', type: 'blog'},
|
||||
{key: 'default_locale', type: 'blog'}
|
||||
{key: 'default_locale', type: 'blog'},
|
||||
{key: 'newsletter_show_badge', type: 'newsletter'},
|
||||
{key: 'newsletter_show_header', type: 'newsletter'},
|
||||
{key: 'newsletter_body_font_category', type: 'newsletter'}
|
||||
];
|
||||
|
||||
describe('Settings API (v2)', function () {
|
||||
|
|
|
@ -65,7 +65,10 @@ const defaultSettingsKeys = [
|
|||
'shared_views',
|
||||
'active_timezone',
|
||||
'default_locale',
|
||||
'accent_color'
|
||||
'accent_color',
|
||||
'newsletter_show_badge',
|
||||
'newsletter_show_header',
|
||||
'newsletter_body_font_category'
|
||||
];
|
||||
|
||||
describe('Settings API (v3)', function () {
|
||||
|
|
|
@ -34,7 +34,7 @@ describe('DB version integrity', function () {
|
|||
// Only these variables should need updating
|
||||
const currentSchemaHash = '97705c7f5ae33414fcdb009c143480a8';
|
||||
const currentFixturesHash = 'd46d696c94d03e41a5903500547fea77';
|
||||
const currentSettingsHash = 'c8daa2c9632bb75f9d60655de09ae3bd';
|
||||
const currentSettingsHash = '229360069a9c77a945727a3c5869c3c6';
|
||||
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
|
||||
|
||||
// If this test is failing, then it is likely a change has been made that requires a DB version bump,
|
||||
|
|
Loading…
Add table
Reference in a new issue