From 67e15e1fee8cf6ef3d1a614f73ca0a6c708b149b Mon Sep 17 00:00:00 2001 From: songtianlun Date: Tue, 8 Apr 2025 14:29:13 +0800 Subject: [PATCH] feat: enhance submit_urls method to include host - Updated submit_urls method to accept a host parameter. - Modified the submit_urls call in each_slice to pass the host. - Added keyLocation to the data hash using the host. This change allows for more flexible URL submissions with hosts specific to the IndexNow API requirements. The host is now a parameter, improving the configurability of the submit process. --- app/workers/submit_to_indexnow_worker.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/workers/submit_to_indexnow_worker.rb b/app/workers/submit_to_indexnow_worker.rb index 3da6d3c..090edb3 100644 --- a/app/workers/submit_to_indexnow_worker.rb +++ b/app/workers/submit_to_indexnow_worker.rb @@ -33,7 +33,7 @@ class SubmitToIndexnowWorker # 分批提交 URLs (每批最多 10000 个 URLs,符合 IndexNow 限制) urls.each_slice(100) do |url_batch| - submit_urls(url_batch) + submit_urls(url_batch, @host) end Rails.logger.info "Successfully submitted #{urls.size} URLs to IndexNow" @@ -96,8 +96,9 @@ class SubmitToIndexnowWorker urls.uniq end - def submit_urls(urls) + def submit_urls(urls, host) return if urls.empty? + return if host.empty? # 随机选择一个 IndexNow 端点 endpoint = INDEXNOW_ENDPOINTS.sample @@ -106,6 +107,7 @@ class SubmitToIndexnowWorker data = { host: URI.parse(@host).host, key: INDEXNOW_KEY, + keyLocation: "#{host}/#{INDEXNOW_KEY}.txt", urlList: urls }