From 5e58cbcd1ae0b156ad640dc40f39c56ea28e3ece Mon Sep 17 00:00:00 2001 From: Jeff Schwartz Date: Mon, 31 Dec 2018 15:39:37 -0500 Subject: [PATCH] now allowing for "complex" article file names --- lib/metadata/getPublicDestPath.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/metadata/getPublicDestPath.js b/lib/metadata/getPublicDestPath.js index 34c9865..fafa068 100644 --- a/lib/metadata/getPublicDestPath.js +++ b/lib/metadata/getPublicDestPath.js @@ -13,16 +13,26 @@ const showBadDateMessage = articleFileName => { const getArticleDestPath = articleFileName => { articleFileName = normalizeArticleFileName(articleFileName); - const parts = articleFileName.split("-"); + + // validate article file name matches expected pattern + const found = /(\d{4})-(\d{2})-(\d{2})/.test(articleFileName.substring(0, 10)); + if (!found) { + showBadDateMessage(articleFileName); + process.exit(); + } + + // validate article file name date + const parts = articleFileName.substring(0, 10).split("-"); const yyyy = Number(parts[0]); const mm = Number(parts[1]); const dd = Number(parts[2]); - const fileName = parts[3]; - if (isNaN(yyyy) || isNaN(mm) || isNaN(dd) || !isDateValid(mm, dd, yyyy)) { showBadDateMessage(articleFileName); process.exit(); } + + // return the article's destination path + const fileName = articleFileName.substring(11); return `${yyyy}${sep}${prefaceMMDDWithZero(mm.toString())}${sep}${prefaceMMDDWithZero(dd.toString())}${sep}${parse(fileName).name}${sep}index.html`; };