@astrojs/markdoc 0.0.0-data-collections-20230418125011
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +129 -0
- package/LICENSE +61 -0
- package/README.md +326 -0
- package/components/Renderer.astro +17 -0
- package/components/TreeNode.ts +81 -0
- package/components/index.ts +2 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +6 -0
- package/dist/default-config.d.ts +5 -0
- package/dist/default-config.js +13 -0
- package/dist/experimental-assets-config.d.ts +2 -0
- package/dist/experimental-assets-config.js +25 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +114 -0
- package/dist/load-config.d.ts +14 -0
- package/dist/load-config.js +82 -0
- package/dist/utils.d.ts +40 -0
- package/dist/utils.js +60 -0
- package/package.json +62 -0
- package/src/config.ts +5 -0
- package/src/default-config.ts +18 -0
- package/src/experimental-assets-config.ts +29 -0
- package/src/index.ts +164 -0
- package/src/load-config.ts +102 -0
- package/src/utils.ts +98 -0
- package/template/content-module-types.d.ts +7 -0
- package/test/content-collections.test.js +110 -0
- package/test/entry-prop.test.js +58 -0
- package/test/fixtures/content-collections/astro.config.mjs +7 -0
- package/test/fixtures/content-collections/node_modules/.bin/astro +17 -0
- package/test/fixtures/content-collections/package.json +9 -0
- package/test/fixtures/content-collections/src/content/blog/post-1.mdoc +7 -0
- package/test/fixtures/content-collections/src/content/blog/post-2.mdoc +7 -0
- package/test/fixtures/content-collections/src/content/blog/post-3.mdoc +7 -0
- package/test/fixtures/content-collections/src/content/config.ts +12 -0
- package/test/fixtures/content-collections/src/pages/collection.json.js +10 -0
- package/test/fixtures/content-collections/src/pages/entry.json.js +10 -0
- package/test/fixtures/content-collections/utils.js +8 -0
- package/test/fixtures/entry-prop/astro.config.mjs +7 -0
- package/test/fixtures/entry-prop/node_modules/.bin/astro +17 -0
- package/test/fixtures/entry-prop/package.json +9 -0
- package/test/fixtures/entry-prop/src/content/blog/entry.mdoc +9 -0
- package/test/fixtures/entry-prop/src/content/config.ts +9 -0
- package/test/fixtures/entry-prop/src/pages/index.astro +19 -0
- package/test/fixtures/image-assets/astro.config.mjs +10 -0
- package/test/fixtures/image-assets/node_modules/.bin/astro +17 -0
- package/test/fixtures/image-assets/package.json +9 -0
- package/test/fixtures/image-assets/src/assets/alias/cityscape.jpg +0 -0
- package/test/fixtures/image-assets/src/assets/relative/oar.jpg +0 -0
- package/test/fixtures/image-assets/src/content/docs/intro.mdoc +7 -0
- package/test/fixtures/image-assets/src/pages/index.astro +19 -0
- package/test/fixtures/image-assets/src/public/favicon.svg +9 -0
- package/test/fixtures/render-null/astro.config.mjs +7 -0
- package/test/fixtures/render-null/markdoc.config.mjs +26 -0
- package/test/fixtures/render-null/node_modules/.bin/astro +17 -0
- package/test/fixtures/render-null/package.json +9 -0
- package/test/fixtures/render-null/src/content/blog/render-null.mdoc +7 -0
- package/test/fixtures/render-null/src/pages/index.astro +19 -0
- package/test/fixtures/render-simple/astro.config.mjs +7 -0
- package/test/fixtures/render-simple/node_modules/.bin/astro +17 -0
- package/test/fixtures/render-simple/package.json +9 -0
- package/test/fixtures/render-simple/src/content/blog/simple.mdoc +7 -0
- package/test/fixtures/render-simple/src/pages/index.astro +19 -0
- package/test/fixtures/render-with-components/astro.config.mjs +7 -0
- package/test/fixtures/render-with-components/markdoc.config.mjs +28 -0
- package/test/fixtures/render-with-components/node_modules/.bin/astro +17 -0
- package/test/fixtures/render-with-components/package.json +12 -0
- package/test/fixtures/render-with-components/src/components/Code.astro +12 -0
- package/test/fixtures/render-with-components/src/components/CustomMarquee.astro +1 -0
- package/test/fixtures/render-with-components/src/content/blog/with-components.mdoc +17 -0
- package/test/fixtures/render-with-components/src/pages/index.astro +19 -0
- package/test/fixtures/render-with-config/astro.config.mjs +7 -0
- package/test/fixtures/render-with-config/markdoc.config.mjs +15 -0
- package/test/fixtures/render-with-config/node_modules/.bin/astro +17 -0
- package/test/fixtures/render-with-config/package.json +9 -0
- package/test/fixtures/render-with-config/src/content/blog/with-config.mdoc +13 -0
- package/test/fixtures/render-with-config/src/pages/index.astro +19 -0
- package/test/image-assets.test.js +76 -0
- package/test/render.test.js +150 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
[35m@astrojs/markdoc:build: [0mcache hit, replaying output [2mbb209a9dad6aec7b[0m
|
|
2
|
+
[35m@astrojs/markdoc:build: [0m
|
|
3
|
+
[35m@astrojs/markdoc:build: [0m> @astrojs/markdoc@0.0.0-data-collections-20230418125011 build /home/runner/work/astro/astro/packages/integrations/markdoc
|
|
4
|
+
[35m@astrojs/markdoc:build: [0m> astro-scripts build "src/**/*.ts" && tsc
|
|
5
|
+
[35m@astrojs/markdoc:build: [0m
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# @astrojs/markdoc
|
|
2
|
+
|
|
3
|
+
## 0.0.0-data-collections-20230418125011
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#6850](https://github.com/withastro/astro/pull/6850) [`0559a11eb`](https://github.com/withastro/astro/commit/0559a11eb886595dfcfe3f571ca0c9f409f9fd0a) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Introducing data collections and references. These offer a way to store JSON file as collection entries under the new `src/data/` directory. You can reference this data from existing content collections using "references." Learn more on our docs (TODO!)
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`0559a11eb`](https://github.com/withastro/astro/commit/0559a11eb886595dfcfe3f571ca0c9f409f9fd0a), [`4c7ba4da0`](https://github.com/withastro/astro/commit/4c7ba4da084d7508df91cbac03c2b099a8301e2b), [`1f2699461`](https://github.com/withastro/astro/commit/1f2699461d4cdcc8007ae47ebff74ace62eee058)]:
|
|
10
|
+
- astro@0.0.0-data-collections-20230418125011
|
|
11
|
+
|
|
12
|
+
## 0.1.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [#6723](https://github.com/withastro/astro/pull/6723) [`73fcc7627`](https://github.com/withastro/astro/commit/73fcc7627e27a001d3ed2f4d046999d91f1aef85) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Fix: when using `render: null` in your config, content is now rendered without a wrapper element.
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [[`489dd8d69`](https://github.com/withastro/astro/commit/489dd8d69cdd9d7c243cf8bec96051a914984b9c), [`a1a4f45b5`](https://github.com/withastro/astro/commit/a1a4f45b51a80215fa7598da83bd0d9c5acd20d2), [`a1108e037`](https://github.com/withastro/astro/commit/a1108e037115cdb67d03505286c7d3a4fc2a1ff5), [`8b88e4cf1`](https://github.com/withastro/astro/commit/8b88e4cf15c8bea7942b3985380164e0edf7250b), [`d54cbe413`](https://github.com/withastro/astro/commit/d54cbe41349e55f8544212ad9320705f07325920), [`4c347ab51`](https://github.com/withastro/astro/commit/4c347ab51e46f2319d614f8577fe502e3dc816e2), [`ff0430786`](https://github.com/withastro/astro/commit/ff043078630e678348ae4f4757b3015b3b862c16), [`2f2e572e9`](https://github.com/withastro/astro/commit/2f2e572e937fd25451bbc78a05d55b7caa1ca3ec), [`7116c021a`](https://github.com/withastro/astro/commit/7116c021a39eac15a6e1264dfbd11bef0f5d618a)]:
|
|
19
|
+
- astro@2.2.0
|
|
20
|
+
|
|
21
|
+
## 0.1.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- [#6653](https://github.com/withastro/astro/pull/6653) [`7c439868a`](https://github.com/withastro/astro/commit/7c439868a3bc7d466418da9af669966014f3d9fe) Thanks [@bholmesdev](https://github.com/bholmesdev)! - 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)).
|
|
26
|
+
|
|
27
|
+
## Migration
|
|
28
|
+
|
|
29
|
+
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.
|
|
30
|
+
|
|
31
|
+
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:
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
// markdoc.config.mjs
|
|
35
|
+
import { defineMarkdocConfig } from '@astrojs/markdoc/config';
|
|
36
|
+
import Aside from './src/components/Aside.astro';
|
|
37
|
+
|
|
38
|
+
export default defineMarkdocConfig({
|
|
39
|
+
tags: {
|
|
40
|
+
aside: {
|
|
41
|
+
render: Aside,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
You should also remove the `components` prop from your `Content` components. Since components are imported into your config directly, this is no longer needed.
|
|
48
|
+
|
|
49
|
+
```diff
|
|
50
|
+
---
|
|
51
|
+
- import Aside from '../components/Aside.astro';
|
|
52
|
+
import { getEntryBySlug } from 'astro:content';
|
|
53
|
+
|
|
54
|
+
const entry = await getEntryBySlug('docs', 'why-markdoc');
|
|
55
|
+
const { Content } = await entry.render();
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
<Content
|
|
59
|
+
- components={{ Aside }}
|
|
60
|
+
/>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Patch Changes
|
|
64
|
+
|
|
65
|
+
- Updated dependencies [[`1f783e320`](https://github.com/withastro/astro/commit/1f783e32075c20b13063599696644f5d47b75d8d), [`2e92e9aa9`](https://github.com/withastro/astro/commit/2e92e9aa976735c3ddb647152bb9c4850136e386), [`adecda7d6`](https://github.com/withastro/astro/commit/adecda7d6009793c5d20519a997e3b7afb08ad57), [`386336441`](https://github.com/withastro/astro/commit/386336441ad70017eea22db0683591126131db21), [`7c439868a`](https://github.com/withastro/astro/commit/7c439868a3bc7d466418da9af669966014f3d9fe), [`25cd3e574`](https://github.com/withastro/astro/commit/25cd3e574999c1c7294a089ad8c39df27ccdbf17), [`4bf87c64f`](https://github.com/withastro/astro/commit/4bf87c64ff7e9ca49e0f5c27e06bd49faaf60542), [`fc0ed9c53`](https://github.com/withastro/astro/commit/fc0ed9c53cd374860bbdb2503318a55ca09a2662)]:
|
|
66
|
+
- astro@2.1.8
|
|
67
|
+
|
|
68
|
+
## 0.0.5
|
|
69
|
+
|
|
70
|
+
### Patch Changes
|
|
71
|
+
|
|
72
|
+
- [#6630](https://github.com/withastro/astro/pull/6630) [`cfcf2e2ff`](https://github.com/withastro/astro/commit/cfcf2e2ffdaa68ace5c84329c05b83559a29d638) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Support automatic image optimization for Markdoc images when using `experimental.assets`. You can [follow our Assets guide](https://docs.astro.build/en/guides/assets/#enabling-assets-in-your-project) to enable this feature in your project. Then, start using relative or aliased image sources in your Markdoc files for automatic optimization:
|
|
73
|
+
|
|
74
|
+
```md
|
|
75
|
+
<!--Relative paths-->
|
|
76
|
+
|
|
77
|
+

|
|
78
|
+
|
|
79
|
+
<!--Or configured aliases-->
|
|
80
|
+
|
|
81
|
+

|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- Updated dependencies [[`b7194103e`](https://github.com/withastro/astro/commit/b7194103e39267bf59dcd6ba00f522e424219d16), [`cfcf2e2ff`](https://github.com/withastro/astro/commit/cfcf2e2ffdaa68ace5c84329c05b83559a29d638), [`45da39a86`](https://github.com/withastro/astro/commit/45da39a8642d64eb318840b18dfc2b5ccc6561bc), [`7daef9a29`](https://github.com/withastro/astro/commit/7daef9a2993b5d457f3d243a1ebfd1dd383b3327)]:
|
|
85
|
+
- astro@2.1.7
|
|
86
|
+
|
|
87
|
+
## 0.0.4
|
|
88
|
+
|
|
89
|
+
### Patch Changes
|
|
90
|
+
|
|
91
|
+
- [#6588](https://github.com/withastro/astro/pull/6588) [`f42f47dc6`](https://github.com/withastro/astro/commit/f42f47dc6a91cdb6534dab0ecbf9e8e85f00ba40) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Allow access to content collection entry information (including parsed frontmatter and the entry slug) from your Markdoc using the `$entry` variable:
|
|
92
|
+
|
|
93
|
+
```mdx
|
|
94
|
+
---
|
|
95
|
+
title: Hello Markdoc!
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
# {% $entry.data.title %}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
- [#6607](https://github.com/withastro/astro/pull/6607) [`86273b588`](https://github.com/withastro/astro/commit/86273b5881cc61ebee11d40280b4c0aba8f4bb2e) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Fix: Update Markdoc renderer internals to remove unneeded dependencies
|
|
102
|
+
|
|
103
|
+
- [#6622](https://github.com/withastro/astro/pull/6622) [`b37b86540`](https://github.com/withastro/astro/commit/b37b865400e77e92878d7e150244acce47e933c6) Thanks [@paulrudy](https://github.com/paulrudy)! - Fix README instructions for installing Markdoc manually.
|
|
104
|
+
|
|
105
|
+
## 0.0.3
|
|
106
|
+
|
|
107
|
+
### Patch Changes
|
|
108
|
+
|
|
109
|
+
- [#6552](https://github.com/withastro/astro/pull/6552) [`392ba3e4d`](https://github.com/withastro/astro/commit/392ba3e4d55f73ce9194bd94a2243f1aa62af079) Thanks [@bluwy](https://github.com/bluwy)! - Fix integration return type
|
|
110
|
+
|
|
111
|
+
## 0.0.2
|
|
112
|
+
|
|
113
|
+
### Patch Changes
|
|
114
|
+
|
|
115
|
+
- [#6494](https://github.com/withastro/astro/pull/6494) [`a13e9d7e3`](https://github.com/withastro/astro/commit/a13e9d7e33baccf51e7d4815f99b481ad174bc57) Thanks [@Yan-Thomas](https://github.com/Yan-Thomas)! - Consistency improvements to several package descriptions
|
|
116
|
+
|
|
117
|
+
## 0.0.1
|
|
118
|
+
|
|
119
|
+
### Patch Changes
|
|
120
|
+
|
|
121
|
+
- [#6209](https://github.com/withastro/astro/pull/6209) [`fec583909`](https://github.com/withastro/astro/commit/fec583909ab62829dc0c1600e2387979365f2b94) Thanks [@bholmesdev](https://github.com/bholmesdev)! - Introduce the (experimental) `@astrojs/markdoc` integration. This unlocks Markdoc inside your Content Collections, bringing support for Astro and UI components in your content. This also improves Astro core internals to make Content Collections extensible to more file types in the future.
|
|
122
|
+
|
|
123
|
+
You can install this integration using the `astro add` command:
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
astro add markdoc
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
[Read the `@astrojs/markdoc` documentation](https://docs.astro.build/en/guides/integrations-guide/markdoc/) for usage instructions, and browse the [new `with-markdoc` starter](https://astro.new/with-markdoc) to try for yourself.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Fred K. Schott
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
"""
|
|
25
|
+
This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository:
|
|
26
|
+
|
|
27
|
+
Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)
|
|
28
|
+
|
|
29
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
30
|
+
|
|
31
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
32
|
+
|
|
33
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
"""
|
|
38
|
+
This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/vitejs/vite repository:
|
|
39
|
+
|
|
40
|
+
MIT License
|
|
41
|
+
|
|
42
|
+
Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
|
|
43
|
+
|
|
44
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
45
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
46
|
+
in the Software without restriction, including without limitation the rights
|
|
47
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
48
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
49
|
+
furnished to do so, subject to the following conditions:
|
|
50
|
+
|
|
51
|
+
The above copyright notice and this permission notice shall be included in all
|
|
52
|
+
copies or substantial portions of the Software.
|
|
53
|
+
|
|
54
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
55
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
56
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
57
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
58
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
59
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
60
|
+
SOFTWARE.
|
|
61
|
+
"""
|
package/README.md
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
# @astrojs/markdoc (experimental) 📝
|
|
2
|
+
|
|
3
|
+
This **[Astro integration][astro-integration]** enables the usage of [Markdoc](https://markdoc.dev/) to create components, pages, and content collection entries.
|
|
4
|
+
|
|
5
|
+
- <strong>[Why Markdoc?](#why-markdoc)</strong>
|
|
6
|
+
- <strong>[Installation](#installation)</strong>
|
|
7
|
+
- <strong>[Usage](#usage)</strong>
|
|
8
|
+
- <strong>[Configuration](#configuration)</strong>
|
|
9
|
+
- <strong>[Examples](#examples)</strong>
|
|
10
|
+
- <strong>[Troubleshooting](#troubleshooting)</strong>
|
|
11
|
+
- <strong>[Contributing](#contributing)</strong>
|
|
12
|
+
- <strong>[Changelog](#changelog)</strong>
|
|
13
|
+
|
|
14
|
+
## Why Markdoc?
|
|
15
|
+
|
|
16
|
+
Markdoc allows you to enhance your Markdown with [Astro components][astro-components]. If you have existing content authored in Markdoc, this integration allows you to bring those files to your Astro project using content collections.
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
### Quick Install
|
|
21
|
+
|
|
22
|
+
The `astro add` command-line tool automates the installation for you. Run one of the following commands in a new terminal window. (If you aren't sure which package manager you're using, run the first command.) Then, follow the prompts, and type "y" in the terminal (meaning "yes") for each one.
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
# Using NPM
|
|
26
|
+
npx astro add markdoc
|
|
27
|
+
# Using Yarn
|
|
28
|
+
yarn astro add markdoc
|
|
29
|
+
# Using PNPM
|
|
30
|
+
pnpm astro add markdoc
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
If you run into any issues, [feel free to report them to us on GitHub](https://github.com/withastro/astro/issues) and try the manual installation steps below.
|
|
34
|
+
|
|
35
|
+
### Manual Install
|
|
36
|
+
|
|
37
|
+
First, install the `@astrojs/markdoc` package using your package manager. If you're using npm or aren't sure, run this in the terminal:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
npm install @astrojs/markdoc
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Then, apply this integration to your `astro.config.*` file using the `integrations` property:
|
|
44
|
+
|
|
45
|
+
__`astro.config.mjs`__
|
|
46
|
+
|
|
47
|
+
```js ins={2} "markdoc()"
|
|
48
|
+
import { defineConfig } from 'astro/config';
|
|
49
|
+
import markdoc from '@astrojs/markdoc';
|
|
50
|
+
|
|
51
|
+
export default defineConfig({
|
|
52
|
+
// ...
|
|
53
|
+
integrations: [markdoc()],
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
### Editor Integration
|
|
59
|
+
|
|
60
|
+
[VS Code](https://code.visualstudio.com/) supports Markdown by default. However, for Markdoc editor support, you may wish to add the following setting in your VSCode config. This ensures authoring Markdoc files provides a Markdown-like editor experience.
|
|
61
|
+
|
|
62
|
+
```json title=".vscode/settings.json"
|
|
63
|
+
"files.associations": {
|
|
64
|
+
"*.mdoc": "markdown"
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
Markdoc files can only be used within content collections. Add entries to any content collection using the `.mdoc` extension:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
src/content/docs/
|
|
74
|
+
why-markdoc.mdoc
|
|
75
|
+
quick-start.mdoc
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Then, query your collection using the [Content Collection APIs](https://docs.astro.build/en/guides/content-collections/#querying-collections):
|
|
79
|
+
|
|
80
|
+
```astro
|
|
81
|
+
---
|
|
82
|
+
import { getEntryBySlug } from 'astro:content';
|
|
83
|
+
|
|
84
|
+
const entry = await getEntryBySlug('docs', 'why-markdoc');
|
|
85
|
+
const { Content } = await entry.render();
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
<!--Access frontmatter properties with `data`-->
|
|
89
|
+
<h1>{entry.data.title}</h1>
|
|
90
|
+
<!--Render Markdoc contents with the Content component-->
|
|
91
|
+
<Content />
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
📚 See the [Astro Content Collection docs][astro-content-collections] for more information.
|
|
95
|
+
|
|
96
|
+
## Configuration
|
|
97
|
+
|
|
98
|
+
`@astrojs/markdoc` offers configuration options to use all of Markdoc's features and connect UI components to your content.
|
|
99
|
+
|
|
100
|
+
### Using components
|
|
101
|
+
|
|
102
|
+
You can add Astro components to your Markdoc using both [Markdoc tags][markdoc-tags] and HTML element [nodes][markdoc-nodes].
|
|
103
|
+
|
|
104
|
+
#### Render Markdoc tags as Astro components
|
|
105
|
+
|
|
106
|
+
You may configure [Markdoc tags][markdoc-tags] that map to components. You can configure a new tag by creating a `markdoc.config.mjs|ts` file at the root of your project and configuring the `tag` attribute.
|
|
107
|
+
|
|
108
|
+
This example renders an `Aside` component, and allows a `type` prop to be passed as a string:
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
// markdoc.config.mjs
|
|
112
|
+
import { defineMarkdocConfig } from '@astrojs/markdoc/config';
|
|
113
|
+
import Aside from './src/components/Aside.astro';
|
|
114
|
+
|
|
115
|
+
export default defineMarkdocConfig({
|
|
116
|
+
tags: {
|
|
117
|
+
aside: {
|
|
118
|
+
render: Aside,
|
|
119
|
+
attributes: {
|
|
120
|
+
// Markdoc requires type defs for each attribute.
|
|
121
|
+
// These should mirror the `Props` type of the component
|
|
122
|
+
// you are rendering.
|
|
123
|
+
// See Markdoc's documentation on defining attributes
|
|
124
|
+
// https://markdoc.dev/docs/attributes#defining-attributes
|
|
125
|
+
type: { type: String },
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
This component can now be used in your Markdoc files with the `{% aside %}` tag. Children will be passed to your component's default slot:
|
|
133
|
+
|
|
134
|
+
```md
|
|
135
|
+
# Welcome to Markdoc 👋
|
|
136
|
+
|
|
137
|
+
{% aside type="tip" %}
|
|
138
|
+
|
|
139
|
+
Use tags like this fancy "aside" to add some *flair* to your docs.
|
|
140
|
+
|
|
141
|
+
{% /aside %}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
#### Render Markdoc nodes / HTML elements as Astro components
|
|
145
|
+
|
|
146
|
+
You may also want to map standard HTML elements like headings and paragraphs to components. For this, you can configure a custom [Markdoc node][markdoc-nodes]. This example overrides Markdoc's `heading` node to render a `Heading` component, passing the built-in `level` attribute as a prop:
|
|
147
|
+
|
|
148
|
+
```js
|
|
149
|
+
// markdoc.config.mjs
|
|
150
|
+
import { defineMarkdocConfig } from '@astrojs/markdoc/config';
|
|
151
|
+
import Heading from './src/components/Heading.astro';
|
|
152
|
+
|
|
153
|
+
export default defineMarkdocConfig({
|
|
154
|
+
nodes: {
|
|
155
|
+
heading: {
|
|
156
|
+
render: Heading,
|
|
157
|
+
attributes: {
|
|
158
|
+
// Pass the attributes from Markdoc's default heading node
|
|
159
|
+
// as component props.
|
|
160
|
+
level: { type: String },
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
})
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Now, all Markdown headings will render with the `Heading.astro` component. This example uses a level 3 heading, automatically passing `level: 3` as the component prop:
|
|
168
|
+
|
|
169
|
+
```md
|
|
170
|
+
### I'm a level 3 heading!
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
📚 [Find all of Markdoc's built-in nodes and node attributes on their documentation.](https://markdoc.dev/docs/nodes#built-in-nodes)
|
|
174
|
+
|
|
175
|
+
#### Use client-side UI components
|
|
176
|
+
|
|
177
|
+
Today, the `components` prop does not support the `client:` directive for hydrating components. To embed client-side components, create a wrapper `.astro` file to import your component and apply a `client:` directive manually.
|
|
178
|
+
|
|
179
|
+
This example wraps a `Aside.tsx` component with a `ClientAside.astro` wrapper:
|
|
180
|
+
|
|
181
|
+
```astro
|
|
182
|
+
---
|
|
183
|
+
// src/components/ClientAside.astro
|
|
184
|
+
import Aside from './Aside';
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
<Aside {...Astro.props} client:load />
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
This component can be passed to the `render` prop for any [tag][markdoc-tags] or [node][markdoc-nodes] in your config:
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
// markdoc.config.mjs
|
|
194
|
+
import { defineMarkdocConfig } from '@astrojs/markdoc/config';
|
|
195
|
+
import Aside from './src/components/Aside.astro';
|
|
196
|
+
|
|
197
|
+
export default defineMarkdocConfig({
|
|
198
|
+
tags: {
|
|
199
|
+
aside: {
|
|
200
|
+
render: Aside,
|
|
201
|
+
attributes: {
|
|
202
|
+
type: { type: String },
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
})
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Access frontmatter and content collection information from your templates
|
|
210
|
+
|
|
211
|
+
You can access content collection information from your Markdoc templates using the `$entry` variable. This includes the entry `slug`, `collection` name, and frontmatter `data` parsed by your content collection schema (if any). This example renders the `title` frontmatter property as a heading:
|
|
212
|
+
|
|
213
|
+
```md
|
|
214
|
+
---
|
|
215
|
+
title: Welcome to Markdoc 👋
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
# {% $entry.data.title %}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
The `$entry` object matches [the `CollectionEntry` type](https://docs.astro.build/en/reference/api-reference/#collection-entry-type), excluding the `.render()` property.
|
|
222
|
+
|
|
223
|
+
### Markdoc config
|
|
224
|
+
|
|
225
|
+
The `markdoc.config.mjs|ts` file accepts [all Markdoc configuration options](https://markdoc.dev/docs/config), including [tags](https://markdoc.dev/docs/tags) and [functions](https://markdoc.dev/docs/functions).
|
|
226
|
+
|
|
227
|
+
You can pass these options from the default export in your `markdoc.config.mjs|ts` file:
|
|
228
|
+
|
|
229
|
+
```js
|
|
230
|
+
// markdoc.config.mjs
|
|
231
|
+
import { defineMarkdocConfig } from '@astrojs/markdoc/config';
|
|
232
|
+
|
|
233
|
+
export default defineMarkdocConfig({
|
|
234
|
+
functions: {
|
|
235
|
+
getCountryEmoji: {
|
|
236
|
+
transform(parameters) {
|
|
237
|
+
const [country] = Object.values(parameters);
|
|
238
|
+
const countryToEmojiMap = {
|
|
239
|
+
japan: '🇯🇵',
|
|
240
|
+
spain: '🇪🇸',
|
|
241
|
+
france: '🇫🇷',
|
|
242
|
+
}
|
|
243
|
+
return countryToEmojiMap[country] ?? '🏳'
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
})
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
Now, you can call this function from any Markdoc content entry:
|
|
251
|
+
|
|
252
|
+
```md
|
|
253
|
+
¡Hola {% getCountryEmoji("spain") %}!
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
📚 [See the Markdoc documentation](https://markdoc.dev/docs/functions#creating-a-custom-function) for more on using variables or functions in your content.
|
|
257
|
+
|
|
258
|
+
### Pass Markdoc variables
|
|
259
|
+
|
|
260
|
+
You may need to pass [variables][markdoc-variables] to your content. This is useful when passing SSR parameters like A/B tests.
|
|
261
|
+
|
|
262
|
+
Variables can be passed as props via the `Content` component:
|
|
263
|
+
|
|
264
|
+
```astro
|
|
265
|
+
---
|
|
266
|
+
import { getEntryBySlug } from 'astro:content';
|
|
267
|
+
|
|
268
|
+
const entry = await getEntryBySlug('docs', 'why-markdoc');
|
|
269
|
+
const { Content } = await entry.render();
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
<!--Pass the `abTest` param as a variable-->
|
|
273
|
+
<Content abTestGroup={Astro.params.abTestGroup} />
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Now, `abTestGroup` is available as a variable in `docs/why-markdoc.mdoc`:
|
|
277
|
+
|
|
278
|
+
```md
|
|
279
|
+
{% if $abTestGroup === 'image-optimization-lover' %}
|
|
280
|
+
|
|
281
|
+
Let me tell you about image optimization...
|
|
282
|
+
|
|
283
|
+
{% /if %}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
To make a variable global to all Markdoc files, you can use the `variables` attribute from your `markdoc.config.mjs|ts`:
|
|
287
|
+
|
|
288
|
+
```js
|
|
289
|
+
import { defineMarkdocConfig } from '@astrojs/markdoc/config';
|
|
290
|
+
|
|
291
|
+
export default defineMarkdocConfig({
|
|
292
|
+
variables: {
|
|
293
|
+
environment: process.env.IS_PROD ? 'prod' : 'dev',
|
|
294
|
+
}
|
|
295
|
+
})
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## Examples
|
|
299
|
+
|
|
300
|
+
* The [Astro Markdoc starter template](https://github.com/withastro/astro/tree/latest/examples/with-markdoc) shows how to use Markdoc files in your Astro project.
|
|
301
|
+
|
|
302
|
+
## Troubleshooting
|
|
303
|
+
|
|
304
|
+
For help, check out the `#support` channel on [Discord](https://astro.build/chat). Our friendly Support Squad members are here to help!
|
|
305
|
+
|
|
306
|
+
You can also check our [Astro Integration Documentation][astro-integration] for more on integrations.
|
|
307
|
+
|
|
308
|
+
## Contributing
|
|
309
|
+
|
|
310
|
+
This package is maintained by Astro's Core team. You're welcome to submit an issue or PR!
|
|
311
|
+
|
|
312
|
+
## Changelog
|
|
313
|
+
|
|
314
|
+
See [CHANGELOG.md](https://github.com/withastro/astro/tree/main/packages/integrations/markdoc/CHANGELOG.md) for a history of changes to this integration.
|
|
315
|
+
|
|
316
|
+
[astro-integration]: https://docs.astro.build/en/guides/integrations-guide/
|
|
317
|
+
|
|
318
|
+
[astro-components]: https://docs.astro.build/en/core-concepts/astro-components/
|
|
319
|
+
|
|
320
|
+
[astro-content-collections]: https://docs.astro.build/en/guides/content-collections/
|
|
321
|
+
|
|
322
|
+
[markdoc-tags]: https://markdoc.dev/docs/tags
|
|
323
|
+
|
|
324
|
+
[markdoc-nodes]: https://markdoc.dev/docs/nodes
|
|
325
|
+
|
|
326
|
+
[markdoc-variables]: https://markdoc.dev/docs/variables
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { Config } from '@markdoc/markdoc';
|
|
3
|
+
import Markdoc from '@markdoc/markdoc';
|
|
4
|
+
import { ComponentNode, createTreeNode } from './TreeNode.js';
|
|
5
|
+
|
|
6
|
+
type Props = {
|
|
7
|
+
config: Config;
|
|
8
|
+
stringifiedAst: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const { stringifiedAst, config } = Astro.props as Props;
|
|
12
|
+
|
|
13
|
+
const ast = Markdoc.Ast.fromJSON(stringifiedAst);
|
|
14
|
+
const content = Markdoc.transform(ast, config);
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
<ComponentNode treeNode={createTreeNode(content)} />
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { AstroInstance } from 'astro';
|
|
2
|
+
import { Fragment } from 'astro/jsx-runtime';
|
|
3
|
+
import type { RenderableTreeNode } from '@markdoc/markdoc';
|
|
4
|
+
import Markdoc from '@markdoc/markdoc';
|
|
5
|
+
import { createComponent, renderComponent, render } from 'astro/runtime/server/index.js';
|
|
6
|
+
|
|
7
|
+
export type TreeNode =
|
|
8
|
+
| {
|
|
9
|
+
type: 'text';
|
|
10
|
+
content: string;
|
|
11
|
+
}
|
|
12
|
+
| {
|
|
13
|
+
type: 'component';
|
|
14
|
+
component: AstroInstance['default'];
|
|
15
|
+
props: Record<string, any>;
|
|
16
|
+
children: TreeNode[];
|
|
17
|
+
}
|
|
18
|
+
| {
|
|
19
|
+
type: 'element';
|
|
20
|
+
tag: string;
|
|
21
|
+
attributes: Record<string, any>;
|
|
22
|
+
children: TreeNode[];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const ComponentNode = createComponent({
|
|
26
|
+
factory(result: any, { treeNode }: { treeNode: TreeNode }) {
|
|
27
|
+
if (treeNode.type === 'text') return render`${treeNode.content}`;
|
|
28
|
+
const slots = {
|
|
29
|
+
default: () =>
|
|
30
|
+
render`${treeNode.children.map((child) =>
|
|
31
|
+
renderComponent(result, 'ComponentNode', ComponentNode, { treeNode: child })
|
|
32
|
+
)}`,
|
|
33
|
+
};
|
|
34
|
+
if (treeNode.type === 'component') {
|
|
35
|
+
return renderComponent(
|
|
36
|
+
result,
|
|
37
|
+
treeNode.component.name,
|
|
38
|
+
treeNode.component,
|
|
39
|
+
treeNode.props,
|
|
40
|
+
slots
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
return renderComponent(result, treeNode.tag, treeNode.tag, treeNode.attributes, slots);
|
|
44
|
+
},
|
|
45
|
+
propagation: 'none',
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
export function createTreeNode(node: RenderableTreeNode | RenderableTreeNode[]): TreeNode {
|
|
49
|
+
if (typeof node === 'string' || typeof node === 'number') {
|
|
50
|
+
return { type: 'text', content: String(node) };
|
|
51
|
+
} else if (Array.isArray(node)) {
|
|
52
|
+
return {
|
|
53
|
+
type: 'component',
|
|
54
|
+
component: Fragment,
|
|
55
|
+
props: {},
|
|
56
|
+
children: node.map((child) => createTreeNode(child)),
|
|
57
|
+
};
|
|
58
|
+
} else if (node === null || typeof node !== 'object' || !Markdoc.Tag.isTag(node)) {
|
|
59
|
+
return { type: 'text', content: '' };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (typeof node.name === 'function') {
|
|
63
|
+
const component = node.name;
|
|
64
|
+
const props = node.attributes;
|
|
65
|
+
const children = node.children.map((child) => createTreeNode(child));
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
type: 'component',
|
|
69
|
+
component,
|
|
70
|
+
props,
|
|
71
|
+
children,
|
|
72
|
+
};
|
|
73
|
+
} else {
|
|
74
|
+
return {
|
|
75
|
+
type: 'element',
|
|
76
|
+
tag: node.name,
|
|
77
|
+
attributes: node.attributes,
|
|
78
|
+
children: node.children.map((child) => createTreeNode(child)),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED