feat(marketing): add agent-friendly page representations - #39
Conversation
|
no API key found — this repo is configured to use To fix: add the key as a GitHub Actions secret (referenced from your workflow's Open repo secrets → · Configure model → · Setup docs → · Ask in Discord →
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (10)
🚧 Files skipped from review as they are similar to previous changes (5)
📝 WalkthroughWalkthroughAdds localized Markdown homepage and sitemap endpoints, centralized public route metadata, Accept negotiation for HTML, XML, and Markdown responses, and a ChangesMarkdown content negotiation
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant proxy
participant negotiateContentType
participant MarkdownHomeRoute
participant SitemapRoute
Client->>proxy: Request homepage or sitemap with Accept
proxy->>negotiateContentType: Select supported media type
negotiateContentType-->>proxy: Return HTML, XML, Markdown, or null
proxy->>MarkdownHomeRoute: Rewrite localized Markdown homepage request
proxy->>SitemapRoute: Route sitemap representation request
proxy-->>Client: Return negotiated response or 406 response
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThe PR adds negotiated Markdown representations for localized homepages and the sitemap while retaining HTML and XML defaults.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; both previously reported representation issues are fixed in the current code.
|
| Filename | Overview |
|---|---|
| proxy.ts | Adds content negotiation, RSC bypass, representation rewrites, 406 handling, and Vary: Accept; the prior text/xml rejection is fixed. |
| app/[locale]/page.tsx | Adds a localized Markdown alternate that now targets the dedicated homepage Markdown route. |
| app/api/markdown/home/[[...locale]]/route.ts | Serves validated English and Spanish homepage Markdown with explicit caching and content-type headers. |
| lib/common/accept.ts | Implements media-range parsing and deterministic negotiation by specificity, quality, and header position. |
| lib/marketing/site-map.ts | Centralizes public sitemap entries and safely renders escaped XML output. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Homepage or sitemap request] --> B{RSC request?}
B -->|Yes| C[Continue to page renderer]
B -->|No| D[Negotiate Accept header]
D -->|Markdown| E[Rewrite to Markdown API route]
D -->|text/xml sitemap| F[Rewrite to sitemap API route]
D -->|HTML or application/xml| G[Continue to default renderer]
D -->|No acceptable type| H[Return 406]
Reviews (4): Last reviewed commit: "refactor(marketing): simplify agent-frie..." | Re-trigger Greptile
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
proxy.ts (1)
15-64: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider splitting the negotiation branch out of
proxy.
proxycurrently handles RSC detection, Accept negotiation dispatch, Markdown rewrite construction, sitemap passthrough, andgtMiddlewaredelegation in one function. Static analysis flags this range as high complexity. Extracting the negotiation block (lines 28-56) into a named helper, such asresolveDocumentRepresentation(request, isHomepage, isSitemap)returning either aResponseornull(meaning "fall through togtMiddleware"), would keepproxyitself limited to routing dispatch and improve testability of the negotiation branch in isolation.As per coding guidelines, "Keep functions small, self-contained, and limited to a single named responsibility."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@proxy.ts` around lines 15 - 64, Extract the Accept negotiation logic from proxy into a named helper such as resolveDocumentRepresentation(request, isHomepage, isSitemap), including media-type negotiation, Markdown rewrite construction, sitemap passthrough, and Not Acceptable responses. Have the helper return a Response for handled representations or null to indicate fall-through, while keeping RSC detection and gtMiddleware delegation in proxy.Sources: Coding guidelines, Linters/SAST tools
lib/common/accept.test.ts (1)
1-108: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd tests for case-insensitive Accept values and duplicate-type quality handling.
The suite covers quality precedence, specificity, wildcards, and defaults well. Two edge cases used by this critical routing path are not covered:
- Mixed-case media types in the
Acceptheader (e.g."TEXT/HTML").- Duplicate entries for the same type with different
qvalues (e.g."text/html;q=0.2, text/html;q=0.9"), wherenegotiateContentTypecurrently keeps the first-declared entry for a given specificity level rather than the highest-quality one.Since this module decides every homepage/sitemap response representation and drives 406 responses, adding these cases locks in current behavior and catches future regressions cheaply.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/common/accept.test.ts` around lines 1 - 108, Add tests under the negotiateContentType suite for case-insensitive media-type matching, such as a mixed-case TEXT/HTML Accept value, and for duplicate entries of the same media type with differing q values. Assert that matching ignores case and duplicate entries select the highest quality value, using the existing SUPPORTED_TYPES and default arguments.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/api/markdown/home/`[[...locale]]/route.ts:
- Around line 81-87: Update the locale handling in the route’s request function
to validate the complete optional locale array with a Zod v4 schema derived from
SUPPORTED_LOCALES. Accept only no locale or one supported locale segment, reject
unsupported locales and extra segments with a 404 Response, and select
HOME_MARKDOWN using the validated locale while preserving the default en-US
behavior.
In `@proxy.ts`:
- Around line 80-98: Normalize the locale segment in both isHomepagePath and
getHomepageLocale by removing a trailing slash from pathname.slice(1) before
comparing it with SUPPORTED_LOCALES. Preserve the root-path handling and
DEFAULT_LOCALE fallback, while ensuring paths such as /en-US/ resolve to the
same locale as /en-US.
---
Nitpick comments:
In `@lib/common/accept.test.ts`:
- Around line 1-108: Add tests under the negotiateContentType suite for
case-insensitive media-type matching, such as a mixed-case TEXT/HTML Accept
value, and for duplicate entries of the same media type with differing q values.
Assert that matching ignores case and duplicate entries select the highest
quality value, using the existing SUPPORTED_TYPES and default arguments.
In `@proxy.ts`:
- Around line 15-64: Extract the Accept negotiation logic from proxy into a
named helper such as resolveDocumentRepresentation(request, isHomepage,
isSitemap), including media-type negotiation, Markdown rewrite construction,
sitemap passthrough, and Not Acceptable responses. Have the helper return a
Response for handled representations or null to indicate fall-through, while
keeping RSC detection and gtMiddleware delegation in proxy.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4db8ab95-e50d-403f-ae3e-3c671a0a68a2
📒 Files selected for processing (8)
app/[locale]/page.tsxapp/api/markdown/home/[[...locale]]/route.tsapp/api/markdown/sitemap/route.tsapp/sitemap.tslib/common/accept.test.tslib/common/accept.tslib/marketing/site-map.tsproxy.ts
|
no API key found — this repo is configured to use To fix: add the key as a GitHub Actions secret (referenced from your workflow's Open repo secrets → · Configure model → · Setup docs → · Ask in Discord →
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/marketing/site-map.ts`:
- Around line 74-92: The buildPublicSitemapEntries function currently assigns a
new Date on every sitemap request, making every route appear freshly modified.
Replace this per-call timestamp with real per-route modification dates from
PUBLIC_STATIC_ROUTES, or otherwise reuse a single stable module-level timestamp
across calls while preserving each entry’s lastModified field.
In `@proxy.ts`:
- Around line 95-98: Update createNotAcceptableResponse to derive availableTypes
from the same SITEMAP_MEDIA_TYPES or HOMEPAGE_MEDIA_TYPES arrays used by
negotiateContentType, joining the selected array into the response string so the
406 message stays synchronized when supported media types change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: dd615e61-b11f-4912-a279-1eefba505da7
📒 Files selected for processing (10)
app/[locale]/page.tsxapp/api/markdown/home/[[...locale]]/route.test.tsapp/api/markdown/home/[[...locale]]/route.tsapp/api/sitemap/route.test.tsapp/api/sitemap/route.tsapp/sitemap.tslib/common/accept.test.tslib/common/accept.tslib/marketing/site-map.tsproxy.ts
🚧 Files skipped from review as they are similar to previous changes (2)
- lib/common/accept.test.ts
- app/[locale]/page.tsx
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
|
no API key found — this repo is configured to use To fix: add the key as a GitHub Actions secret (referenced from your workflow's Open repo secrets → · Configure model → · Setup docs → · Ask in Discord →
|
|
no API key found — this repo is configured to use To fix: add the key as a GitHub Actions secret (referenced from your workflow's Open repo secrets → · Configure model → · Setup docs → · Ask in Discord →
|

Summary
Validation
Summary by CodeRabbit
New Features
Bug Fixes