Skip to content

Commit

Permalink
now allowing for "complex" article file names
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffschwartz committed Dec 31, 2018
1 parent 516579b commit 5e58cbc
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/metadata/getPublicDestPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
};

Expand Down

0 comments on commit 5e58cbc

Please sign in to comment.