commit 0d1548d501250b1ee4795cf010d4e5f04a67c3ba parent 76c82f7b1b7b3da8b2984d36dec37e9c3fbda8c9 Author: Demonstrandum <moi@knutsen.co> Date: Thu, 19 Mar 2020 21:12:06 +0000 Give nth result of search, exclude number at end. Diffstat:
M | lib/api/google.ts | | | 4 | +++- |
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/lib/api/google.ts b/lib/api/google.ts @@ -38,7 +38,9 @@ const web_search = (param : CSE) => new Promise((resolve, reject) => { } const num_match = param.query.trim().match(/[ ]+(\d+)$/); - const result_index = Math.abs(num_match ? Number(num_match[1]) - 1 : 0); + if (num_match) + param.query = param.query.slice(0, -num_match[1].length).trim(); + const result_index = Math.abs(num_match ? Number(num_match[1]) - 1 : 0) % 10; const cs = google.customsearch('v1'); cs.cse.list({