mirror of
https://github.com/TryGhost/Ghost.git
synced 2023-12-13 21:00:40 +01:00
🐛 Return reg. HTML on Amperize time-out (#7324)
no issue `{{amp_content}}` helper can handle error now, if returned from `Amperize` module. In case of on error, we return the unprocessed HTML, which will then get validated by the `Sanitize` functionality. The unprocessed HTML will be stored in the cache, until the post is updated. Points to Amperize fork of AileenCGN as dependency to have include the error handling changes incl. timeouts.
This commit is contained in:
parent
761d963893
commit
b3b1bcca94
2 changed files with 19 additions and 3 deletions
|
@ -12,6 +12,7 @@ var hbs = require('express-hbs'),
|
|||
moment = require('moment'),
|
||||
sanitizeHtml = require('sanitize-html'),
|
||||
config = require('../../../../config'),
|
||||
errors = require('../../../../errors'),
|
||||
makeAbsoluteUrl = require('../../../../utils/make-absolute-urls'),
|
||||
cheerio = require('cheerio'),
|
||||
amperize = new Amperize(),
|
||||
|
@ -121,10 +122,20 @@ function getAmperizeHTML(html, post) {
|
|||
html = makeAbsoluteUrl(html, config.url, post.url).html();
|
||||
|
||||
if (!amperizeCache[post.id] || moment(new Date(amperizeCache[post.id].updated_at)).diff(new Date(post.updated_at)) < 0) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
return new Promise(function (resolve) {
|
||||
amperize.parse(html, function (err, res) {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
if (err.src) {
|
||||
errors.logError(err.message, 'AMP HTML couldn\'t get parsed:' + err.src);
|
||||
} else {
|
||||
errors.logError(err);
|
||||
}
|
||||
|
||||
// save it in cache to prevent multiple calls to Amperize until
|
||||
// content is updated.
|
||||
amperizeCache[post.id] = {updated_at: post.updated_at, amp: html};
|
||||
// return the original html on an error
|
||||
return resolve(html);
|
||||
}
|
||||
|
||||
amperizeCache[post.id] = {updated_at: post.updated_at, amp: res};
|
||||
|
@ -157,6 +168,11 @@ function ampContent() {
|
|||
$('video').children('source').remove();
|
||||
$('video').children('track').remove();
|
||||
|
||||
// Case: AMP parsing failed and we returned the regular HTML,
|
||||
// then we have to remove remaining, invalid HTML tags.
|
||||
$('audio').children('source').remove();
|
||||
$('audio').children('track').remove();
|
||||
|
||||
ampHTML = $.html();
|
||||
|
||||
// @TODO: remove this, when Amperize supports HTML sanitizing
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
"node": "~0.10.0 || ~0.12.0 || ^4.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"amperize": "https://github.com/AileenCGN/amperize/tarball/fixed-layout-for-small-images",
|
||||
"amperize": "https://github.com/AileenCGN/amperize/tarball/error-handling-on-timeout",
|
||||
"archiver": "1.0.1",
|
||||
"bcryptjs": "2.3.0",
|
||||
"bluebird": "3.4.1",
|
||||
|
|
Loading…
Reference in a new issue