buildSamplePostPath()

This commit is contained in:
Will Boyd
2025-01-28 08:14:15 -05:00
parent 8d4e7a03fc
commit 1877e43611
3 changed files with 50 additions and 25 deletions
+39
View File
@@ -1,3 +1,42 @@
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'));
}
if (config.dateFolders === 'year-month') {
pathSegments.push(dt.toFormat('LL'));
}
// create slug fragment, possibly date prefixed
let slugFragment = slug;
if (config.prefixDate) {
slugFragment = dt.toFormat('yyyy-LL-dd') + '-' + slugFragment;
}
// use slug fragment as folder or filename as specified
if (config.postFolders) {
pathSegments.push(slugFragment, 'index.md');
} else {
pathSegments.push(slugFragment + '.md');
}
return path.join(...pathSegments);
}
export function getFilenameFromUrl(url) {
let filename = url.split('/').slice(-1)[0];
try {