alphagov / smart-answers

Serves smart answers on GOV.UK
https://docs.publishing.service.gov.uk/apps/smart-answers.html
MIT License
176 stars 120 forks source link

Set the canonical URL for the marriage-abroad SA #6758

Closed mtaylorgds closed 6 months ago

mtaylorgds commented 6 months ago

During the migration of this Smart Answer to FCDO, its start page is now a duplicate of the newly-created one in Mainstream Publisher. To aid search engines in resolving this, set a "canonical URL" link in the Smart Answer start page to that of the Mainstream Publisher-managed one.

Since we don't have access to the "content ID" within the start page (landing) template, use the slug to identify when it is being rendered for the marriage abroad Smart Answer.

The setting of a canonical_url variable, which is then passed to the render calls of the machine_readable_metadata component, is necessary, as if that variable is "inlined" no canonical URL link tag appears in the generated HTML.

This is a temporary hack—once the migration is complete (expected to be in approximately 6–8 weeks), the marriage abroad Smart Answer will be retired and then this change should be reverted.

I haven't identified a way to write a test for this change, which is why there aren't any tests.

Trello ticket

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

Follow these steps if you are doing a Rails upgrade.