2020-04-30 22:26:12 +03:00
|
|
|
const errors = require('@tryghost/errors');
|
|
|
|
const {logging} = require('./common');
|
2020-05-27 20:47:53 +03:00
|
|
|
const config = require('../../shared/config');
|
2020-03-25 22:53:11 +03:00
|
|
|
|
2020-04-29 18:44:27 +03:00
|
|
|
let cardFactory;
|
|
|
|
let cards;
|
|
|
|
let mobiledocHtmlRenderer;
|
2017-12-14 14:09:54 +03:00
|
|
|
|
2020-03-19 15:18:54 +03:00
|
|
|
module.exports = {
|
2020-04-08 18:42:55 +03:00
|
|
|
get blankDocument() {
|
|
|
|
return {
|
|
|
|
version: '0.3.1',
|
|
|
|
markups: [],
|
|
|
|
atoms: [],
|
|
|
|
cards: [],
|
|
|
|
sections: [
|
|
|
|
[1, 'p', [
|
|
|
|
[0, [], 0, '']
|
|
|
|
]]
|
|
|
|
]
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2017-12-14 14:09:54 +03:00
|
|
|
get cards() {
|
2020-04-08 20:21:15 +03:00
|
|
|
if (!cards) {
|
|
|
|
const CardFactory = require('@tryghost/kg-card-factory');
|
|
|
|
const defaultCards = require('@tryghost/kg-default-cards');
|
2020-03-25 22:53:11 +03:00
|
|
|
|
2020-04-08 20:21:15 +03:00
|
|
|
cardFactory = new CardFactory({
|
|
|
|
siteUrl: config.get('url')
|
|
|
|
});
|
2020-03-25 22:53:11 +03:00
|
|
|
|
2020-04-08 20:21:15 +03:00
|
|
|
cards = defaultCards.map((card) => {
|
|
|
|
return cardFactory.createCard(card);
|
|
|
|
});
|
|
|
|
}
|
2020-03-25 22:53:11 +03:00
|
|
|
|
|
|
|
return cards;
|
2017-12-14 14:09:54 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get atoms() {
|
2020-04-08 16:49:14 +03:00
|
|
|
return require('@tryghost/kg-default-atoms');
|
2017-12-14 14:09:54 +03:00
|
|
|
},
|
|
|
|
|
2020-04-08 20:21:15 +03:00
|
|
|
get mobiledocHtmlRenderer() {
|
|
|
|
if (!mobiledocHtmlRenderer) {
|
|
|
|
const MobiledocHtmlRenderer = require('@tryghost/kg-mobiledoc-html-renderer');
|
|
|
|
|
|
|
|
mobiledocHtmlRenderer = new MobiledocHtmlRenderer({
|
|
|
|
cards: this.cards,
|
|
|
|
atoms: this.atoms,
|
|
|
|
unknownCardHandler(args) {
|
2020-04-30 22:26:12 +03:00
|
|
|
logging.error(new errors.InternalServerError({
|
2020-04-08 20:21:15 +03:00
|
|
|
message: 'Mobiledoc card \'' + args.env.name + '\' not found.'
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return mobiledocHtmlRenderer;
|
2020-03-19 15:18:54 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
get htmlToMobiledocConverter() {
|
|
|
|
try {
|
|
|
|
return require('@tryghost/html-to-mobiledoc').toMobiledoc;
|
|
|
|
} catch (err) {
|
|
|
|
return () => {
|
2020-04-30 22:26:12 +03:00
|
|
|
throw new errors.InternalServerError({
|
2020-03-19 15:18:54 +03:00
|
|
|
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
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
2017-03-14 21:07:33 +03:00
|
|
|
}
|
|
|
|
};
|