From 9e6d38adc9df0d8713d86a458337cb13e7a24f69 Mon Sep 17 00:00:00 2001 From: Will Boyd Date: Tue, 22 Dec 2020 10:21:44 -0500 Subject: [PATCH] Advanced settings for date and time formatting --- src/parser.js | 11 ++++++++++- src/settings.js | 9 +++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/parser.js b/src/parser.js index 5c87fee..9afecf7 100644 --- a/src/parser.js +++ b/src/parser.js @@ -3,6 +3,7 @@ const luxon = require('luxon'); const xml2js = require('xml2js'); const shared = require('./shared'); +const settings = require('./settings'); const translator = require('./translator'); async function parseFilePromise(config) { @@ -82,7 +83,15 @@ function getPostTitle(post) { } function getPostDate(post) { - return luxon.DateTime.fromRFC2822(post.pubDate[0], { zone: 'utc' }).toISO(); + const dateTime = luxon.DateTime.fromRFC2822(post.pubDate[0], { zone: 'utc' }); + + 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(); + } } function getCategories(post) { diff --git a/src/settings.js b/src/settings.js index 288830c..cad784b 100644 --- a/src/settings.js +++ b/src/settings.js @@ -5,3 +5,12 @@ exports.image_file_request_delay = 500; // time in ms to wait between saving Markdown files // increase this if your file system becomes overloaded exports.markdown_file_write_delay = 25; + +// enable this to include time with post dates +// for example, "2020-12-25" would become "2020-12-25T11:20:35.000Z" +exports.include_time_with_date = false; + +// override post date formatting with a custom formatting string (for example: 'yyyy LLL dd') +// tokens are documented here: https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens +// if set, this takes precedence over include_time_with_date +exports.custom_date_formatting = '';