Change when date is formatted

This commit is contained in:
Will Boyd
2025-02-03 14:27:37 -05:00
parent 8a25175c73
commit 7934f4e4b4
4 changed files with 31 additions and 29 deletions
+7 -12
View File
@@ -3,6 +3,7 @@ import chalk from 'chalk';
import fs from 'fs';
import http from 'http';
import https from 'https';
import * as luxon from 'luxon';
import path from 'path';
import * as shared from './shared.js';
@@ -71,7 +72,7 @@ async function writeMarkdownFilesPromise(posts, config) {
}
}
async function loadMarkdownFilePromise(post) {
async function loadMarkdownFilePromise(post, config) {
let output = '---\n';
Object.entries(post.frontmatter).forEach(([key, value]) => {
@@ -82,7 +83,11 @@ async function loadMarkdownFilePromise(post) {
outputValue = value.reduce((list, item) => `${list}\n - "${item}"`, '');
}
} else if (value instanceof luxon.DateTime) {
outputValue = encodeDate(value);
if (config.customDateFormatting) {
outputValue = value.toFormat(config.customDateFormatting);
} else {
outputValue = config.includeTimeWithDate ? value.toISO() : value.toISODate();
}
} else {
// single string value
const escapedValue = (value || '').replace(/"/g, '\\"');
@@ -100,16 +105,6 @@ 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;