-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Markdoc] New config format with runtime variable support! (#6653)
* deps: esbuild * feat: support direct component imports for render! * deps: add devalue back * refactor: remove unused components prop * refactor: load experimental assets config separately * fix: upate Content type def to support props * refactor: replace astro stub with inline data * feat: pass through viteId to getRenderMod * fix: add back $entry var with defaults convention * chore: remove unneeded validateRenderProps * chore: remove uneeded validateComponents * fix: remove userMarkdocConfig prop * chore: add helpful error for legacy config * deps: kleur * fix: add back `isCapitalized` * fix: log instead of throw to avoid scary stacktrace * chore: delete more old logic (nice) * chore: delete MORE unused utils * chore: comment on separate assets config * chore: remove console.log * chore: general code cleanup * test: new render config * docs: new README * fix: add expect-error on astro:assets * feat: add defineMarkdocConfig helper * docs: update example README * test: add runtime variable * chore: lint * chore: changeset * chore: add component import deletion * docs: add notes on Vite fork * fix: astro check * chore: add `.mts` to markdoc config formats
- Loading branch information
1 parent
c13d428
commit 7c43986
Showing
44 changed files
with
737 additions
and
636 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
'@astrojs/markdoc': minor | ||
'astro': patch | ||
--- | ||
|
||
Simplify Markdoc configuration with a new `markdoc.config.mjs` file. This lets you import Astro components directly to render as Markdoc tags and nodes, without the need for the previous `components` property. This new configuration also unlocks passing variables to your Markdoc from the `Content` component ([see the new docs](https://docs.astro.build/en/guides/integrations-guide/markdoc/#pass-markdoc-variables)). | ||
|
||
## Migration | ||
|
||
Move any existing Markdoc config from your `astro.config` to a new `markdoc.config.mjs` file at the root of your project. This should be applied as a default export, with the optional `defineMarkdocConfig()` helper for autocomplete in your editor. | ||
|
||
This example configures an `aside` Markdoc tag. Note that components should be imported and applied to the `render` attribute _directly,_ instead of passing the name as a string: | ||
|
||
```js | ||
// markdoc.config.mjs | ||
import { defineMarkdocConfig } from '@astrojs/markdoc/config'; | ||
import Aside from './src/components/Aside.astro'; | ||
|
||
export default defineMarkdocConfig({ | ||
tags: { | ||
aside: { | ||
render: Aside, | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
You should also remove the `components` prop from your `Content` components. Since components are imported into your config directly, this is no longer needed. | ||
|
||
```diff | ||
--- | ||
- import Aside from '../components/Aside.astro'; | ||
import { getEntryBySlug } from 'astro:content'; | ||
|
||
const entry = await getEntryBySlug('docs', 'why-markdoc'); | ||
const { Content } = await entry.render(); | ||
--- | ||
|
||
<Content | ||
- components={{ Aside }} | ||
/> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { defineMarkdocConfig } from '@astrojs/markdoc/config'; | ||
import Aside from './src/components/Aside.astro'; | ||
|
||
export default defineMarkdocConfig({ | ||
tags: { | ||
aside: { | ||
render: Aside, | ||
attributes: { | ||
type: { type: String }, | ||
title: { type: String }, | ||
}, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
}, | ||
"dependencies": { | ||
"@astrojs/markdoc": "^0.0.5", | ||
"astro": "^2.1.7" | ||
"astro": "^2.1.7", | ||
"kleur": "^4.1.5" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
--- | ||
import { getEntryBySlug } from 'astro:content'; | ||
import DocsContent from '../components/DocsContent.astro'; | ||
import Layout from '../layouts/Layout.astro'; | ||
const intro = await getEntryBySlug('docs', 'intro'); | ||
const { Content } = await intro.render(); | ||
--- | ||
|
||
<Layout title={intro.data.title}> | ||
<main> | ||
<h1>{intro.data.title}</h1> | ||
<!-- `DocsContent` is a thin wrapper around --> | ||
<!-- the `Content` component provided by Content Collections, --> | ||
<!-- with added configuration for components. --> | ||
<!-- This allows you to share global components wherever you render your Markdoc. --> | ||
<DocsContent entry={intro} /> | ||
<Content variables={{ revealSecret: true }} /> | ||
</main> | ||
</Layout> | ||
|
||
<style is:global> | ||
table { | ||
margin-block: 2rem; | ||
margin-inline: auto; | ||
} | ||
table td { | ||
padding-block: 0.3rem; | ||
padding-inline: 0.5rem; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.