Skip to content

feat(ast): strip /index suffix from path when index files are used#756

Closed
avivkeller wants to merge 2 commits intomainfrom
cursor/united-states-capital-25e3
Closed

feat(ast): strip /index suffix from path when index files are used#756
avivkeller wants to merge 2 commits intomainfrom
cursor/united-states-capital-25e3

Conversation

@avivkeller
Copy link
Copy Markdown
Member

@avivkeller avivkeller commented Apr 6, 2026

Description

When parsing markdown files, the path property on the resulting AST node was including /index for index files (e.g. index.md/index, api/index.md/api/index). This changes the behavior so index files resolve to their parent directory path:

  • index.mdpath: /
  • api/index.mdpath: /api
  • api/fs.mdpath: /api/fs (unchanged)

The fix is in src/generators/ast/generate.mjs in the processChunk function, where the relativePath is computed from the file path relative to the glob parent.

Additionally, src/generators/metadata/utils/parse.mjs is updated so that the api and basename identifiers (derived from path) fall back to 'index' when path === '/'. This preserves correct behavior for all downstream generators that use api/basename as file identifiers (e.g. legacy-json writing index.json, legacy-json-all skipping the index section, legacy-html writing index.html, web generator using basename.html for navigation).

Validation

A new test file src/generators/ast/__tests__/generate.test.mjs was added with 5 test cases covering:

  • Top-level index file (/index.md/)
  • Nested index file (sub/index.md/sub)
  • Non-index files (unchanged)
  • Files whose name contains "index" but isn't exactly "index" (e.g. indexes.md, unchanged)
  • Multiple files processed together

All 408 tests in the test suite pass.

Related Issues

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run node --run test and all tests passed.
  • I have check code formatting with node --run format & node --run lint.
  • I've covered new added functionality with unit tests if necessary.
Open in Web Open in Cursor 

Index files (e.g. index.md) should resolve to their parent directory
path rather than /index. For example:
- /index.md -> path: /
- /api/index.md -> path: /api
- /api/fs.md -> path: /api/fs (unchanged)
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api-docs-tooling Ready Ready Preview Apr 6, 2026 9:12pm

Request Review

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 6, 2026

Codecov Report

❌ Patch coverage is 97.50000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.40%. Comparing base (b2330d9) to head (808b8d0).

Files with missing lines Patch % Lines
src/generators/metadata/utils/parse.mjs 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #756      +/-   ##
==========================================
- Coverage   78.42%   78.40%   -0.03%     
==========================================
  Files         157      158       +1     
  Lines       13959    14035      +76     
  Branches     1152     1167      +15     
==========================================
+ Hits        10948    11004      +56     
- Misses       3006     3026      +20     
  Partials        5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

legacy-html Generator

File Base Head Diff
index.html 17.98 KB 17.86 KB -125.00 B (-0.68%)

llms-txt Generator

File Base Head Diff
llms.txt 13.75 KB 13.75 KB -5.00 B (-0.04%)

orama-db Generator

File Base Head Diff
orama-db.json 8.28 MB 8.28 MB -10.00 B (-0.00%)

web Generator

File Base Head Diff
addons.html 262.56 KB 262.55 KB -8.00 B (-0.00%)
assert.html 330.00 KB 329.99 KB -8.00 B (-0.00%)
async_context.html 187.57 KB 187.57 KB -8.00 B (-0.00%)
async_hooks.html 159.71 KB 159.70 KB -8.00 B (-0.00%)
buffer.html 905.72 KB 905.71 KB -8.00 B (-0.00%)
child_process.html 381.70 KB 381.69 KB -8.00 B (-0.00%)
cli.html 495.11 KB 495.10 KB -8.00 B (-0.00%)
cluster.html 196.30 KB 196.29 KB -8.00 B (-0.00%)
console.html 146.77 KB 146.76 KB -8.00 B (-0.01%)
crypto.html 1.09 MB 1.09 MB -8.00 B (-0.00%)
debugger.html 54.22 KB 54.21 KB -8.00 B (-0.01%)
deprecations.html 505.31 KB 505.30 KB -8.00 B (-0.00%)
dgram.html 194.37 KB 194.36 KB -8.00 B (-0.00%)
diagnostics_channel.html 303.42 KB 303.41 KB -8.00 B (-0.00%)
dns.html 295.81 KB 295.80 KB -8.00 B (-0.00%)
documentation.html 38.04 KB 38.03 KB -8.00 B (-0.02%)
domain.html 105.10 KB 105.09 KB -8.00 B (-0.01%)
embedding.html 59.42 KB 59.42 KB -8.00 B (-0.01%)
environment_variables.html 44.04 KB 44.03 KB -8.00 B (-0.02%)
errors.html 461.17 KB 461.17 KB -8.00 B (-0.00%)
esm.html 155.33 KB 155.32 KB -8.00 B (-0.01%)
events.html 455.27 KB 455.26 KB -8.00 B (-0.00%)
fs.html 1.43 MB 1.43 MB -8.00 B (-0.00%)
globals.html 230.37 KB 230.36 KB -8.00 B (-0.00%)
http.html 746.16 KB 746.16 KB -8.00 B (-0.00%)
http2.html 768.59 KB 768.58 KB -8.00 B (-0.00%)
https.html 150.35 KB 150.34 KB -8.00 B (-0.01%)
inspector.html 171.38 KB 171.37 KB -8.00 B (-0.00%)
intl.html 58.14 KB 58.13 KB -8.00 B (-0.01%)
module.html 326.66 KB 326.65 KB -8.00 B (-0.00%)
modules.html 178.73 KB 178.72 KB -8.00 B (-0.00%)
n-api.html 807.25 KB 807.24 KB -8.00 B (-0.00%)
net.html 382.29 KB 382.28 KB -8.00 B (-0.00%)
os.html 142.73 KB 142.72 KB -8.00 B (-0.01%)
packages.html 154.65 KB 154.64 KB -8.00 B (-0.01%)
path.html 139.26 KB 139.25 KB -8.00 B (-0.01%)
perf_hooks.html 381.49 KB 381.48 KB -8.00 B (-0.00%)
permissions.html 55.14 KB 55.13 KB -8.00 B (-0.01%)
process.html 676.15 KB 676.14 KB -8.00 B (-0.00%)
punycode.html 63.19 KB 63.18 KB -8.00 B (-0.01%)
querystring.html 63.85 KB 63.84 KB -8.00 B (-0.01%)
quic.html 358.97 KB 358.97 KB -8.00 B (-0.00%)
readline.html 252.17 KB 252.17 KB -8.00 B (-0.00%)
repl.html 183.30 KB 183.29 KB -8.00 B (-0.00%)
report.html 175.92 KB 175.91 KB -8.00 B (-0.00%)
single-executable-applications.html 106.94 KB 106.94 KB -8.00 B (-0.01%)
sqlite.html 268.08 KB 268.07 KB -8.00 B (-0.00%)
stream.html 855.30 KB 855.30 KB -8.00 B (-0.00%)
stream_iter.html 309.03 KB 309.02 KB -8.00 B (-0.00%)
string_decoder.html 55.39 KB 55.38 KB -8.00 B (-0.01%)
synopsis.html 42.67 KB 42.66 KB -8.00 B (-0.02%)
test.html 766.71 KB 766.71 KB -8.00 B (-0.00%)
timers.html 133.50 KB 133.50 KB -8.00 B (-0.01%)
tls.html 373.79 KB 373.78 KB -8.00 B (-0.00%)
tracing.html 84.16 KB 84.15 KB -8.00 B (-0.01%)
tty.html 95.29 KB 95.28 KB -8.00 B (-0.01%)
typescript.html 53.47 KB 53.46 KB -8.00 B (-0.01%)
url.html 347.67 KB 347.67 KB -8.00 B (-0.00%)
util.html 691.89 KB 691.88 KB -8.00 B (-0.00%)
v8.html 321.09 KB 321.08 KB -8.00 B (-0.00%)
vm.html 370.80 KB 370.79 KB -8.00 B (-0.00%)
wasi.html 69.37 KB 69.36 KB -8.00 B (-0.01%)
webcrypto.html 522.00 KB 521.99 KB -8.00 B (-0.00%)
webstreams.html 357.21 KB 357.20 KB -8.00 B (-0.00%)
worker_threads.html 365.47 KB 365.46 KB -8.00 B (-0.00%)
zlib.html 290.24 KB 290.23 KB -8.00 B (-0.00%)
zlib_iter.html 88.06 KB 88.05 KB -8.00 B (-0.01%)
index.js 5.73 KB 5.73 KB -5.00 B (-0.09%)

When path is '/' (set by the ast generator for index.md files), the
derived api and basename values were empty strings. This broke all
downstream generators that rely on api/basename as file identifiers
(e.g. legacy-json writing index.json, legacy-json-all skipping the
index section, legacy-html writing index.html, etc.).

Add an 'index' fallback so that path='/' correctly maps to
api='index' and basename='index', matching the pre-existing behavior
for those identifiers.
@avivkeller
Copy link
Copy Markdown
Member Author

(This was a test of a Cloud Agent)

@avivkeller avivkeller closed this Apr 6, 2026
@ovflowd ovflowd deleted the cursor/united-states-capital-25e3 branch April 6, 2026 21:29
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