feat: support path-prefix canonical base URLs in --canonical-origin - #102
Conversation
A canonical like https://prod.com/docs// left a trailing slash in the normalized value, so the rewrite regex silently matched nothing. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…rlap A URL ending exactly at the canonical base wasn't rewritten when an XML closing tag followed, so a sitemap's landing-page entry (<loc>https://prod.example.com/docs</loc>) kept its production URL in path-prefix mode. Add < to the boundary lookahead; a literal < can never appear in a valid URL, so the match is unambiguous. Also warn (without disabling the flag) when the canonical base is a path-prefix of the target base, since URLs in fetched content that already point at the target get re-prefixed by the rewrite.
|
Hey, thanks for the PR Philip! This is a good enhancement, and I appreciate that it fixes a divergence we had between the CLI (which reduced the flag to I did push one follow-up commit (9ebdac8) with two additions found while reviewing:
|
--canonical-originpreviously accepted only an origin, so it worked when production and preview shared the same path structure. But when production docs live under a path prefix (e.g.https://example.com/docs) and the preview serves from a different base, an origin swap produces broken URLs.This PR lets the flag accept an origin plus a path prefix. When a prefix is given, matching URLs in fetched content are rewritten to the full target base instead of just swapping origins.
Along the way this fixes two latent issues in the canonical-origin rewrite itself: a
$in the target URL was interpreted as a replacement pattern, and URLs ending at?,#,), or,(markdown links, prose) weren't matched. The canonical value is also normalized consistently now (trailing slashes, host case, default ports).Verified end to end against a real deploy: a Vercel preview of neon.com/docs scored identically to production with
--canonical-origin https://neon.com/docs.🤖 Generated with Claude Code