@astrojs/markdoc 0.1.3 → 0.2.0

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.
Files changed (76) hide show
  1. package/README.md +7 -8
  2. package/dist/config.d.ts +38 -1
  3. package/dist/config.js +7 -3
  4. package/dist/index.js +36 -18
  5. package/dist/nodes/heading.d.ts +4 -0
  6. package/dist/nodes/heading.js +39 -0
  7. package/dist/nodes/index.d.ts +4 -0
  8. package/dist/nodes/index.js +7 -0
  9. package/dist/runtime.d.ts +16 -0
  10. package/dist/runtime.js +63 -0
  11. package/package.json +11 -4
  12. package/template/content-module-types.d.ts +1 -0
  13. package/.turbo/turbo-build.log +0 -4
  14. package/CHANGELOG.md +0 -138
  15. package/dist/default-config.d.ts +0 -5
  16. package/dist/default-config.js +0 -13
  17. package/src/config.ts +0 -6
  18. package/src/default-config.ts +0 -18
  19. package/src/experimental-assets-config.ts +0 -29
  20. package/src/index.ts +0 -188
  21. package/src/load-config.ts +0 -109
  22. package/src/utils.ts +0 -98
  23. package/test/content-collections.test.js +0 -110
  24. package/test/entry-prop.test.js +0 -58
  25. package/test/fixtures/content-collections/astro.config.mjs +0 -7
  26. package/test/fixtures/content-collections/node_modules/.bin/astro +0 -17
  27. package/test/fixtures/content-collections/package.json +0 -9
  28. package/test/fixtures/content-collections/src/content/blog/post-1.mdoc +0 -7
  29. package/test/fixtures/content-collections/src/content/blog/post-2.mdoc +0 -7
  30. package/test/fixtures/content-collections/src/content/blog/post-3.mdoc +0 -7
  31. package/test/fixtures/content-collections/src/content/config.ts +0 -12
  32. package/test/fixtures/content-collections/src/pages/collection.json.js +0 -10
  33. package/test/fixtures/content-collections/src/pages/entry.json.js +0 -10
  34. package/test/fixtures/content-collections/utils.js +0 -8
  35. package/test/fixtures/entry-prop/astro.config.mjs +0 -7
  36. package/test/fixtures/entry-prop/node_modules/.bin/astro +0 -17
  37. package/test/fixtures/entry-prop/package.json +0 -9
  38. package/test/fixtures/entry-prop/src/content/blog/entry.mdoc +0 -9
  39. package/test/fixtures/entry-prop/src/content/config.ts +0 -9
  40. package/test/fixtures/entry-prop/src/pages/index.astro +0 -19
  41. package/test/fixtures/image-assets/astro.config.mjs +0 -10
  42. package/test/fixtures/image-assets/node_modules/.bin/astro +0 -17
  43. package/test/fixtures/image-assets/package.json +0 -9
  44. package/test/fixtures/image-assets/src/assets/alias/cityscape.jpg +0 -0
  45. package/test/fixtures/image-assets/src/assets/relative/oar.jpg +0 -0
  46. package/test/fixtures/image-assets/src/content/docs/intro.mdoc +0 -7
  47. package/test/fixtures/image-assets/src/pages/index.astro +0 -19
  48. package/test/fixtures/image-assets/src/public/favicon.svg +0 -9
  49. package/test/fixtures/render-null/astro.config.mjs +0 -7
  50. package/test/fixtures/render-null/markdoc.config.mjs +0 -26
  51. package/test/fixtures/render-null/node_modules/.bin/astro +0 -17
  52. package/test/fixtures/render-null/package.json +0 -9
  53. package/test/fixtures/render-null/src/content/blog/render-null.mdoc +0 -7
  54. package/test/fixtures/render-null/src/pages/index.astro +0 -19
  55. package/test/fixtures/render-simple/astro.config.mjs +0 -7
  56. package/test/fixtures/render-simple/node_modules/.bin/astro +0 -17
  57. package/test/fixtures/render-simple/package.json +0 -9
  58. package/test/fixtures/render-simple/src/content/blog/simple.mdoc +0 -7
  59. package/test/fixtures/render-simple/src/pages/index.astro +0 -19
  60. package/test/fixtures/render-with-components/astro.config.mjs +0 -7
  61. package/test/fixtures/render-with-components/markdoc.config.mjs +0 -28
  62. package/test/fixtures/render-with-components/node_modules/.bin/astro +0 -17
  63. package/test/fixtures/render-with-components/package.json +0 -12
  64. package/test/fixtures/render-with-components/src/components/Code.astro +0 -12
  65. package/test/fixtures/render-with-components/src/components/CustomMarquee.astro +0 -1
  66. package/test/fixtures/render-with-components/src/content/blog/with-components.mdoc +0 -17
  67. package/test/fixtures/render-with-components/src/pages/index.astro +0 -19
  68. package/test/fixtures/render-with-config/astro.config.mjs +0 -7
  69. package/test/fixtures/render-with-config/markdoc.config.mjs +0 -15
  70. package/test/fixtures/render-with-config/node_modules/.bin/astro +0 -17
  71. package/test/fixtures/render-with-config/package.json +0 -9
  72. package/test/fixtures/render-with-config/src/content/blog/with-config.mdoc +0 -13
  73. package/test/fixtures/render-with-config/src/pages/index.astro +0 -19
  74. package/test/image-assets.test.js +0 -76
  75. package/test/render.test.js +0 -150
  76. package/tsconfig.json +0 -10
package/src/index.ts DELETED
@@ -1,188 +0,0 @@
1
- /* eslint-disable no-console */
2
- import type { Node } from '@markdoc/markdoc';
3
- import Markdoc from '@markdoc/markdoc';
4
- import type { AstroConfig, AstroIntegration, ContentEntryType, HookParameters } from 'astro';
5
- import fs from 'node:fs';
6
- import { fileURLToPath, pathToFileURL } from 'node:url';
7
- import { isValidUrl, MarkdocError, parseFrontmatter, prependForwardSlash } from './utils.js';
8
- // @ts-expect-error Cannot find module 'astro/assets' or its corresponding type declarations.
9
- import { emitESMImage } from 'astro/assets';
10
- import { bold, red, yellow } from 'kleur/colors';
11
- import type * as rollup from 'rollup';
12
- import { applyDefaultConfig } from './default-config.js';
13
- import { loadMarkdocConfig, type MarkdocConfigResult } from './load-config.js';
14
-
15
- type SetupHookParams = HookParameters<'astro:config:setup'> & {
16
- // `contentEntryType` is not a public API
17
- // Add type defs here
18
- addContentEntryType: (contentEntryType: ContentEntryType) => void;
19
- };
20
-
21
- export default function markdocIntegration(legacyConfig?: any): AstroIntegration {
22
- if (legacyConfig) {
23
- console.log(
24
- `${red(
25
- bold('[Markdoc]')
26
- )} Passing Markdoc config from your \`astro.config\` is no longer supported. Configuration should be exported from a \`markdoc.config.mjs\` file. See the configuration docs for more: https://docs.astro.build/en/guides/integrations-guide/markdoc/#configuration`
27
- );
28
- process.exit(0);
29
- }
30
- let markdocConfigResult: MarkdocConfigResult | undefined;
31
- return {
32
- name: '@astrojs/markdoc',
33
- hooks: {
34
- 'astro:config:setup': async (params) => {
35
- const { config: astroConfig, addContentEntryType } = params as SetupHookParams;
36
-
37
- markdocConfigResult = await loadMarkdocConfig(astroConfig);
38
- const userMarkdocConfig = markdocConfigResult?.config ?? {};
39
-
40
- function getEntryInfo({ fileUrl, contents }: { fileUrl: URL; contents: string }) {
41
- const parsed = parseFrontmatter(contents, fileURLToPath(fileUrl));
42
- return {
43
- data: parsed.data,
44
- body: parsed.content,
45
- slug: parsed.data.slug,
46
- rawData: parsed.matter,
47
- };
48
- }
49
- addContentEntryType({
50
- extensions: ['.mdoc'],
51
- getEntryInfo,
52
- async getRenderModule({ entry, viteId }) {
53
- const ast = Markdoc.parse(entry.body);
54
- const pluginContext = this;
55
- const markdocConfig = applyDefaultConfig(userMarkdocConfig, { entry });
56
-
57
- const validationErrors = Markdoc.validate(ast, markdocConfig).filter((e) => {
58
- return (
59
- // Ignore `variable-undefined` errors.
60
- // Variables can be configured at runtime,
61
- // so we cannot validate them at build time.
62
- e.error.id !== 'variable-undefined' &&
63
- (e.error.level === 'error' || e.error.level === 'critical')
64
- );
65
- });
66
- if (validationErrors.length) {
67
- // Heuristic: take number of newlines for `rawData` and add 2 for the `---` fences
68
- const frontmatterBlockOffset = entry._internal.rawData.split('\n').length + 2;
69
- throw new MarkdocError({
70
- message: [
71
- `**${String(entry.collection)} → ${String(entry.id)}** contains invalid content:`,
72
- ...validationErrors.map((e) => `- ${e.error.message}`),
73
- ].join('\n'),
74
- location: {
75
- // Error overlay does not support multi-line or ranges.
76
- // Just point to the first line.
77
- line: frontmatterBlockOffset + validationErrors[0].lines[0],
78
- file: viteId,
79
- },
80
- });
81
- }
82
-
83
- if (astroConfig.experimental.assets) {
84
- await emitOptimizedImages(ast.children, {
85
- astroConfig,
86
- pluginContext,
87
- filePath: entry._internal.filePath,
88
- });
89
- }
90
-
91
- return {
92
- code: `import { jsx as h } from 'astro/jsx-runtime';
93
- import { applyDefaultConfig } from '@astrojs/markdoc/default-config';
94
- import { Renderer } from '@astrojs/markdoc/components';
95
- import * as entry from ${JSON.stringify(viteId + '?astroContent')};${
96
- markdocConfigResult
97
- ? `\nimport userConfig from ${JSON.stringify(
98
- markdocConfigResult.fileUrl.pathname
99
- )};`
100
- : ''
101
- }${
102
- astroConfig.experimental.assets
103
- ? `\nimport { experimentalAssetsConfig } from '@astrojs/markdoc/experimental-assets-config';`
104
- : ''
105
- }
106
- const stringifiedAst = ${JSON.stringify(
107
- /* Double stringify to encode *as* stringified JSON */ JSON.stringify(ast)
108
- )};
109
- export async function Content (props) {
110
- const config = applyDefaultConfig(${
111
- markdocConfigResult
112
- ? '{ ...userConfig, variables: { ...userConfig.variables, ...props } }'
113
- : '{ variables: props }'
114
- }, { entry });${
115
- astroConfig.experimental.assets
116
- ? `\nconfig.nodes = { ...experimentalAssetsConfig.nodes, ...config.nodes };`
117
- : ''
118
- }
119
- return h(Renderer, { stringifiedAst, config }); };`,
120
- };
121
- },
122
- contentModuleTypes: await fs.promises.readFile(
123
- new URL('../template/content-module-types.d.ts', import.meta.url),
124
- 'utf-8'
125
- ),
126
- });
127
- },
128
- 'astro:server:setup': async ({ server }) => {
129
- server.watcher.on('all', (event, entry) => {
130
- if (pathToFileURL(entry).pathname === markdocConfigResult?.fileUrl.pathname) {
131
- console.log(
132
- yellow(
133
- `${bold('[Markdoc]')} Restart the dev server for config changes to take effect.`
134
- )
135
- );
136
- }
137
- });
138
- },
139
- },
140
- };
141
- }
142
-
143
- /**
144
- * Emits optimized images, and appends the generated `src` to each AST node
145
- * via the `__optimizedSrc` attribute.
146
- */
147
- async function emitOptimizedImages(
148
- nodeChildren: Node[],
149
- ctx: {
150
- pluginContext: rollup.PluginContext;
151
- filePath: string;
152
- astroConfig: AstroConfig;
153
- }
154
- ) {
155
- for (const node of nodeChildren) {
156
- if (
157
- node.type === 'image' &&
158
- typeof node.attributes.src === 'string' &&
159
- shouldOptimizeImage(node.attributes.src)
160
- ) {
161
- // Attempt to resolve source with Vite.
162
- // This handles relative paths and configured aliases
163
- const resolved = await ctx.pluginContext.resolve(node.attributes.src, ctx.filePath);
164
-
165
- if (resolved?.id && fs.existsSync(new URL(prependForwardSlash(resolved.id), 'file://'))) {
166
- const src = await emitESMImage(
167
- resolved.id,
168
- ctx.pluginContext.meta.watchMode,
169
- ctx.pluginContext.emitFile,
170
- { config: ctx.astroConfig }
171
- );
172
- node.attributes.__optimizedSrc = src;
173
- } else {
174
- throw new MarkdocError({
175
- message: `Could not resolve image ${JSON.stringify(
176
- node.attributes.src
177
- )} from ${JSON.stringify(ctx.filePath)}. Does the file exist?`,
178
- });
179
- }
180
- }
181
- await emitOptimizedImages(node.children, ctx);
182
- }
183
- }
184
-
185
- function shouldOptimizeImage(src: string) {
186
- // Optimize anything that is NOT external or an absolute path to `public/`
187
- return !isValidUrl(src) && !src.startsWith('/');
188
- }
@@ -1,109 +0,0 @@
1
- import type { Config as MarkdocConfig } from '@markdoc/markdoc';
2
- import type { AstroConfig } from 'astro';
3
- import { build as esbuild } from 'esbuild';
4
- import * as fs from 'node:fs';
5
- import { fileURLToPath } from 'node:url';
6
-
7
- const SUPPORTED_MARKDOC_CONFIG_FILES = [
8
- 'markdoc.config.js',
9
- 'markdoc.config.mjs',
10
- 'markdoc.config.mts',
11
- 'markdoc.config.ts',
12
- ];
13
-
14
- export type MarkdocConfigResult = {
15
- config: MarkdocConfig;
16
- fileUrl: URL;
17
- };
18
-
19
- export async function loadMarkdocConfig(
20
- astroConfig: Pick<AstroConfig, 'root'>
21
- ): Promise<MarkdocConfigResult | undefined> {
22
- let markdocConfigUrl: URL | undefined;
23
- for (const filename of SUPPORTED_MARKDOC_CONFIG_FILES) {
24
- const filePath = new URL(filename, astroConfig.root);
25
- if (!fs.existsSync(filePath)) continue;
26
-
27
- markdocConfigUrl = filePath;
28
- break;
29
- }
30
- if (!markdocConfigUrl) return;
31
-
32
- const { code, dependencies } = await bundleConfigFile({
33
- markdocConfigUrl,
34
- astroConfig,
35
- });
36
- const config: MarkdocConfig = await loadConfigFromBundledFile(astroConfig.root, code);
37
-
38
- return {
39
- config,
40
- fileUrl: markdocConfigUrl,
41
- };
42
- }
43
-
44
- /**
45
- * Forked from Vite's `bundleConfigFile` function
46
- * with added handling for `.astro` imports,
47
- * and removed unused Deno patches.
48
- * @see https://github.com/vitejs/vite/blob/main/packages/vite/src/node/config.ts#L961
49
- */
50
- async function bundleConfigFile({
51
- markdocConfigUrl,
52
- astroConfig,
53
- }: {
54
- markdocConfigUrl: URL;
55
- astroConfig: Pick<AstroConfig, 'root'>;
56
- }): Promise<{ code: string; dependencies: string[] }> {
57
- const result = await esbuild({
58
- absWorkingDir: fileURLToPath(astroConfig.root),
59
- entryPoints: [fileURLToPath(markdocConfigUrl)],
60
- outfile: 'out.js',
61
- write: false,
62
- target: ['node16'],
63
- platform: 'node',
64
- packages: 'external',
65
- bundle: true,
66
- format: 'esm',
67
- sourcemap: 'inline',
68
- metafile: true,
69
- plugins: [
70
- {
71
- name: 'stub-astro-imports',
72
- setup(build) {
73
- build.onResolve({ filter: /.*\.astro$/ }, () => {
74
- return {
75
- // Stub with an unused default export
76
- path: 'data:text/javascript,export default true',
77
- external: true,
78
- };
79
- });
80
- },
81
- },
82
- ],
83
- });
84
- const { text } = result.outputFiles[0];
85
- return {
86
- code: text,
87
- dependencies: result.metafile ? Object.keys(result.metafile.inputs) : [],
88
- };
89
- }
90
-
91
- /**
92
- * Forked from Vite config loader, replacing CJS-based path concat
93
- * with ESM only
94
- * @see https://github.com/vitejs/vite/blob/main/packages/vite/src/node/config.ts#L1074
95
- */
96
- async function loadConfigFromBundledFile(root: URL, code: string): Promise<MarkdocConfig> {
97
- // Write it to disk, load it with native Node ESM, then delete the file.
98
- const tmpFileUrl = new URL(`markdoc.config.timestamp-${Date.now()}.mjs`, root);
99
- fs.writeFileSync(tmpFileUrl, code);
100
- try {
101
- return (await import(tmpFileUrl.pathname)).default;
102
- } finally {
103
- try {
104
- fs.unlinkSync(tmpFileUrl);
105
- } catch {
106
- // already removed if this function is called twice simultaneously
107
- }
108
- }
109
- }
package/src/utils.ts DELETED
@@ -1,98 +0,0 @@
1
- import matter from 'gray-matter';
2
- import type { ErrorPayload as ViteErrorPayload } from 'vite';
3
-
4
- /**
5
- * Match YAML exception handling from Astro core errors
6
- * @see 'astro/src/core/errors.ts'
7
- */
8
- export function parseFrontmatter(fileContents: string, filePath: string) {
9
- try {
10
- // `matter` is empty string on cache results
11
- // clear cache to prevent this
12
- (matter as any).clearCache();
13
- return matter(fileContents);
14
- } catch (e: any) {
15
- if (e.name === 'YAMLException') {
16
- const err: Error & ViteErrorPayload['err'] = e;
17
- err.id = filePath;
18
- err.loc = { file: e.id, line: e.mark.line + 1, column: e.mark.column };
19
- err.message = e.reason;
20
- throw err;
21
- } else {
22
- throw e;
23
- }
24
- }
25
- }
26
-
27
- /**
28
- * Matches AstroError object with types like error codes stubbed out
29
- * @see 'astro/src/core/errors/errors.ts'
30
- */
31
- export class MarkdocError extends Error {
32
- public errorCode: number;
33
- public loc: ErrorLocation | undefined;
34
- public title: string | undefined;
35
- public hint: string | undefined;
36
- public frame: string | undefined;
37
-
38
- type = 'MarkdocError';
39
-
40
- constructor(props: ErrorProperties, ...params: any) {
41
- super(...params);
42
-
43
- const {
44
- // Use default code for unknown errors in Astro core
45
- // We don't have a best practice for integration error codes yet
46
- code = 99999,
47
- name,
48
- title = 'MarkdocError',
49
- message,
50
- stack,
51
- location,
52
- hint,
53
- frame,
54
- } = props;
55
-
56
- this.errorCode = code;
57
- this.title = title;
58
- if (message) this.message = message;
59
- // Only set this if we actually have a stack passed, otherwise uses Error's
60
- this.stack = stack ? stack : this.stack;
61
- this.loc = location;
62
- this.hint = hint;
63
- this.frame = frame;
64
- }
65
- }
66
-
67
- interface ErrorLocation {
68
- file?: string;
69
- line?: number;
70
- column?: number;
71
- }
72
-
73
- interface ErrorProperties {
74
- code?: number;
75
- title?: string;
76
- name?: string;
77
- message?: string;
78
- location?: ErrorLocation;
79
- hint?: string;
80
- stack?: string;
81
- frame?: string;
82
- }
83
-
84
- /**
85
- * @see 'astro/src/core/path.ts'
86
- */
87
- export function prependForwardSlash(str: string) {
88
- return str[0] === '/' ? str : '/' + str;
89
- }
90
-
91
- export function isValidUrl(str: string): boolean {
92
- try {
93
- new URL(str);
94
- return true;
95
- } catch {
96
- return false;
97
- }
98
- }
@@ -1,110 +0,0 @@
1
- import { parse as parseDevalue } from 'devalue';
2
- import { expect } from 'chai';
3
- import { loadFixture, fixLineEndings } from '../../../astro/test/test-utils.js';
4
- import markdoc from '../dist/index.js';
5
-
6
- function formatPost(post) {
7
- return {
8
- ...post,
9
- body: fixLineEndings(post.body),
10
- };
11
- }
12
-
13
- const root = new URL('./fixtures/content-collections/', import.meta.url);
14
-
15
- describe('Markdoc - Content Collections', () => {
16
- let baseFixture;
17
-
18
- before(async () => {
19
- baseFixture = await loadFixture({
20
- root,
21
- integrations: [markdoc()],
22
- });
23
- });
24
-
25
- describe('dev', () => {
26
- let devServer;
27
-
28
- before(async () => {
29
- devServer = await baseFixture.startDevServer();
30
- });
31
-
32
- after(async () => {
33
- await devServer.stop();
34
- });
35
-
36
- it('loads entry', async () => {
37
- const res = await baseFixture.fetch('/entry.json');
38
- const post = parseDevalue(await res.text());
39
- expect(formatPost(post)).to.deep.equal(post1Entry);
40
- });
41
-
42
- it('loads collection', async () => {
43
- const res = await baseFixture.fetch('/collection.json');
44
- const posts = parseDevalue(await res.text());
45
- expect(posts).to.not.be.null;
46
-
47
- expect(posts.sort().map((post) => formatPost(post))).to.deep.equal([
48
- post1Entry,
49
- post2Entry,
50
- post3Entry,
51
- ]);
52
- });
53
- });
54
-
55
- describe('build', () => {
56
- before(async () => {
57
- await baseFixture.build();
58
- });
59
-
60
- it('loads entry', async () => {
61
- const res = await baseFixture.readFile('/entry.json');
62
- const post = parseDevalue(res);
63
- expect(formatPost(post)).to.deep.equal(post1Entry);
64
- });
65
-
66
- it('loads collection', async () => {
67
- const res = await baseFixture.readFile('/collection.json');
68
- const posts = parseDevalue(res);
69
- expect(posts).to.not.be.null;
70
- expect(posts.sort().map((post) => formatPost(post))).to.deep.equal([
71
- post1Entry,
72
- post2Entry,
73
- post3Entry,
74
- ]);
75
- });
76
- });
77
- });
78
-
79
- const post1Entry = {
80
- id: 'post-1.mdoc',
81
- slug: 'post-1',
82
- collection: 'blog',
83
- data: {
84
- schemaWorks: true,
85
- title: 'Post 1',
86
- },
87
- body: '\n## Post 1\n\nThis is the contents of post 1.\n',
88
- };
89
-
90
- const post2Entry = {
91
- id: 'post-2.mdoc',
92
- slug: 'post-2',
93
- collection: 'blog',
94
- data: {
95
- schemaWorks: true,
96
- title: 'Post 2',
97
- },
98
- body: '\n## Post 2\n\nThis is the contents of post 2.\n',
99
- };
100
-
101
- const post3Entry = {
102
- id: 'post-3.mdoc',
103
- slug: 'post-3',
104
- collection: 'blog',
105
- data: {
106
- schemaWorks: true,
107
- title: 'Post 3',
108
- },
109
- body: '\n## Post 3\n\nThis is the contents of post 3.\n',
110
- };
@@ -1,58 +0,0 @@
1
- import { parseHTML } from 'linkedom';
2
- import { expect } from 'chai';
3
- import { loadFixture } from '../../../astro/test/test-utils.js';
4
- import markdoc from '../dist/index.js';
5
-
6
- const root = new URL('./fixtures/entry-prop/', import.meta.url);
7
-
8
- describe('Markdoc - Entry prop', () => {
9
- let baseFixture;
10
-
11
- before(async () => {
12
- baseFixture = await loadFixture({
13
- root,
14
- integrations: [markdoc()],
15
- });
16
- });
17
-
18
- describe('dev', () => {
19
- let devServer;
20
-
21
- before(async () => {
22
- devServer = await baseFixture.startDevServer();
23
- });
24
-
25
- after(async () => {
26
- await devServer.stop();
27
- });
28
-
29
- it('has expected entry properties', async () => {
30
- const res = await baseFixture.fetch('/');
31
- const html = await res.text();
32
- const { document } = parseHTML(html);
33
- expect(document.querySelector('h1')?.textContent).to.equal('Processed by schema: Test entry');
34
- expect(document.getElementById('id')?.textContent?.trim()).to.equal('id: entry.mdoc');
35
- expect(document.getElementById('slug')?.textContent?.trim()).to.equal('slug: entry');
36
- expect(document.getElementById('collection')?.textContent?.trim()).to.equal(
37
- 'collection: blog'
38
- );
39
- });
40
- });
41
-
42
- describe('build', () => {
43
- before(async () => {
44
- await baseFixture.build();
45
- });
46
-
47
- it('has expected entry properties', async () => {
48
- const html = await baseFixture.readFile('/index.html');
49
- const { document } = parseHTML(html);
50
- expect(document.querySelector('h1')?.textContent).to.equal('Processed by schema: Test entry');
51
- expect(document.getElementById('id')?.textContent?.trim()).to.equal('id: entry.mdoc');
52
- expect(document.getElementById('slug')?.textContent?.trim()).to.equal('slug: entry');
53
- expect(document.getElementById('collection')?.textContent?.trim()).to.equal(
54
- 'collection: blog'
55
- );
56
- });
57
- });
58
- });
@@ -1,7 +0,0 @@
1
- import { defineConfig } from 'astro/config';
2
- import markdoc from '@astrojs/markdoc';
3
-
4
- // https://astro.build/config
5
- export default defineConfig({
6
- integrations: [markdoc()],
7
- });
@@ -1,17 +0,0 @@
1
- #!/bin/sh
2
- basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
3
-
4
- case `uname` in
5
- *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
6
- esac
7
-
8
- if [ -z "$NODE_PATH" ]; then
9
- export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules"
10
- else
11
- export NODE_PATH="/home/runner/work/astro/astro/packages/astro/node_modules:/home/runner/work/astro/astro/packages/node_modules:/home/runner/work/astro/astro/node_modules:/home/runner/work/astro/node_modules:/home/runner/work/node_modules:/home/runner/node_modules:/home/node_modules:/node_modules:/home/runner/work/astro/astro/node_modules/.pnpm/node_modules:$NODE_PATH"
12
- fi
13
- if [ -x "$basedir/node" ]; then
14
- exec "$basedir/node" "$basedir/../../../../../../../astro/astro.js" "$@"
15
- else
16
- exec node "$basedir/../../../../../../../astro/astro.js" "$@"
17
- fi
@@ -1,9 +0,0 @@
1
- {
2
- "name": "@test/markdoc-content-collections",
3
- "version": "0.0.0",
4
- "private": true,
5
- "dependencies": {
6
- "@astrojs/markdoc": "workspace:*",
7
- "astro": "workspace:*"
8
- }
9
- }
@@ -1,7 +0,0 @@
1
- ---
2
- title: Post 1
3
- ---
4
-
5
- ## Post 1
6
-
7
- This is the contents of post 1.
@@ -1,7 +0,0 @@
1
- ---
2
- title: Post 2
3
- ---
4
-
5
- ## Post 2
6
-
7
- This is the contents of post 2.
@@ -1,7 +0,0 @@
1
- ---
2
- title: Post 3
3
- ---
4
-
5
- ## Post 3
6
-
7
- This is the contents of post 3.
@@ -1,12 +0,0 @@
1
- import { defineCollection, z } from 'astro:content';
2
-
3
- const blog = defineCollection({
4
- schema: z.object({
5
- title: z.string(),
6
- }).transform(data => ({
7
- ...data,
8
- schemaWorks: true,
9
- }))
10
- });
11
-
12
- export const collections = { blog };
@@ -1,10 +0,0 @@
1
- import { getCollection } from 'astro:content';
2
- import { stringify } from 'devalue';
3
- import { stripAllRenderFn } from '../../utils.js';
4
-
5
- export async function get() {
6
- const posts = await getCollection('blog');
7
- return {
8
- body: stringify(stripAllRenderFn(posts))
9
- };
10
- }
@@ -1,10 +0,0 @@
1
- import { getEntryBySlug } from 'astro:content';
2
- import { stringify } from 'devalue';
3
- import { stripRenderFn } from '../../utils.js';
4
-
5
- export async function get() {
6
- const post = await getEntryBySlug('blog', 'post-1');
7
- return {
8
- body: stringify(stripRenderFn(post)),
9
- };
10
- }
@@ -1,8 +0,0 @@
1
- export function stripRenderFn(entryWithRender) {
2
- const { render, ...entry } = entryWithRender;
3
- return entry;
4
- }
5
-
6
- export function stripAllRenderFn(collection = []) {
7
- return collection.map(stripRenderFn);
8
- }
@@ -1,7 +0,0 @@
1
- import { defineConfig } from 'astro/config';
2
- import markdoc from '@astrojs/markdoc';
3
-
4
- // https://astro.build/config
5
- export default defineConfig({
6
- integrations: [markdoc()],
7
- });