Repository navigation
Fix .md redirect target for routes.yaml-remapped pages (#30375) - #30700
wakqasahmed wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (17)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📜 Recent review details🧰 Additional context used📚 Code guidelines (2)📓 Path-based instructions (6)Review whether tests prove changed behaviour, meaningful error/edge paths, and externally observable contracts without coupling to implementation details.⚙️ CodeRabbit configuration file Files:
New source files must be TypeScript: flag new JS files as a required change unless exempt (DB migrations, apps/ember-admin/, tool/config files, scripts/, docker/, generated code).⚙️ CodeRabbit configuration file Files:
Review lens: "where does this data become trusted?" Boundary data (HTTP input, external API/SDK responses, env/config, DB/filesystem reads, queue/webhook/event payloads) is `unknown` until validated — Zod by default.⚙️ CodeRabbit configuration file Files:
Prioritise concrete correctness, security, data-integrity, compatibility, and regression risks.⚙️ CodeRabbit configuration file Files:
Source excerpt: Ghost has several test suites across the monorepo.📄 CodeRabbit inference engine (docs/contributing/testing.md) Files:
Source excerpt: Built Admin assets are copied into `ghost/core/core/built/admin/` for the Ghost release.📄 CodeRabbit inference engine (docs/codebase/monorepo-structure.md) Files:
🪛 ast-grep (0.45.3)ghost/core/core/frontend/services/routing/parent-router.js[warning] 117-117: Detects non-literal values in regular expressions (detect-non-literal-regexp) [warning] 117-117: Do not use variable for regular expressions (regexp-non-literal) 🔇 Additional comments (17)
WalkthroughCustom collection and static routes now register Suggested reviewers: Priority: ➖ Normal Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to No merge-blocking issue is established for the custom Markdown routes. Complete normal checks before merging. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The new Markdown URLs reuse existing gift, subscription and payment checks. No introduced access bypass was established, but complete verification of protected-content serialization and all response-cache behavior remains incomplete. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error)
✅ Passed checks (5 passed)
Full details: New Files Are TypescriptExplanation The PR adds
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
302eaf2 to
bacec11
Compare
ref TryGhost#30375 The `<route>.md` controller hand-rolled a Content API call with its own include list; it now reads the entry through the data service, the same path the route's html uses. The mount and redirect logic was duplicated across routers, so it moved onto ParentRouter and also covers channel routes, which had the same broken redirect. A route only gets a markdown URL when its data reads exactly one post or page, so a multi-entry route never serves the wrong entry, and the redirect target and Content-Location now honour a subdirectory for the root route. Gift tokens are stripped like on every other `.md` URL.
ref TryGhost#30375 Routed markdown reuses the regular `.md` gating, so the e2e suite covers a post data entry, a members-only data page and the llms toggle against a real routes.yaml rather than mocks.
bacec11 to
c684b5e
Compare
When a page's URL is remapped by routes.yaml (a collection's `data:` source, or the site root), its `.md` variant redirects to the wrong place. The reporter pointed at the markdown controller, but the actual bug is one level up: `ParentRouter._respectDominantRouter()` builds the dominant-router redirect by appending the unmatched `.md` request path onto the routed directory, so `/contact.md` becomes `/rubrique/contact.md` (404) instead of `/rubrique.md`. For a root-mapped page this produces a redirect to itself instead of a working `/index.md`.
Fixed the dominant-router redirect to use `getMarkdownPath(targetRoute)` when the incoming request is a `.md` path, same as the correct path used for `llms.txt` generation. Also mounted a real `.md` route directly on entry-backed collection/static routes (instead of relying only on the redirect) so the root-page case resolves to a working `/index.md` rather than looping, and threaded the resolved canonical path through so `Content-Location` and the non-llms redirect target stay consistent.
Added e2e coverage with a real routes.yaml fixture covering both cases (collection `data:` remap and root remap). Confirmed both fail on the pre-fix code (`/rubrique/contact.md` 404, self-redirect loop on `/about.md`) and pass after the fix. Ran the broader routing test suite too (55/55 passing) since this touches shared redirect logic.
Closes #30375