Skip to content

Commit

Permalink
the output now actually goes in the output directory
Browse files Browse the repository at this point in the history
  • Loading branch information
justindhillon committed Nov 17, 2023
1 parent 4f24ff1 commit 898f3ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion bin/scan/scanLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
});

Expand Down
8 changes: 5 additions & 3 deletions bin/scan/writeBrokenLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ function isLocalhostUrl(url) {
// data is string
// path is <file/directory path>
// 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);

Expand All @@ -34,7 +36,7 @@ function writeToFile(data, PATH) {
// path is <file/directory path>
// 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 }
Expand All @@ -44,7 +46,7 @@ async function writeBrokenLinks(links, PATH) {
process.exit(1);
}
if (result.status === "dead") {
writeToFile(link, PATH);
writeToFile(link, PATH, fluff);
}
});
}
Expand Down

0 comments on commit 898f3ab

Please sign in to comment.