Repository navigation
Keep the canonical URL and og:url after the Notion client loads - #194
Merged
Merged
Conversation
The Notion client rewrites link[rel=canonical], og:url and twitter:url to its own relative /Title-<id> path after load, on every page. The client script already restored the configured titles and descriptions; it now also keeps these three tags on the URL the worker chose: the slug for mapped pages, the page ID for pages without one. The render check verifies this in the browser. Closes #193 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #193.
After it loads, the Notion client rewrites
link[rel=canonical],og:urlandtwitter:urlto its own relative/<Title>-<page-id>path, on every page. It adds a#blockfragment after anchor clicks. The client script already kept the configured title and description after Notion changed them (applyMeta, #146). It now also keeps these three tags on the URL the worker chose:/<slug>for mapped pages;/<page-id>for pages without a slug, as on the server since Give pages without a slug their own canonical URL #192.Changes:
CLIENT_METAgetsorigin: 'https://' + MY_DOMAIN. The value is passed as JSON instead of being written into the script as a string.setContenttakes the attribute to set, so it can also sethref. It now updates every matching tag, not just the first, in case Notion adds a second one.applyMetacomputes the canonical path with the same rules as the server and sets the three tags.MutationObserveralso watcheshrefchanges.canonical urlcheck. In the browser, after the page loads, the canonical URL must be on the site's own origin and point to the root page, andog:urlmust resolve to the same URL.Verification
npm test: 25 tests pass. This change is in the browser script, so it is covered by the render check and a Chromium comparison instead.In
wrangler devagainst the live render check page, read in Chromium 10 s after load://Worknot-Render-Check-<id>(relative)https://render-check.example.com/subpage/Render-Check-Subpage-<id>(relative)https://render-check.example.com/subpage/<item-id>(no slug)/Item-Beta-<id>(relative)https://render-check.example.com/<item-id>The values shown are for
link[rel=canonical].og:urlandtwitter:urlhad the same values in each case. The head had 0 attribute changes in the 3 s after the page settled, so the worker and the Notion client don't keep rewriting each other's values.npm run check:render:canonical urlpasses, and no check is FAIL.canonical urlis FAIL (canonical: /Worknot-Render-Check-<id>#<block>). It passes on notion.site, so the check catches this regression.Not tested: switching pages inside the Notion app. The subpage link on the test page doesn't load on notion.site either (the navigation checks are
NOTION). The fix uses the sameMutationObserverpath as the title handling, which runs whenever Notion updates the head.