Gracefully handle invalid dates

This commit is contained in:
Will Boyd
2025-02-10 16:33:24 -05:00
parent cc09a41744
commit cb9dd9255e
+8 -3
View File
@@ -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;