Fix Markdown content negotiation#528
Conversation
✅ Deploy Preview for zero-to-nix ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughStart-route slug derivation now uses ChangesStart-route slug refactor
Markdown negotiation, plain-text SEO, and deps
Sequence DiagramsequenceDiagram
autonumber
actor Page
participant Layout
participant Head
participant Utils
Page->>Layout: render(title, description, markdownNegotiation)
Layout->>Head: render(title, description, markdownNegotiation)
Head->>Utils: plainText(description) (async)
Utils-->>Head: plainDescription
Head->>Head: set SEO metadata (description/twitter) using plainDescription
alt markdownNegotiation true
Head->>Head: emit <link rel="alternate" type="text/markdown" href="{canonical}.md">
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@src/components/Head.astro`:
- Around line 80-83: The alternate markdown link currently uses
`${canonical.href}.md` which can produce a double-slash if canonical.href ends
with a trailing slash; update the Head.astro logic that renders the alternate
link (the markdownNegotiation conditional) to derive the markdown URL from
canonical.pathname with trailing slash removed (e.g., use
canonical.pathname.replace(/\/$/, "") and then append ".md") so the generated
href is normalized and safe regardless of trailingSlash config or atypical
deployments.
🪄 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
Run ID: 8a006a81-08a4-422b-a16d-3074fad5a76a
📒 Files selected for processing (4)
src/components/Head.astrosrc/layouts/Layout.astrosrc/pages/concepts/[slug].astrosrc/pages/start/[slug].astro
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 `@src/components/Head.astro`:
- Around line 80-83: The alternate link object in Head.astro (the entry with
rel: "alternate" and href:
`${canonical.origin}${canonical.pathname.replace(/\/$/, "")}.md`) needs a MIME
type for markdown; add a property `type: "text/markdown"` to that link object so
the alternate-representation discovery explicitly declares the content type.
- Around line 22-24: plainDescription can become an empty string after await
plainText(description) and trim(), which will produce a blank meta description;
change the logic around plainDescription (the const declaration that uses
description, plainText, and siteDescription) to check the trimmed result and if
it's falsy/empty fallback to siteDescription (i.e., compute const stripped =
description ? (await plainText(description)).trim() : ""; then set const
plainDescription = stripped || siteDescription) so empty markdown-stripped
descriptions use siteDescription instead of emitting a blank.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
| const plainDescription = description | ||
| ? (await plainText(description)).trim() | ||
| : siteDescription; |
There was a problem hiding this comment.
Fallback if stripped markdown description is empty.
After markdown removal and trim, the result can be empty; this would emit a blank meta description. Please fallback to siteDescription in that case.
Proposed fix
-const plainDescription = description
- ? (await plainText(description)).trim()
- : siteDescription;
+const plainDescription = description
+ ? (await plainText(description)).trim() || siteDescription
+ : siteDescription;🤖 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 `@src/components/Head.astro` around lines 22 - 24, plainDescription can become
an empty string after await plainText(description) and trim(), which will
produce a blank meta description; change the logic around plainDescription (the
const declaration that uses description, plainText, and siteDescription) to
check the trimmed result and if it's falsy/empty fallback to siteDescription
(i.e., compute const stripped = description ? (await
plainText(description)).trim() : ""; then set const plainDescription = stripped
|| siteDescription) so empty markdown-stripped descriptions use siteDescription
instead of emitting a blank.
| { | ||
| rel: "alternate", | ||
| href: `${canonical.origin}${canonical.pathname.replace(/\/$/, "")}.md`, | ||
| }, |
There was a problem hiding this comment.
Add MIME type to the markdown alternate link.
For alternate-representation discovery, include type: "text/markdown" on the link entry.
Proposed fix
{
rel: "alternate",
+ type: "text/markdown",
href: `${canonical.origin}${canonical.pathname.replace(/\/$/, "")}.md`,
},📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| { | |
| rel: "alternate", | |
| href: `${canonical.origin}${canonical.pathname.replace(/\/$/, "")}.md`, | |
| }, | |
| { | |
| rel: "alternate", | |
| type: "text/markdown", | |
| href: `${canonical.origin}${canonical.pathname.replace(/\/$/, "")}.md`, | |
| }, |
🤖 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 `@src/components/Head.astro` around lines 80 - 83, The alternate link object in
Head.astro (the entry with rel: "alternate" and href:
`${canonical.origin}${canonical.pathname.replace(/\/$/, "")}.md`) needs a MIME
type for markdown; add a property `type: "text/markdown"` to that link object so
the alternate-representation discovery explicitly declares the content type.
Summary by CodeRabbit
New Feature
Enhancement
Refactor