mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-06-05 15:09:59 +09:00
Gracefully handle invalid dates
This commit is contained in:
+8
-3
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user