Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: automatic Markdoc partial resolution #10649

Merged
merged 23 commits into from
Apr 3, 2024

Conversation

bholmesdev
Copy link
Contributor

@bholmesdev bholmesdev commented Apr 2, 2024

Resolves #10418

Changes

This adds automatic resolution for Markdoc partials by relative file path.

<!--src/content/blog/post.mdoc-->

{% partial file="./_diagram.mdoc" /%}

<!--src/content/blog/_diagram.mdoc-->

## Diagram

<figure>
<img src="..." />
<figcaption>Diagram embedded into <code>post.mdoc</cod>
</figure>
  • Crawl Markdoc AST to discover any partial tags. When one is found, render the partial in-place and assign the node. Flattening lets us catch validation errors at buildtime and discover nested component tags for hoisted scripts.
  • Ensure manually configured partials are still respected to make this a non-breaking feature
  • Track file changes to related partials using addWatchFile()
  • Update validator to ignore any "partial not found" errors.

Testing

Add tests to render components and HTML within a partial.

Docs

withastro/docs#7743

Copy link

changeset-bot bot commented Apr 2, 2024

🦋 Changeset detected

Latest commit: 39994e6

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Apr 2, 2024
@bholmesdev
Copy link
Contributor Author

Seems the test file contains too many prod build calls and times out. Will try to reuse fixtures and split the render.test.js file

@sarah11918
Copy link
Member

@bholmesdev Just wanted to check on the naming convention here Ben, because we are currently referring to "page partials" as just plain old "partials" (I guess, the only kind we had so it didn't much matter): https://docs.astro.build/en/basics/astro-pages/#page-partials

So, I'm wondering whether in conjunction with your PR documenting Markdoc partials we should update wording on the Pages page to always say "page partial" and whether we should be clear to always say "Markdoc partial" when referring to these files.

The joys of adding the second thing that use the same word. 😄

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Can we have at least one test that raises an error in case we attempt to render a partial that doesn't exist or it's an incorrect folder? This would help to set down expectations.

.changeset/moody-spies-learn.md Show resolved Hide resolved
packages/integrations/markdoc/package.json Outdated Show resolved Hide resolved
packages/integrations/markdoc/src/content-entry-type.ts Outdated Show resolved Hide resolved
@bholmesdev bholmesdev merged commit 90cfade into main Apr 3, 2024
14 checks passed
@bholmesdev bholmesdev deleted the fix/markdoc-partial-with-component branch April 3, 2024 20:48
@astrobot-houston astrobot-houston mentioned this pull request Apr 3, 2024
taktran added a commit to ag-grid/ag-grid that referenced this pull request May 7, 2024
Use native astro markdoc support for `partial` instead.

See withastro/astro#10418 and withastro/astro#10649
taktran added a commit to ag-grid/ag-grid that referenced this pull request May 7, 2024
Use native astro markdoc support for `partial` instead.

See withastro/astro#10418 and withastro/astro#10649
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: integration Related to any renderer integration (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom markdoc tag to include markdoc file does not render react component
5 participants