@astrojs/markdoc 0.4.1 → 0.4.3
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/README.md +33 -12
- package/dist/content-entry-type.js +6 -3
- package/dist/load-config.js +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -105,13 +105,12 @@ This example renders an `Aside` component, and allows a `type` prop to be passed
|
|
|
105
105
|
|
|
106
106
|
```js
|
|
107
107
|
// markdoc.config.mjs
|
|
108
|
-
import { defineMarkdocConfig } from '@astrojs/markdoc/config';
|
|
109
|
-
import Aside from './src/components/Aside.astro';
|
|
108
|
+
import { defineMarkdocConfig, component } from '@astrojs/markdoc/config';
|
|
110
109
|
|
|
111
110
|
export default defineMarkdocConfig({
|
|
112
111
|
tags: {
|
|
113
112
|
aside: {
|
|
114
|
-
render: Aside,
|
|
113
|
+
render: component('./src/components/Aside.astro'),
|
|
115
114
|
attributes: {
|
|
116
115
|
// Markdoc requires type defs for each attribute.
|
|
117
116
|
// These should mirror the `Props` type of the component
|
|
@@ -137,6 +136,31 @@ Use tags like this fancy "aside" to add some _flair_ to your docs.
|
|
|
137
136
|
{% /aside %}
|
|
138
137
|
```
|
|
139
138
|
|
|
139
|
+
### Use Astro components from npm packages and TypeScript files
|
|
140
|
+
|
|
141
|
+
You may need to use Astro components exposed as named exports from TypeScript or JavaScript files. This is common when using npm packages and design systems.
|
|
142
|
+
|
|
143
|
+
You can pass the import name as the second argument to the `component()` function:
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
// markdoc.config.mjs
|
|
147
|
+
import { defineMarkdocConfig, component } from '@astrojs/markdoc/config';
|
|
148
|
+
|
|
149
|
+
export default defineMarkdocConfig({
|
|
150
|
+
tags: {
|
|
151
|
+
tabs: {
|
|
152
|
+
render: component('@astrojs/starlight/components', 'Tabs'),
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
This generates the following import statement internally:
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
import { Tabs } from '@astrojs/starlight/components';
|
|
162
|
+
```
|
|
163
|
+
|
|
140
164
|
### Custom headings
|
|
141
165
|
|
|
142
166
|
`@astrojs/markdoc` automatically adds anchor links to your headings, and [generates a list of `headings` via the content collections API](https://docs.astro.build/en/guides/content-collections/#rendering-content-to-html). To further customize how headings are rendered, you can apply an Astro component [as a Markdoc node][markdoc-nodes].
|
|
@@ -145,14 +169,13 @@ This example renders a `Heading.astro` component using the `render` property:
|
|
|
145
169
|
|
|
146
170
|
```js
|
|
147
171
|
// markdoc.config.mjs
|
|
148
|
-
import { defineMarkdocConfig, nodes } from '@astrojs/markdoc/config';
|
|
149
|
-
import Heading from './src/components/Heading.astro';
|
|
172
|
+
import { defineMarkdocConfig, nodes, component } from '@astrojs/markdoc/config';
|
|
150
173
|
|
|
151
174
|
export default defineMarkdocConfig({
|
|
152
175
|
nodes: {
|
|
153
176
|
heading: {
|
|
154
177
|
...nodes.heading, // Preserve default anchor link generation
|
|
155
|
-
render: Heading,
|
|
178
|
+
render: component('./src/components/Heading.astro'),
|
|
156
179
|
},
|
|
157
180
|
},
|
|
158
181
|
});
|
|
@@ -239,14 +262,13 @@ This example renders blockquotes with a custom `Quote.astro` component:
|
|
|
239
262
|
|
|
240
263
|
```js
|
|
241
264
|
// markdoc.config.mjs
|
|
242
|
-
import { defineMarkdocConfig, nodes } from '@astrojs/markdoc/config';
|
|
243
|
-
import Quote from './src/components/Quote.astro';
|
|
265
|
+
import { defineMarkdocConfig, nodes, component } from '@astrojs/markdoc/config';
|
|
244
266
|
|
|
245
267
|
export default defineMarkdocConfig({
|
|
246
268
|
nodes: {
|
|
247
269
|
blockquote: {
|
|
248
270
|
...nodes.blockquote, // Apply Markdoc's defaults for other options
|
|
249
|
-
render: Quote,
|
|
271
|
+
render: component('./src/components/Quote.astro'),
|
|
250
272
|
},
|
|
251
273
|
},
|
|
252
274
|
});
|
|
@@ -273,13 +295,12 @@ This Astro component can now be passed to the `render` prop for any [tag][markdo
|
|
|
273
295
|
|
|
274
296
|
```js
|
|
275
297
|
// markdoc.config.mjs
|
|
276
|
-
import { defineMarkdocConfig } from '@astrojs/markdoc/config';
|
|
277
|
-
import ClientAside from './src/components/ClientAside.astro';
|
|
298
|
+
import { defineMarkdocConfig, component } from '@astrojs/markdoc/config';
|
|
278
299
|
|
|
279
300
|
export default defineMarkdocConfig({
|
|
280
301
|
tags: {
|
|
281
302
|
aside: {
|
|
282
|
-
render: ClientAside,
|
|
303
|
+
render: component('./src/components/ClientAside.astro'),
|
|
283
304
|
attributes: {
|
|
284
305
|
type: { type: String },
|
|
285
306
|
},
|
|
@@ -3,7 +3,7 @@ import matter from "gray-matter";
|
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { isComponentConfig, isValidUrl, MarkdocError, prependForwardSlash } from "./utils.js";
|
|
6
|
-
import { emitESMImage } from "astro/assets";
|
|
6
|
+
import { emitESMImage } from "astro/assets/utils";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { setupConfig } from "./runtime.js";
|
|
9
9
|
async function getContentEntryType({
|
|
@@ -161,17 +161,20 @@ function shouldOptimizeImage(src) {
|
|
|
161
161
|
function getStringifiedImports(componentConfigMap, componentNamePrefix, root) {
|
|
162
162
|
let stringifiedComponentImports = "";
|
|
163
163
|
for (const [key, config] of Object.entries(componentConfigMap)) {
|
|
164
|
-
const importName = config.namedExport ? `{ ${config.namedExport} as ${componentNamePrefix + key} }` : componentNamePrefix + key;
|
|
164
|
+
const importName = config.namedExport ? `{ ${config.namedExport} as ${componentNamePrefix + toImportName(key)} }` : componentNamePrefix + toImportName(key);
|
|
165
165
|
const resolvedPath = config.type === "local" ? new URL(config.path, root).pathname : config.path;
|
|
166
166
|
stringifiedComponentImports += `import ${importName} from ${JSON.stringify(resolvedPath)};
|
|
167
167
|
`;
|
|
168
168
|
}
|
|
169
169
|
return stringifiedComponentImports;
|
|
170
170
|
}
|
|
171
|
+
function toImportName(unsafeName) {
|
|
172
|
+
return unsafeName.replace("-", "_");
|
|
173
|
+
}
|
|
171
174
|
function getStringifiedMap(componentConfigMap, componentNamePrefix) {
|
|
172
175
|
let stringifiedComponentMap = "{";
|
|
173
176
|
for (const key in componentConfigMap) {
|
|
174
|
-
stringifiedComponentMap += `${key}: ${componentNamePrefix + key},
|
|
177
|
+
stringifiedComponentMap += `${JSON.stringify(key)}: ${componentNamePrefix + toImportName(key)},
|
|
175
178
|
`;
|
|
176
179
|
}
|
|
177
180
|
stringifiedComponentMap += "}";
|
package/dist/load-config.js
CHANGED
|
@@ -53,7 +53,7 @@ async function bundleConfigFile({
|
|
|
53
53
|
build.onResolve({ filter: /.*\.astro$/ }, () => {
|
|
54
54
|
markdocError = new MarkdocError({
|
|
55
55
|
message: "`.astro` files are no longer supported in the Markdoc config.",
|
|
56
|
-
hint: "Use the `component()` utility to specify a component path instead."
|
|
56
|
+
hint: "Use the `component()` utility to specify a component path instead. See https://docs.astro.build/en/guides/integrations-guide/markdoc/"
|
|
57
57
|
});
|
|
58
58
|
return {
|
|
59
59
|
// Stub with an unused default export.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astrojs/markdoc",
|
|
3
3
|
"description": "Add support for Markdoc in your Astro site",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"author": "withastro",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"zod": "^3.17.3"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"astro": "^2.8.
|
|
70
|
+
"astro": "^2.8.5"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@astrojs/markdown-remark": "^2.2.1",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"mocha": "^9.2.2",
|
|
81
81
|
"rollup": "^3.25.1",
|
|
82
82
|
"vite": "^4.3.9",
|
|
83
|
-
"astro": "2.8.
|
|
83
|
+
"astro": "2.8.5",
|
|
84
84
|
"astro-scripts": "0.0.14"
|
|
85
85
|
},
|
|
86
86
|
"engines": {
|