Skip to content

Instantly share code, notes, and snippets.

@BobD
Last active October 28, 2021 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BobD/933624b93caf605965efea864f2b01fe to your computer and use it in GitHub Desktop.
Save BobD/933624b93caf605965efea864f2b01fe to your computer and use it in GitHub Desktop.
const { exec } = require("child_process");
const inputChunks = [];
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", (chunk) => inputChunks.push(chunk));
process.stdin.on("end", function () {
const inputJSON = inputChunks.join("");
const prismicData = JSON.parse(inputJSON);
const curlCommand = getCurlToDownloadAllImages(prismicData);
exec(curlCommand);
});
function getCurlToDownloadAllImages(data) {
const { results: entries } = data;
const allImageUrls = [];
for (const entry of entries) {
const {
data: {
image: { url },
},
} = entry;
if (!url) {
continue;
}
allImageUrls.push(url.slice(0, url.indexOf("?auto=compress,format")));
}
return `curl ${[...new Set(allImageUrls)]
.map((url) => ` -O ${url}`)
.join("")}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment