Skip to content

Commit

Permalink
Merge pull request #15 from justindhillon/fix-output-directory
Browse files Browse the repository at this point in the history
 Files now go in output folder
justindhillon authored Nov 17, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents bca71a4 + 898f3ab commit fedb8d2
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
@@ -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);
}
});

8 changes: 5 additions & 3 deletions bin/scan/writeBrokenLinks.js
Original file line number Diff line number Diff line change
@@ -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);

@@ -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 }
@@ -44,7 +46,7 @@ async function writeBrokenLinks(links, PATH) {
process.exit(1);
}
if (result.status === "dead") {
writeToFile(link, PATH);
writeToFile(link, PATH, fluff);
}
});
}

0 comments on commit fedb8d2

Please sign in to comment.