Skip to content

Resolve partial imports using the @site alias and partials directories - #55

Merged
rachfop merged 3 commits into
rachfop:mainfrom
ilanazholobovsky:fix-site-alias-partials
Jul 17, 2026
Merged

rachfop merged 3 commits into
rachfop:mainfrom
ilanazholobovsky:fix-site-alias-partials

Conversation

@ilanazholobovsky

Copy link
Copy Markdown
Contributor

Closes #54

Problem

resolvePartialImports only recognizes the ./_partial.mdx convention: the import regex requires an underscore in the path, and paths resolve relative to the importing file. Docusaurus sites that keep partials in src/partials/ and import them via the @site alias (kebab-case filenames, no underscore) never match, so the JSX tag survives unresolved and the partial's content is missing from the generated markdown. Details and a real-world example in #54.

Changes (all in resolvePartialImports)

  1. Widen the import regex to accept any .mdx/.md import path; the partial-detection decision moves entirely to the filter below.
  2. Treat imports from a /partials/ directory as partials, in addition to the existing underscore convention (which is unchanged).
  3. Resolve the @site/ alias against the site directory. Docusaurus runs builds from the site dir, so process.cwd() is the site root.
  4. Strip the partial's own import lines before splicing. Partials commonly import theme components (@theme/Tabs etc.); once inlined mid-document those lines are no longer at the start of the content, escape the later line-anchored excludeImports pass, and leak as literal text (worst case inside numbered lists: 1. import Tabs from '@theme/Tabs';).

Testing

  • New tests/test-site-alias-partials.js (wired into test:unit): builds a site-shaped fixture (src/partials/ + docs/), imports a partial via @site/src/partials/..., and asserts the tag is resolved, the content is inlined in both block and list context, and no import lines leak.
  • Full test:unit suite passes from a clean checkout (npm install && npm run build && npm run test:unit), including the existing test-partials.js, test-missing-partials.js, and test-circular-imports.js — the underscore convention behaves exactly as before.
  • Also validated against a production Docusaurus site (docs.bitrise.io, 444 pages, 144 of them using @site partials): before — 144 pages with unresolved tags; after — 0 unresolved tags, 0 leaked imports, 0 errors.

@rachfop

rachfop commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Thanks for getting this together. I'll check it out in a minute, but a quick glance it looks correct.

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.

Partials imported via the @site alias are not resolved (tag left in output, content missing)

2 participants