-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5,386 changed files
with
361,333 additions
and
376,959 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,4 @@ | |
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": { | ||
"onlyUpdatePeerDependentsWhenOutOfRange": true | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,81 @@ | ||
const getUrlToCheck = (currentUrl, deploymentUrl) => { | ||
const url = new URL(currentUrl); | ||
url.hostname = new URL(deploymentUrl).hostname; | ||
return url.toString(); | ||
const url = new URL(currentUrl); | ||
url.hostname = new URL(deploymentUrl).hostname; | ||
return url.toString(); | ||
}; | ||
|
||
const checkUrl = async (url) => { | ||
const { status } = await fetch(url, { | ||
method: "GET", | ||
}); | ||
return [status, new URL(url).pathname]; | ||
const { status } = await fetch(url, { | ||
method: "GET", | ||
}); | ||
return [status, new URL(url).pathname]; | ||
}; | ||
|
||
const toChunks = (array, chunkSize) => { | ||
const chunks = []; | ||
for (let i = 0; i < array.length; i += chunkSize) { | ||
chunks.push(array.slice(i, i + chunkSize)); | ||
} | ||
return chunks; | ||
const chunks = []; | ||
for (let i = 0; i < array.length; i += chunkSize) { | ||
chunks.push(array.slice(i, i + chunkSize)); | ||
} | ||
return chunks; | ||
}; | ||
|
||
const checkChunk = (chunk, deploymentUrl, success, fail) => { | ||
return new Promise((resolve) => { | ||
const promises = chunk.map((url) => { | ||
return checkUrl(getUrlToCheck(url, deploymentUrl)); | ||
}); | ||
return new Promise((resolve) => { | ||
const promises = chunk.map((url) => { | ||
return checkUrl(getUrlToCheck(url, deploymentUrl)); | ||
}); | ||
|
||
Promise.all(promises).then((results) => { | ||
results.forEach(([status, url]) => { | ||
if (status === 200) { | ||
success.push(url); | ||
} else { | ||
fail.push(url); | ||
} | ||
}); | ||
resolve(); | ||
}); | ||
Promise.all(promises).then((results) => { | ||
results.forEach(([status, url]) => { | ||
if (status === 200) { | ||
success.push(url); | ||
} else { | ||
fail.push(url); | ||
} | ||
}); | ||
resolve(); | ||
}); | ||
}); | ||
}; | ||
|
||
const checkExistingLinks = async (sitemapUrl, deploymentUrl) => { | ||
const data = await (await fetch(sitemapUrl)).text(); | ||
const data = await (await fetch(sitemapUrl)).text(); | ||
|
||
const urls = data.match(/<loc>(.*?)<\/loc>/g).map((loc) => { | ||
return loc.replace("<loc>", "").replace("</loc>", ""); | ||
}); | ||
const urls = data.match(/<loc>(.*?)<\/loc>/g).map((loc) => { | ||
return loc.replace("<loc>", "").replace("</loc>", ""); | ||
}); | ||
|
||
let success = []; | ||
let fail = []; | ||
let success = []; | ||
let fail = []; | ||
|
||
console.log("Checking for existing urls in:", sitemapUrl); | ||
console.log("Deployment url:", deploymentUrl); | ||
console.log("Checking for existing urls in:", sitemapUrl); | ||
console.log("Deployment url:", deploymentUrl); | ||
|
||
const chunks = toChunks(urls, 10); | ||
const chunks = toChunks(urls, 10); | ||
|
||
let done = 0; | ||
let done = 0; | ||
|
||
for (const chunk of chunks) { | ||
console.log(`Checking chunk ${done + 1}/${chunks.length}`); | ||
done++; | ||
await checkChunk(chunk, deploymentUrl, success, fail); | ||
} | ||
for (const chunk of chunks) { | ||
console.log(`Checking chunk ${done + 1}/${chunks.length}`); | ||
done++; | ||
await checkChunk(chunk, deploymentUrl, success, fail); | ||
} | ||
|
||
if (fail.length > 0) { | ||
console.log("Broken links:"); | ||
fail.forEach((link) => { | ||
console.log(link); | ||
}); | ||
process.exit(1); | ||
} | ||
if (fail.length > 0) { | ||
console.log("Broken links:"); | ||
fail.forEach((link) => { | ||
console.log(link); | ||
}); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
if (!process.env.DEPLOY_URL) { | ||
console.log("DEPLOY_URL is not defined"); | ||
process.exit(1); | ||
console.log("DEPLOY_URL is not defined"); | ||
process.exit(1); | ||
} | ||
|
||
checkExistingLinks( | ||
process.env.SITEMAP_URL ?? "https://refine.dev/sitemap.xml", | ||
process.env.DEPLOY_URL, | ||
process.env.SITEMAP_URL ?? "https://refine.dev/sitemap.xml", | ||
process.env.DEPLOY_URL, | ||
); |
Oops, something went wrong.