diff --git a/core/frontend/apps/amp/lib/helpers/amp_content.js b/core/frontend/apps/amp/lib/helpers/amp_content.js index 7aabd91266..68fd196397 100644 --- a/core/frontend/apps/amp/lib/helpers/amp_content.js +++ b/core/frontend/apps/amp/lib/helpers/amp_content.js @@ -8,7 +8,7 @@ // there if available. The cacheId is a combination of `updated_at` and the `slug`. const Promise = require('bluebird'); -const moment = require('moment'); +const {DateTime, Interval} = require('luxon'); const errors = require('@tryghost/errors'); const logging = require('@tryghost/logging'); @@ -119,14 +119,26 @@ function getAmperizeHTML(html, post) { } let Amperize = require('amperize'); - let startedAtMoment = moment(); amperize = amperize || new Amperize(); - if (!amperizeCache[post.id] || moment(new Date(amperizeCache[post.id].updated_at)).diff(new Date(post.updated_at)) < 0) { + const startedAtMoment = DateTime.now(); + + let cacheDateTime; + let postDateTime; + + if (amperizeCache[post.id]) { + const {updated_at: ampCacheUpdatedAt} = amperizeCache[post.id]; + const {updated_at: postUpdatedAt} = post; + + cacheDateTime = DateTime.fromJSDate(new Date(ampCacheUpdatedAt)); + postDateTime = DateTime.fromJSDate(new Date(postUpdatedAt)); + } + + if (!amperizeCache[post.id] || cacheDateTime.diff(postDateTime).valueOf() < 0) { return new Promise((resolve) => { amperize.parse(html, (err, res) => { - logging.info('amp.parse', post.url, moment().diff(startedAtMoment, 'ms') + 'ms'); + logging.info('amp.parse', post.url, Interval.fromDateTimes(startedAtMoment, DateTime.now()).length('milliseconds') + 'ms'); if (err) { if (err.src) {