diff --git a/README.md b/README.md index cfb45ac..94d195f 100644 --- a/README.md +++ b/README.md @@ -24,18 +24,18 @@ To retrieve the rank of a website for a specific keyword, run the `google-rank` $ google-rank wikipedia.org krakatoa Ranks for wikipedia.org website: -1 krakatoa +page 1 rank 1 krakatoa ``` Multiple keywords can also be specified: ``` -$ google-rank wikipedia.org krakatoa mit 'social media' +$ google-rank wikipedia.org krakatoa facebook 'social media' Ranks for wikipedia.org website: -1 krakatoa -2 mit -1 social media +page 1 rank 1 krakatoa +page 2 rank 2 facebook +page 1 rank 1 social media ``` If the website is not found for the specified keywords, it will output the rank as `?`: @@ -44,7 +44,7 @@ If the website is not found for the specified keywords, it will output the rank $ google-rank wikipedia.org 'best city to travel' Ranks for wikipedia.org website: -? best city to travel +page ? rank ? best city to travel ``` ## License diff --git a/lib/google-rank.js b/lib/google-rank.js index 53078c4..46ee7b9 100755 --- a/lib/google-rank.js +++ b/lib/google-rank.js @@ -7,19 +7,27 @@ async function run() { commander_1.program .argument("", "website name") .arguments("") + .option("--max-page ", "maximum page to search for", "3") .parse(); const website = commander_1.program.args[0]; const keywords = commander_1.program.args.slice(1); + const opts = commander_1.program.opts(); + const maxPage = Number.parseInt(opts.maxPage); const rankByKeywords = []; for (const keyword of keywords) { - const prom = (0, utils_1.getWebsiteRank)(website, keyword); + const prom = (0, utils_1.getWebsiteRank)(website, keyword, { maxPage }); rankByKeywords.push([keyword, prom]); } process.stdout.write(`Ranks for ${website} website:\n`); for (const [keyword, prom] of rankByKeywords) { const rank = await prom; - const rankStr = rank !== undefined ? `${rank.rank}` : "?"; - process.stdout.write(`${rankStr} ${keyword}\n`); + if (rank === undefined) { + process.stdout.write(`page ? rank ?`); + } + else { + process.stdout.write(`page ${rank.page + 1} rank ${rank.rank + 1}`); + } + process.stdout.write(` ${keyword}\n`); } } run(); diff --git a/lib/google-rank.js.map b/lib/google-rank.js.map index 7bedda2..3d36e40 100644 --- a/lib/google-rank.js.map +++ b/lib/google-rank.js.map @@ -1 +1 @@ -{"version":3,"file":"google-rank.js","sourceRoot":"","sources":["../src/google-rank.ts"],"names":[],"mappings":";;;AAEA,yCAAoC;AACpC,mCAAsD;AAEtD,KAAK,UAAU,GAAG;IAChB,mBAAO;SACJ,QAAQ,CAAC,WAAW,EAAE,cAAc,CAAC;SACrC,SAAS,CAAC,eAAe,CAAC;SAC1B,KAAK,EAAE,CAAC;IAEX,MAAM,OAAO,GAAG,mBAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAChC,MAAM,QAAQ,GAAG,mBAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEvC,MAAM,cAAc,GAAiD,EAAE,CAAC;IACxE,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;QAC9B,MAAM,IAAI,GAAG,IAAA,sBAAc,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC9C,cAAc,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;KACtC;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,OAAO,aAAa,CAAC,CAAC;IACxD,KAAK,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,cAAc,EAAE;QAC5C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;QACxB,MAAM,OAAO,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;QAC1D,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,IAAI,OAAO,IAAI,CAAC,CAAC;KACjD;AACH,CAAC;AAED,GAAG,EAAE,CAAC"} \ No newline at end of file +{"version":3,"file":"google-rank.js","sourceRoot":"","sources":["../src/google-rank.ts"],"names":[],"mappings":";;;AAEA,yCAAoC;AACpC,mCAAsD;AAEtD,KAAK,UAAU,GAAG;IAChB,mBAAO;SACJ,QAAQ,CAAC,WAAW,EAAE,cAAc,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.ts b/src/google-rank.ts index d72d1cb..2097059 100644 --- a/src/google-rank.ts +++ b/src/google-rank.ts @@ -7,22 +7,30 @@ async function run() { program .argument("", "website name") .arguments("") + .option("--max-page ", "maximum page to search for", "3") .parse(); const website = program.args[0]; const keywords = program.args.slice(1); + const opts = program.opts(); + const maxPage = Number.parseInt(opts.maxPage); + const rankByKeywords: [string, Promise][] = []; for (const keyword of keywords) { - const prom = getWebsiteRank(website, keyword); + const prom = getWebsiteRank(website, keyword, { maxPage }); rankByKeywords.push([keyword, prom]); } process.stdout.write(`Ranks for ${website} website:\n`); for (const [keyword, prom] of rankByKeywords) { const rank = await prom; - const rankStr = rank !== undefined ? `${rank.rank}` : "?"; - process.stdout.write(`${rankStr} ${keyword}\n`); + if (rank === undefined) { + process.stdout.write(`page ? rank ?`); + } else { + process.stdout.write(`page ${rank.page + 1} rank ${rank.rank + 1}`); + } + process.stdout.write(` ${keyword}\n`); } }