diff --git a/.changeset/early-pigs-poke.md b/.changeset/early-pigs-poke.md new file mode 100644 index 0000000..c5da829 --- /dev/null +++ b/.changeset/early-pigs-poke.md @@ -0,0 +1,5 @@ +--- +"google-indexing-script": minor +--- + +Shuffle indexablePages to prevent using API quota on checking the same pages over and over again diff --git a/src/index.ts b/src/index.ts index abd6a4b..ab367e8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,6 +31,14 @@ export type IndexOptions = { }; }; +function shuffleArray(array: unknown[]) { + for (let i = array.length - 1; i > 0; i--) { + const j = Math.floor(Math.random() * (i + 1)); + [array[i], array[j]] = [array[j], array[i]]; + } + return array; +} + /** * Indexes the specified domain or site URL. * @param input - The domain or site URL to index. @@ -146,6 +154,8 @@ export const index = async (input: string = process.argv[2], options: IndexOptio indexableStatuses.includes(status as Status) ? pages : [] ); + shuffleArray(indexablePages); + if (indexablePages.length === 0) { console.log(`✨ There are no pages that can be indexed. Everything is already indexed!`); } else {