Fix date stuff in path building

This commit is contained in:
Will Boyd
2025-02-03 14:47:43 -05:00
parent 7934f4e4b4
commit 71028a272b
3 changed files with 5 additions and 14 deletions
+3 -12
View File
@@ -1,30 +1,21 @@
import * as luxon from 'luxon';
import path from 'path';
import * as settings from './settings.js';
export function buildPostPath(outputDir, type, date, slug, config) {
let dt;
if (settings.custom_date_formatting) {
dt = luxon.DateTime.fromFormat(date, settings.custom_date_formatting);
} else {
dt = luxon.DateTime.fromISO(date);
}
// start with base output dir and post type
const pathSegments = [outputDir, type];
if (config.dateFolders === 'year' || config.dateFolders === 'year-month') {
pathSegments.push(dt.toFormat('yyyy'));
pathSegments.push(date.toFormat('yyyy'));
}
if (config.dateFolders === 'year-month') {
pathSegments.push(dt.toFormat('LL'));
pathSegments.push(date.toFormat('LL'));
}
// create slug fragment, possibly date prefixed
let slugFragment = slug;
if (config.prefixDate) {
slugFragment = dt.toFormat('yyyy-LL-dd') + '-' + slugFragment;
slugFragment = date.toFormat('yyyy-LL-dd') + '-' + slugFragment;
}
// use slug fragment as folder or filename as specified