@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.
Files changed (81) hide show
  1. package/.turbo/turbo-build.log +5 -0
  2. package/CHANGELOG.md +129 -0
  3. package/LICENSE +61 -0
  4. package/README.md +326 -0
  5. package/components/Renderer.astro +17 -0
  6. package/components/TreeNode.ts +81 -0
  7. package/components/index.ts +2 -0
  8. package/dist/config.d.ts +2 -0
  9. package/dist/config.js +6 -0
  10. package/dist/default-config.d.ts +5 -0
  11. package/dist/default-config.js +13 -0
  12. package/dist/experimental-assets-config.d.ts +2 -0
  13. package/dist/experimental-assets-config.js +25 -0
  14. package/dist/index.d.ts +2 -0
  15. package/dist/index.js +114 -0
  16. package/dist/load-config.d.ts +14 -0
  17. package/dist/load-config.js +82 -0
  18. package/dist/utils.d.ts +40 -0
  19. package/dist/utils.js +60 -0
  20. package/package.json +62 -0
  21. package/src/config.ts +5 -0
  22. package/src/default-config.ts +18 -0
  23. package/src/experimental-assets-config.ts +29 -0
  24. package/src/index.ts +164 -0
  25. package/src/load-config.ts +102 -0
  26. package/src/utils.ts +98 -0
  27. package/template/content-module-types.d.ts +7 -0
  28. package/test/content-collections.test.js +110 -0
  29. package/test/entry-prop.test.js +58 -0
  30. package/test/fixtures/content-collections/astro.config.mjs +7 -0
  31. package/test/fixtures/content-collections/node_modules/.bin/astro +17 -0
  32. package/test/fixtures/content-collections/package.json +9 -0
  33. package/test/fixtures/content-collections/src/content/blog/post-1.mdoc +7 -0
  34. package/test/fixtures/content-collections/src/content/blog/post-2.mdoc +7 -0
  35. package/test/fixtures/content-collections/src/content/blog/post-3.mdoc +7 -0
  36. package/test/fixtures/content-collections/src/content/config.ts +12 -0
  37. package/test/fixtures/content-collections/src/pages/collection.json.js +10 -0
  38. package/test/fixtures/content-collections/src/pages/entry.json.js +10 -0
  39. package/test/fixtures/content-collections/utils.js +8 -0
  40. package/test/fixtures/entry-prop/astro.config.mjs +7 -0
  41. package/test/fixtures/entry-prop/node_modules/.bin/astro +17 -0
  42. package/test/fixtures/entry-prop/package.json +9 -0
  43. package/test/fixtures/entry-prop/src/content/blog/entry.mdoc +9 -0
  44. package/test/fixtures/entry-prop/src/content/config.ts +9 -0
  45. package/test/fixtures/entry-prop/src/pages/index.astro +19 -0
  46. package/test/fixtures/image-assets/astro.config.mjs +10 -0
  47. package/test/fixtures/image-assets/node_modules/.bin/astro +17 -0
  48. package/test/fixtures/image-assets/package.json +9 -0
  49. package/test/fixtures/image-assets/src/assets/alias/cityscape.jpg +0 -0
  50. package/test/fixtures/image-assets/src/assets/relative/oar.jpg +0 -0
  51. package/test/fixtures/image-assets/src/content/docs/intro.mdoc +7 -0
  52. package/test/fixtures/image-assets/src/pages/index.astro +19 -0
  53. package/test/fixtures/image-assets/src/public/favicon.svg +9 -0
  54. package/test/fixtures/render-null/astro.config.mjs +7 -0
  55. package/test/fixtures/render-null/markdoc.config.mjs +26 -0
  56. package/test/fixtures/render-null/node_modules/.bin/astro +17 -0
  57. package/test/fixtures/render-null/package.json +9 -0
  58. package/test/fixtures/render-null/src/content/blog/render-null.mdoc +7 -0
  59. package/test/fixtures/render-null/src/pages/index.astro +19 -0
  60. package/test/fixtures/render-simple/astro.config.mjs +7 -0
  61. package/test/fixtures/render-simple/node_modules/.bin/astro +17 -0
  62. package/test/fixtures/render-simple/package.json +9 -0
  63. package/test/fixtures/render-simple/src/content/blog/simple.mdoc +7 -0
  64. package/test/fixtures/render-simple/src/pages/index.astro +19 -0
  65. package/test/fixtures/render-with-components/astro.config.mjs +7 -0
  66. package/test/fixtures/render-with-components/markdoc.config.mjs +28 -0
  67. package/test/fixtures/render-with-components/node_modules/.bin/astro +17 -0
  68. package/test/fixtures/render-with-components/package.json +12 -0
  69. package/test/fixtures/render-with-components/src/components/Code.astro +12 -0
  70. package/test/fixtures/render-with-components/src/components/CustomMarquee.astro +1 -0
  71. package/test/fixtures/render-with-components/src/content/blog/with-components.mdoc +17 -0
  72. package/test/fixtures/render-with-components/src/pages/index.astro +19 -0
  73. package/test/fixtures/render-with-config/astro.config.mjs +7 -0
  74. package/test/fixtures/render-with-config/markdoc.config.mjs +15 -0
  75. package/test/fixtures/render-with-config/node_modules/.bin/astro +17 -0
  76. package/test/fixtures/render-with-config/package.json +9 -0
  77. package/test/fixtures/render-with-config/src/content/blog/with-config.mdoc +13 -0
  78. package/test/fixtures/render-with-config/src/pages/index.astro +19 -0
  79. package/test/image-assets.test.js +76 -0
  80. package/test/render.test.js +150 -0
  81. package/tsconfig.json +10 -0
@@ -0,0 +1,102 @@
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 async function loadMarkdocConfig(astroConfig: Pick<AstroConfig, 'root'>) {
15
+ let markdocConfigUrl: URL | undefined;
16
+ for (const filename of SUPPORTED_MARKDOC_CONFIG_FILES) {
17
+ const filePath = new URL(filename, astroConfig.root);
18
+ if (!fs.existsSync(filePath)) continue;
19
+
20
+ markdocConfigUrl = filePath;
21
+ break;
22
+ }
23
+ if (!markdocConfigUrl) return;
24
+
25
+ const { code, dependencies } = await bundleConfigFile({
26
+ markdocConfigUrl,
27
+ astroConfig,
28
+ });
29
+ const config: MarkdocConfig = await loadConfigFromBundledFile(astroConfig.root, code);
30
+
31
+ return {
32
+ config,
33
+ fileUrl: markdocConfigUrl,
34
+ };
35
+ }
36
+
37
+ /**
38
+ * Forked from Vite's `bundleConfigFile` function
39
+ * with added handling for `.astro` imports,
40
+ * and removed unused Deno patches.
41
+ * @see https://github.com/vitejs/vite/blob/main/packages/vite/src/node/config.ts#L961
42
+ */
43
+ async function bundleConfigFile({
44
+ markdocConfigUrl,
45
+ astroConfig,
46
+ }: {
47
+ markdocConfigUrl: URL;
48
+ astroConfig: Pick<AstroConfig, 'root'>;
49
+ }): Promise<{ code: string; dependencies: string[] }> {
50
+ const result = await esbuild({
51
+ absWorkingDir: fileURLToPath(astroConfig.root),
52
+ entryPoints: [fileURLToPath(markdocConfigUrl)],
53
+ outfile: 'out.js',
54
+ write: false,
55
+ target: ['node16'],
56
+ platform: 'node',
57
+ packages: 'external',
58
+ bundle: true,
59
+ format: 'esm',
60
+ sourcemap: 'inline',
61
+ metafile: true,
62
+ plugins: [
63
+ {
64
+ name: 'stub-astro-imports',
65
+ setup(build) {
66
+ build.onResolve({ filter: /.*\.astro$/ }, () => {
67
+ return {
68
+ // Stub with an unused default export
69
+ path: 'data:text/javascript,export default true',
70
+ external: true,
71
+ };
72
+ });
73
+ },
74
+ },
75
+ ],
76
+ });
77
+ const { text } = result.outputFiles[0];
78
+ return {
79
+ code: text,
80
+ dependencies: result.metafile ? Object.keys(result.metafile.inputs) : [],
81
+ };
82
+ }
83
+
84
+ /**
85
+ * Forked from Vite config loader, replacing CJS-based path concat
86
+ * with ESM only
87
+ * @see https://github.com/vitejs/vite/blob/main/packages/vite/src/node/config.ts#L1074
88
+ */
89
+ async function loadConfigFromBundledFile(root: URL, code: string): Promise<MarkdocConfig> {
90
+ // Write it to disk, load it with native Node ESM, then delete the file.
91
+ const tmpFileUrl = new URL(`markdoc.config.timestamp-${Date.now()}.mjs`, root);
92
+ fs.writeFileSync(tmpFileUrl, code);
93
+ try {
94
+ return (await import(tmpFileUrl.pathname)).default;
95
+ } finally {
96
+ try {
97
+ fs.unlinkSync(tmpFileUrl);
98
+ } catch {
99
+ // already removed if this function is called twice simultaneously
100
+ }
101
+ }
102
+ }
package/src/utils.ts ADDED
@@ -0,0 +1,98 @@
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
+ }
@@ -0,0 +1,7 @@
1
+ declare module 'astro:content' {
2
+ interface Render {
3
+ '.mdoc': Promise<{
4
+ Content(props: Record<string, any>): import('astro').MarkdownInstance<{}>['Content'];
5
+ }>;
6
+ }
7
+ }
@@ -0,0 +1,110 @@
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
+ };
@@ -0,0 +1,58 @@
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
+ });
@@ -0,0 +1,7 @@
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
+ });
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,9 @@
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
+ }
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: Post 1
3
+ ---
4
+
5
+ ## Post 1
6
+
7
+ This is the contents of post 1.
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: Post 2
3
+ ---
4
+
5
+ ## Post 2
6
+
7
+ This is the contents of post 2.
@@ -0,0 +1,7 @@
1
+ ---
2
+ title: Post 3
3
+ ---
4
+
5
+ ## Post 3
6
+
7
+ This is the contents of post 3.
@@ -0,0 +1,12 @@
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 };
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1,8 @@
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
+ }
@@ -0,0 +1,7 @@
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
+ });
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@test/markdoc-entry-prop",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "dependencies": {
6
+ "@astrojs/markdoc": "workspace:*",
7
+ "astro": "workspace:*"
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ ---
2
+ title: Test entry
3
+ ---
4
+
5
+ # {% $entry.data.title %}
6
+
7
+ - id: {% $entry.id %} {% #id %}
8
+ - slug: {% $entry.slug %} {% #slug %}
9
+ - collection: {% $entry.collection %} {% #collection %}
@@ -0,0 +1,9 @@
1
+ import { defineCollection, z } from 'astro:content';
2
+
3
+ const blog = defineCollection({
4
+ schema: z.object({
5
+ title: z.string().transform(v => 'Processed by schema: ' + v),
6
+ }),
7
+ });
8
+
9
+ export const collections = { blog }
@@ -0,0 +1,19 @@
1
+ ---
2
+ import { getEntryBySlug } from 'astro:content';
3
+
4
+ const entry = await getEntryBySlug('blog', 'entry');
5
+ const { Content } = await entry.render();
6
+ ---
7
+
8
+ <html lang="en">
9
+ <head>
10
+ <meta charset="utf-8" />
11
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
12
+ <meta name="viewport" content="width=device-width" />
13
+ <meta name="generator" content={Astro.generator} />
14
+ <title>Astro</title>
15
+ </head>
16
+ <body>
17
+ <Content />
18
+ </body>
19
+ </html>
@@ -0,0 +1,10 @@
1
+ import { defineConfig } from 'astro/config';
2
+ import markdoc from '@astrojs/markdoc';
3
+
4
+ // https://astro.build/config
5
+ export default defineConfig({
6
+ experimental: {
7
+ assets: true,
8
+ },
9
+ integrations: [markdoc()],
10
+ });
@@ -0,0 +1,17 @@
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
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@test/image-assets",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "dependencies": {
6
+ "@astrojs/markdoc": "workspace:*",
7
+ "astro": "workspace:*"
8
+ }
9
+ }
@@ -0,0 +1,7 @@
1
+ # Image assets
2
+
3
+ ![Favicon](/favicon.svg) {% #public %}
4
+
5
+ ![Oar](../../assets/relative/oar.jpg) {% #relative %}
6
+
7
+ ![Gray cityscape arial view](~/assets/alias/cityscape.jpg) {% #alias %}
@@ -0,0 +1,19 @@
1
+ ---
2
+ import { getEntryBySlug } from 'astro:content';
3
+
4
+ const intro = await getEntryBySlug('docs', 'intro');
5
+ const { Content } = await intro.render();
6
+ ---
7
+
8
+ <html lang="en">
9
+ <head>
10
+ <meta charset="utf-8" />
11
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
12
+ <meta name="viewport" content="width=device-width" />
13
+ <meta name="generator" content={Astro.generator} />
14
+ <title>Astro</title>
15
+ </head>
16
+ <body>
17
+ <Content />
18
+ </body>
19
+ </html>
@@ -0,0 +1,9 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 128 128">
2
+ <path d="M50.4 78.5a75.1 75.1 0 0 0-28.5 6.9l24.2-65.7c.7-2 1.9-3.2 3.4-3.2h29c1.5 0 2.7 1.2 3.4 3.2l24.2 65.7s-11.6-7-28.5-7L67 45.5c-.4-1.7-1.6-2.8-2.9-2.8-1.3 0-2.5 1.1-2.9 2.7L50.4 78.5Zm-1.1 28.2Zm-4.2-20.2c-2 6.6-.6 15.8 4.2 20.2a17.5 17.5 0 0 1 .2-.7 5.5 5.5 0 0 1 5.7-4.5c2.8.1 4.3 1.5 4.7 4.7.2 1.1.2 2.3.2 3.5v.4c0 2.7.7 5.2 2.2 7.4a13 13 0 0 0 5.7 4.9v-.3l-.2-.3c-1.8-5.6-.5-9.5 4.4-12.8l1.5-1a73 73 0 0 0 3.2-2.2 16 16 0 0 0 6.8-11.4c.3-2 .1-4-.6-6l-.8.6-1.6 1a37 37 0 0 1-22.4 2.7c-5-.7-9.7-2-13.2-6.2Z" />
3
+ <style>
4
+ path { fill: #000; }
5
+ @media (prefers-color-scheme: dark) {
6
+ path { fill: #FFF; }
7
+ }
8
+ </style>
9
+ </svg>
@@ -0,0 +1,7 @@
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
+ });