From 8a25175c733dfbfdd353392fa745281f9d42afa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20N=C3=BDvlt?= Date: Mon, 17 Jun 2024 10:13:05 +0200 Subject: [PATCH] Fix datetimes being incorrectly encoded in frontmatter as strings instead of YAML timestamps --- src/writer.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/writer.js b/src/writer.js index d8f8701..c81d229 100644 --- a/src/writer.js +++ b/src/writer.js @@ -81,6 +81,8 @@ async function loadMarkdownFilePromise(post) { // array of one or more strings outputValue = value.reduce((list, item) => `${list}\n - "${item}"`, ''); } + } else if (value instanceof luxon.DateTime) { + outputValue = encodeDate(value); } else { // single string value const escapedValue = (value || '').replace(/"/g, '\\"'); @@ -98,6 +100,16 @@ async function loadMarkdownFilePromise(post) { return output; } +function encodeDate(dateTime) { + if (settings.custom_date_formatting) { + return dateTime.toFormat(settings.custom_date_formatting); + } else if (settings.include_time_with_date) { + return dateTime.toISO(); + } else { + return dateTime.toISODate(); + } +} + async function writeImageFilesPromise(posts, config) { // collect image data from all posts into a single flattened array of payloads let skipCount = 0;