Skip to content

fix .md urls not rendering partials#2776

Merged
atharvadeosthale merged 2 commits intomainfrom
fix-md-docs-partials
Mar 2, 2026
Merged

fix .md urls not rendering partials#2776
atharvadeosthale merged 2 commits intomainfrom
fix-md-docs-partials

Conversation

@atharvadeosthale
Copy link
Member

@atharvadeosthale atharvadeosthale commented Mar 2, 2026

Summary by CodeRabbit

  • New Features
    • Markdown pages can now include reusable content blocks via a simple marker syntax; included blocks are expanded when pages are served, making it easier to compose and maintain shared content.
    • Included partials are handled automatically during page generation, so rendered pages show the expanded content without extra steps.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0e640c and 4db74d5.

📒 Files selected for processing (1)
  • src/lib/server/markdown.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/server/markdown.ts

Walkthrough

Adds an exported async function processMarkdownWithPartials(content: string): Promise<string> that scans Markdown for {% partial file="..." /%} markers, reads corresponding files from src/partials/, replaces markers with file contents, and caches partial contents in a per-process cache. Integrates the processor into request handling by importing and applying processMarkdownWithPartials in src/hooks.server.ts so Markdown fetched for a route is processed before forming the Response.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding partial rendering functionality to markdown files served via direct .md URLs.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-md-docs-partials

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/lib/server/markdown.ts`:
- Line 24: The catch clause currently declares an unused exception variable `e`
(catch (e) { ... }); update the catch to either remove the binding (use `catch {
... }`) or rename it to `_e` to signal intentional discard (e.g., `catch (_e) {
... }`) so ESLint no longer flags it; change the catch header in the same block
where `catch (e)` appears in markdown.ts and keep the existing catch body
unchanged.
- Line 31: The current use of result.replace(fullMatch, partialContent) only
replaces the first occurrence of the partial marker; change it to replace all
occurrences by using result = result.replaceAll(fullMatch, partialContent) or,
if you need broader compatibility/partial contains regex chars, build a global
regex with an escaped fullMatch (e.g. new RegExp(escapeRegExp(fullMatch), 'g'))
and use result = result.replace(regex, partialContent); update the line that
references fullMatch and partialContent in markdown.ts accordingly.
- Around line 19-23: The code reads partials using partialsCache, partialFile
and partialsDir without validating the resolved path, allowing path traversal;
fix by resolving the candidate path (e.g., const resolved =
resolve(join(partialsDir, partialFile))) and ensure the resolved path starts
with the resolved partialsDir (e.g., const base = resolve(partialsDir); if
(!resolved.startsWith(base + path.sep) && resolved !== base) throw or skip)
before calling readFile and caching; mirror the same resolve()/startsWith()
pattern already used in getMarkdownContent to locate and validate the partial
safely.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1917acf and f0e640c.

📒 Files selected for processing (2)
  • src/hooks.server.ts
  • src/lib/server/markdown.ts

@atharvadeosthale atharvadeosthale merged commit 6c37c17 into main Mar 2, 2026
6 checks passed
@atharvadeosthale atharvadeosthale deleted the fix-md-docs-partials branch March 2, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants