Problem/Motivation
Currently, the Drupal IndexNow module does not provide a way for users to dynamically alter the IndexNow submission URL and the key location URL. For greater flexibility and customization, especially for advanced use cases, it would be beneficial to introduce a mechanism (like hooks or settings) that allows users to modify these URLs to meet their specific needs.
Proposed resolution
Drupal's hook system, such as hook_indexnow_alter()
Issue fork index_now-3557839
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #6
macsim commentedWhile altering the key location URL could be a good idea, IMHO there's no reason to alter the page_url sent to index_now since it is an absolute URL of the entity.
There was an issue with projects using domains module with a domain per language that has been fixed on 3.1.x-dev #3558253: Error after submitting translation of node
I updated the issue title in that sense + removed the code you wrote about
hook_index_now_page_url_alter()and only kept thehook_index_now_key_location_url_alter()+ updated the testsCan you please apply the patch https://git.drupalcode.org/project/index_now/-/merge_requests/34.diff and tell me if it suits your needs ?
Comment #7
macsim commentedPostpone this issue because I am not sure it is still needed.
I guess you had an issue because you were using domains module + index now and the bug has been fixed in #3558253: Error after submitting translation of node
I would need more information about your use case
Comment #8
macsim commentedThe headless CMS use case described in #3586683: Provide a way to set a custom base URL for the index (headless CMS) is actually a compelling reason to provide a hook for altering the URLs submitted to Index Now - reopening this issue accordingly.
Comment #9
macsim commentedComment #11
macsim commentedManual testing procedure
The unit tests cover the hook invocation logic, but the following smoke test
verifies the full integration in a real Drupal instance.
Prerequisites
search engine selected)
/admin/config/services/index_nowsosubmissions appear in the logs
Step 1 — Implement the hook in a custom module
Create a file
my_test.modulein a temporary custom module andadd the following:
Step 2 — Trigger a ping
Save any existing node. Index Now should submit its URL to the configured
search engine.
Step 3 — Check the logs
Go to
/admin/reports/dblogand filter by typemy_test. Verify that:node:<id>(entity iscorrectly passed in context)
Also check the
index_nowlog entries to confirm the URLsubmitted to the search engine matches what the hook returned.
Step 4 — Test
hook_index_now_key_location_url_alter(optional)
Add a second implementation to the same module:
Save a node again and verify the log entry shows the expected key location
URL (should match
$settings['index_now.base_url']if configured,or the Drupal site URL otherwise).
Comment #12
macsim commentedComment #15
macsim commented