diff --git a/src/parser.js b/src/parser.js index f1291ab..5fa53a6 100644 --- a/src/parser.js +++ b/src/parser.js @@ -74,15 +74,15 @@ function buildPost(data) { // full raw post data data, - // contents of the post in markdown + // body content converted to markdown content: translator.getPostContent(data.encoded[0]), - // these are not written to file, but help with other things + // particularly useful values for all sorts of things type: data.post_type[0], id: data.post_id[0], isDraft: data.status[0] === 'draft', slug: decodeURIComponent(data.post_name[0]), - date: data.pubDate[0] ? luxon.DateTime.fromRFC2822(data.pubDate[0], { zone: shared.config.customDateTimezone }) : undefined, + date: getPostDate(data), coverImageId: getPostMetaValue(data.postmeta, '_thumbnail_id'), // these are possibly set later in mergeImagesIntoPosts() @@ -91,6 +91,11 @@ function buildPost(data) { }; } +function getPostDate(data) { + const date = luxon.DateTime.fromRFC2822(data.pubDate[0] ?? '', { zone: shared.config.customDateTimezone }); + return date.isValid ? date : undefined; +} + function getPostMetaValue(metas, key) { const meta = metas && metas.find((meta) => meta.meta_key[0] === key); return meta ? meta.meta_value[0] : undefined;