From 898f3ab8743299a79664ab49be2f815e15ae1713 Mon Sep 17 00:00:00 2001 From: Justin Dhillon Date: Fri, 17 Nov 2023 11:50:26 -0800 Subject: [PATCH] the output now actually goes in the output directory --- bin/scan/scanLinks.js | 6 +++++- bin/scan/writeBrokenLinks.js | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/scan/scanLinks.js b/bin/scan/scanLinks.js index 796e380..97fc446 100755 --- a/bin/scan/scanLinks.js +++ b/bin/scan/scanLinks.js @@ -21,6 +21,10 @@ async function links(path) { } else { filePaths.push(path); } + + const removeSlash = path.replace(/\/$/, ""); + const lastSlashIndex = removeSlash.lastIndexOf('/'); + const fluff = removeSlash.substring(0, lastSlashIndex + 1); filePaths.forEach((filePath) => { // gets content of path @@ -32,7 +36,7 @@ async function links(path) { // if any broken links are found, it writes // them to an "output" folder if (links !== null) { - writeBrokenLinks(links, filePath); + writeBrokenLinks(links, filePath, fluff); } }); diff --git a/bin/scan/writeBrokenLinks.js b/bin/scan/writeBrokenLinks.js index f030e4b..d2f13b0 100644 --- a/bin/scan/writeBrokenLinks.js +++ b/bin/scan/writeBrokenLinks.js @@ -10,7 +10,9 @@ function isLocalhostUrl(url) { // data is string // path is // Writes data to identical path in "output" -function writeToFile(data, PATH) { +function writeToFile(data, PATH, fluff) { + console.log(fluff, PATH); + PATH = PATH.replace(fluff, ''); PATH = "output/" + PATH; const directoryPath = path.dirname(PATH); @@ -34,7 +36,7 @@ function writeToFile(data, PATH) { // path is // If broken links are found, it writes them // in an "output" folder -async function writeBrokenLinks(links, PATH) { +async function writeBrokenLinks(links, PATH, fluff) { for (const link of links) { await new Promise(r => setTimeout(r, 2000)); if (isLocalhostUrl(link)) { continue } @@ -44,7 +46,7 @@ async function writeBrokenLinks(links, PATH) { process.exit(1); } if (result.status === "dead") { - writeToFile(link, PATH); + writeToFile(link, PATH, fluff); } }); }