Stuff for drafts, handling missing slugs and dates

This commit is contained in:
Will Boyd
2025-02-09 12:21:13 -05:00
parent a645b2bfdc
commit 42d0688654
7 changed files with 53 additions and 28 deletions
+6 -7
View File
@@ -46,7 +46,7 @@ async function writeMarkdownFilesPromise(posts) {
let skipCount = 0;
let delay = 0;
const payloads = posts.flatMap(post => {
const destinationPath = buildPostPath(post);
const destinationPath = shared.buildPostPath(post);
if (checkFile(destinationPath)) {
// already exists, don't need to save again
skipCount++;
@@ -96,9 +96,12 @@ async function loadMarkdownFilePromise(post) {
if (shared.config.quoteDate) {
outputValue = `"${outputValue}"`;
}
} else if (typeof value === 'boolean') {
// output unquoted
outputValue = value.toString();
} else {
// single string value
const escapedValue = (value || '').replace(/"/g, '\\"');
const escapedValue = (value ?? '').replace(/"/g, '\\"');
if (escapedValue.length > 0) {
outputValue = `"${escapedValue}"`;
}
@@ -118,7 +121,7 @@ async function writeImageFilesPromise(posts) {
let skipCount = 0;
let delay = 0;
const payloads = posts.flatMap(post => {
const postPath = buildPostPath(post);
const postPath = shared.buildPostPath(post);
const imagesDir = path.join(path.dirname(postPath), 'images');
return post.imageUrls.flatMap(imageUrl => {
const filename = shared.getFilenameFromUrl(imageUrl);
@@ -185,10 +188,6 @@ async function loadImageFilePromise(imageUrl) {
return buffer;
}
function buildPostPath(post) {
return shared.buildPostPath(post.type, post.date, post.slug);
}
function checkFile(path) {
return fs.existsSync(path);
}