mirror of
https://github.com/TryGhost/Ghost.git
synced 2023-12-13 21:00:40 +01:00
Added optional support for HTML source
closes TryGhost/Ghost-SDK/issues/51 - Due to JSDOM not supporting Node v6 the support for HTML conversion is now optional
This commit is contained in:
parent
288a38036b
commit
f394eaa7b8
5 changed files with 59 additions and 3 deletions
|
@ -1,3 +1,5 @@
|
|||
const common = require('../../common');
|
||||
|
||||
module.exports = {
|
||||
get mobiledocConverter() {
|
||||
return require('./mobiledoc-converter');
|
||||
|
@ -8,6 +10,31 @@ module.exports = {
|
|||
},
|
||||
|
||||
get htmlToMobiledocConverter() {
|
||||
return require('@tryghost/html-to-mobiledoc').toMobiledoc;
|
||||
try {
|
||||
return require('@tryghost/html-to-mobiledoc').toMobiledoc;
|
||||
} catch (err) {
|
||||
if (process.versions.node.startsWith('v6.')) {
|
||||
// NOTE: When Node v6 is dropped this code block should be removed
|
||||
return () => {
|
||||
throw new common.errors.InternalServerError({
|
||||
message: 'Unable to convert from source HTML to Mobiledoc',
|
||||
context: 'The html-to-mobiledoc package was not installed',
|
||||
help: 'Please upgrade to Node.js v10',
|
||||
code: 'HTML_TO_MOBILEDOC_INSTALLATION',
|
||||
err: err
|
||||
});
|
||||
};
|
||||
} else {
|
||||
return () => {
|
||||
throw new common.errors.InternalServerError({
|
||||
message: 'Unable to convert from source HTML to Mobiledoc',
|
||||
context: 'The html-to-mobiledoc package was not installed',
|
||||
help: 'Please review any errors from the install process by checking the Ghost logs',
|
||||
code: 'HTML_TO_MOBILEDOC_INSTALLATION',
|
||||
err: err
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -371,11 +371,17 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
|
|||
});
|
||||
|
||||
describe('Ensure html to mobiledoc conversion', function () {
|
||||
before(function () {
|
||||
// NOTE: only supported in node v8 and higher
|
||||
if (process.version.startsWith('v6.')) {
|
||||
this.skip();
|
||||
}
|
||||
});
|
||||
|
||||
it('no transformation when no html source option provided', function () {
|
||||
const apiConfig = {};
|
||||
const mobiledoc = '{"version":"0.3.1","atoms":[],"cards":[],"sections":[]}';
|
||||
const frame = {
|
||||
options: {},
|
||||
data: {
|
||||
posts: [
|
||||
{
|
||||
|
|
22
core/test/unit/lib/mobiledoc/converters/converters_spec.js
Normal file
22
core/test/unit/lib/mobiledoc/converters/converters_spec.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
const should = require('should');
|
||||
const converters = require('../../../../../server/lib/mobiledoc/converters');
|
||||
|
||||
describe('Unit: lib/mobiledoc/converters', function () {
|
||||
describe('htmlToMobiledocConverter should be unsupported in node v6', function () {
|
||||
before(function () {
|
||||
if (!process.version.startsWith('v6.')) {
|
||||
this.skip();
|
||||
}
|
||||
});
|
||||
|
||||
it('should throw when running on node v6', function () {
|
||||
try {
|
||||
const thrower = converters.htmlToMobiledocConverter();
|
||||
thrower();
|
||||
throw new Error('should not execute');
|
||||
} catch (err) {
|
||||
err.message.should.equal('Unable to convert from source HTML to Mobiledoc');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
|
@ -38,7 +38,6 @@
|
|||
"dependencies": {
|
||||
"@nexes/nql": "0.2.1",
|
||||
"ajv": "6.8.1",
|
||||
"@tryghost/html-to-mobiledoc": "0.2.3",
|
||||
"amperize": "0.3.8",
|
||||
"analytics-node": "3.3.0",
|
||||
"archiver": "3.0.0",
|
||||
|
@ -114,6 +113,7 @@
|
|||
"xml": "1.0.1"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@tryghost/html-to-mobiledoc": "0.2.3",
|
||||
"sharp": "0.21.3",
|
||||
"sqlite3": "4.0.6"
|
||||
},
|
||||
|
|
|
@ -5986,6 +5986,7 @@ sprintf-js@~1.0.2:
|
|||
sqlite3@4.0.6, sqlite3@^4.0.6:
|
||||
version "4.0.6"
|
||||
resolved "https://registry.yarnpkg.com/sqlite3/-/sqlite3-4.0.6.tgz#e587b583b5acc6cb38d4437dedb2572359c080ad"
|
||||
integrity sha512-EqBXxHdKiwvNMRCgml86VTL5TK1i0IKiumnfxykX0gh6H6jaKijAXvE9O1N7+omfNSawR2fOmIyJZcfe8HYWpw==
|
||||
dependencies:
|
||||
nan "~2.10.0"
|
||||
node-pre-gyp "^0.11.0"
|
||||
|
|
Loading…
Reference in a new issue