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

[Markdoc] New config format with runtime variable support! #6653

Merged
merged 33 commits into from
Mar 27, 2023

Conversation

bholmesdev
Copy link
Contributor

@bholmesdev bholmesdev commented Mar 24, 2023

Changes

Markdoc.BIG.IMPROVEMENTS.mp4
  • Move Markdoc configuration options from your astro.config.mjs to a new markdoc.config.mjs
  • Remove the components property from the <Content /> component. Components can now be imported from the markdoc.config.mjs and applied to the render property directly. No need for magic string mapping anymore 👏
  • Add deps to @astrojs/markdoc: esbuild for processing the markdoc.config, kleur for formatted logging
  • Support passing variables to your Markdoc files from the Content component. These variables can be passed as props:
---
import { getEntryBySlug } from 'astro:content';

const entry = await getEntryBySlug('docs', 'why-markdoc');
const { Content } = await entry.render();
---

<Content name={Astro.params.username} />

This example name variable is available as $name:

Hey {% $name %}! Let's learn about Markdoc.

Testing

  • Update tests to use new Markdoc config
  • Variable passing test

Docs

  • Update core and example READMEs

@bholmesdev bholmesdev requested a review from a team as a code owner March 24, 2023 20:45
@changeset-bot
Copy link

changeset-bot bot commented Mar 24, 2023

🦋 Changeset detected

Latest commit: b51d9a6

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 pkg: astro Related to the core `astro` package (scope) pkg: example Related to an example package (scope) labels Mar 24, 2023
@github-actions github-actions bot added the pkg: integration Related to any renderer integration (scope) label Mar 24, 2023
@bholmesdev bholmesdev force-pushed the feat/markdoc-runtime-variables branch from 268a99b to 13172f2 Compare March 24, 2023 20:48
Comment on lines -77 to -81
} else if (isCapitalized(node.name)) {
throw new MarkdocError({
message: `Unable to render ${JSON.stringify(node.name)}.`,
hint: 'Did you add this to the "components" prop on your <Content /> component?',
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bye bye wacky error handling 👋

]);
});

it('renders content - simple', async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Render tests and fixtures moved to a separate render.test.js

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Uh, I had only one review comment... and it's praise! 🎉

(Am I slipping....?) Great job with the docs, Ben! 🟣

const entry = await getEntryBySlug('docs', 'why-markdoc');
const { Content } = await entry.render();
---
Use tags like this fancy "aside" to add some *flair* to your docs.
Copy link
Member

Choose a reason for hiding this comment

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

You caught Sarah in the right mood. Flair approved! 💅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thought I could get away with some flair in the example code 😉

Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

Looks good 👍

Copy link
Member

@yanthomasdev yanthomasdev left a comment

Choose a reason for hiding this comment

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

Nice @bholmesdev 💜, docs LGTM!

@bholmesdev bholmesdev merged commit 7c43986 into main Mar 27, 2023
@bholmesdev bholmesdev deleted the feat/markdoc-runtime-variables branch March 27, 2023 22:04
@astrobot-houston astrobot-houston mentioned this pull request Mar 27, 2023
@FredKSchott
Copy link
Member

FredKSchott commented Mar 31, 2023

I really love this new API. Sorry I couldn't give feedback earlier, but just wanted to confirm:

  • Is markdoc.config.js used by anyone else? Is the hope that this is a general format/concept that other projects could use as well and eventually could become a standard, or is it really something that will only ever make sense in this form in an Astro project? I have some thoughts on this.
  • Are there any bundling concerns with multiple asides all included in the same global config file? Ex: Say I have 3 tags: A.astro (with scoped styles), B.jsx (or more likely B.astro containing a JSX client:load or client:only island), and C.astro (contains a hoisted script). Are we building Astro projects properly so that the assets only show up for each component on the pages where that component/tag is used?

@bholmesdev
Copy link
Contributor Author

Thanks @FredKSchott! Discussed offline, but I'll summarize here:

  1. Yes, the markdoc.config.js is modeled on the simplest case for NextJS' integration (they offer multiple config options). Feeling pretty comfortable following their lead.
  2. The renderer is built to only hoist scripts and styles for components actually used on the page. So there should be no danger of global config meaning global hoisting anywhere you render content. I'll make a PR with a test case to confirm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pkg: example Related to an example package (scope) pkg: integration Related to any renderer integration (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants