77 getPageIndexingStatus ,
88 convertToFilePath ,
99 checkSiteUrl ,
10+ checkCustomUrls ,
1011} from "./shared/gsc" ;
1112import { getSitemapPages } from "./shared/sitemap" ;
1213import { Status } from "./shared/types" ;
@@ -26,6 +27,7 @@ export type IndexOptions = {
2627 client_email ?: string ;
2728 private_key ?: string ;
2829 path ?: string ;
30+ urls ?: string [ ] ;
2931 quota ?: {
3032 rpmRetry ?: boolean ; // read requests per minute: retry after waiting time
3133 } ;
@@ -53,6 +55,9 @@ export const index = async (input: string = process.argv[2], options: IndexOptio
5355 if ( ! options . path ) {
5456 options . path = args [ "path" ] || process . env . GIS_PATH ;
5557 }
58+ if ( ! options . urls ) {
59+ options . urls = args [ "urls" ] ? args [ "urls" ] . split ( "," ) : undefined ;
60+ }
5661 if ( ! options . quota ) {
5762 options . quota = {
5863 rpmRetry : args [ "rpm-retry" ] === "true" || process . env . GIS_QUOTA_RPM_RETRY === "true" ,
@@ -72,15 +77,24 @@ export const index = async (input: string = process.argv[2], options: IndexOptio
7277
7378 siteUrl = await checkSiteUrl ( accessToken , siteUrl ) ;
7479
75- const [ sitemaps , pages ] = await getSitemapPages ( accessToken , siteUrl ) ;
80+ let pages = options . urls || [ ] ;
81+ if ( pages . length === 0 ) {
82+ console . log ( `🔎 Fetching sitemaps and pages...` ) ;
83+ const [ sitemaps , pagesFromSitemaps ] = await getSitemapPages ( accessToken , siteUrl ) ;
7684
77- if ( sitemaps . length === 0 ) {
78- console . error ( "❌ No sitemaps found, add them to Google Search Console and try again." ) ;
79- console . error ( "" ) ;
80- process . exit ( 1 ) ;
81- }
85+ if ( sitemaps . length === 0 ) {
86+ console . error ( "❌ No sitemaps found, add them to Google Search Console and try again." ) ;
87+ console . error ( "" ) ;
88+ process . exit ( 1 ) ;
89+ }
90+
91+ pages = pagesFromSitemaps ;
8292
83- console . log ( `👉 Found ${ pages . length } URLs in ${ sitemaps . length } sitemap` ) ;
93+ console . log ( `👉 Found ${ pages . length } URLs in ${ sitemaps . length } sitemap` ) ;
94+ } else {
95+ pages = checkCustomUrls ( siteUrl , pages ) ;
96+ console . log ( `👉 Found ${ pages . length } URLs in the provided list` ) ;
97+ }
8498
8599 const statusPerUrl : Record < string , { status : Status ; lastCheckedAt : string } > = existsSync ( cachePath )
86100 ? JSON . parse ( readFileSync ( cachePath , "utf8" ) )
@@ -109,7 +123,7 @@ export const index = async (input: string = process.argv[2], options: IndexOptio
109123 const shouldRecheck = ( status : Status , lastCheckedAt : string ) => {
110124 const shouldIndexIt = indexableStatuses . includes ( status ) ;
111125 const isOld = new Date ( lastCheckedAt ) < new Date ( Date . now ( ) - CACHE_TIMEOUT ) ;
112- return shouldIndexIt && isOld ; ;
126+ return shouldIndexIt && isOld ;
113127 } ;
114128
115129 await batch (
0 commit comments