0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Replaced moment with luxon in amp helper (#13683)

refs: #13648

- We are replacing moment with luxon as it is now recommended.
This commit is contained in:
Enrique Benitez 2021-10-28 14:10:53 -05:00 committed by GitHub
parent 083b57a924
commit 7f001a4758
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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) {