@astrojs/markdoc 0.1.2 → 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.
- package/README.md +8 -11
- package/dist/config.d.ts +38 -0
- package/dist/config.js +7 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +68 -25
- package/dist/load-config.d.ts +5 -12
- package/dist/nodes/heading.d.ts +4 -0
- package/dist/nodes/heading.js +39 -0
- package/dist/nodes/index.d.ts +4 -0
- package/dist/nodes/index.js +7 -0
- package/dist/runtime.d.ts +16 -0
- package/dist/runtime.js +63 -0
- package/package.json +11 -4
- package/template/content-module-types.d.ts +1 -0
- package/.turbo/turbo-build.log +0 -4
- package/CHANGELOG.md +0 -129
- package/dist/default-config.d.ts +0 -5
- package/dist/default-config.js +0 -13
- package/src/config.ts +0 -5
- package/src/default-config.ts +0 -18
- package/src/experimental-assets-config.ts +0 -29
- package/src/index.ts +0 -164
- package/src/load-config.ts +0 -102
- package/src/utils.ts +0 -98
- package/test/content-collections.test.js +0 -110
- package/test/entry-prop.test.js +0 -58
- package/test/fixtures/content-collections/astro.config.mjs +0 -7
- package/test/fixtures/content-collections/node_modules/.bin/astro +0 -17
- package/test/fixtures/content-collections/package.json +0 -9
- package/test/fixtures/content-collections/src/content/blog/post-1.mdoc +0 -7
- package/test/fixtures/content-collections/src/content/blog/post-2.mdoc +0 -7
- package/test/fixtures/content-collections/src/content/blog/post-3.mdoc +0 -7
- package/test/fixtures/content-collections/src/content/config.ts +0 -12
- package/test/fixtures/content-collections/src/pages/collection.json.js +0 -10
- package/test/fixtures/content-collections/src/pages/entry.json.js +0 -10
- package/test/fixtures/content-collections/utils.js +0 -8
- package/test/fixtures/entry-prop/astro.config.mjs +0 -7
- package/test/fixtures/entry-prop/node_modules/.bin/astro +0 -17
- package/test/fixtures/entry-prop/package.json +0 -9
- package/test/fixtures/entry-prop/src/content/blog/entry.mdoc +0 -9
- package/test/fixtures/entry-prop/src/content/config.ts +0 -9
- package/test/fixtures/entry-prop/src/pages/index.astro +0 -19
- package/test/fixtures/image-assets/astro.config.mjs +0 -10
- package/test/fixtures/image-assets/node_modules/.bin/astro +0 -17
- package/test/fixtures/image-assets/package.json +0 -9
- 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 +0 -7
- package/test/fixtures/image-assets/src/pages/index.astro +0 -19
- package/test/fixtures/image-assets/src/public/favicon.svg +0 -9
- package/test/fixtures/render-null/astro.config.mjs +0 -7
- package/test/fixtures/render-null/markdoc.config.mjs +0 -26
- package/test/fixtures/render-null/node_modules/.bin/astro +0 -17
- package/test/fixtures/render-null/package.json +0 -9
- package/test/fixtures/render-null/src/content/blog/render-null.mdoc +0 -7
- package/test/fixtures/render-null/src/pages/index.astro +0 -19
- package/test/fixtures/render-simple/astro.config.mjs +0 -7
- package/test/fixtures/render-simple/node_modules/.bin/astro +0 -17
- package/test/fixtures/render-simple/package.json +0 -9
- package/test/fixtures/render-simple/src/content/blog/simple.mdoc +0 -7
- package/test/fixtures/render-simple/src/pages/index.astro +0 -19
- package/test/fixtures/render-with-components/astro.config.mjs +0 -7
- package/test/fixtures/render-with-components/markdoc.config.mjs +0 -28
- package/test/fixtures/render-with-components/node_modules/.bin/astro +0 -17
- package/test/fixtures/render-with-components/package.json +0 -12
- package/test/fixtures/render-with-components/src/components/Code.astro +0 -12
- package/test/fixtures/render-with-components/src/components/CustomMarquee.astro +0 -1
- package/test/fixtures/render-with-components/src/content/blog/with-components.mdoc +0 -17
- package/test/fixtures/render-with-components/src/pages/index.astro +0 -19
- package/test/fixtures/render-with-config/astro.config.mjs +0 -7
- package/test/fixtures/render-with-config/markdoc.config.mjs +0 -15
- package/test/fixtures/render-with-config/node_modules/.bin/astro +0 -17
- package/test/fixtures/render-with-config/package.json +0 -9
- package/test/fixtures/render-with-config/src/content/blog/with-config.mdoc +0 -13
- package/test/fixtures/render-with-config/src/pages/index.astro +0 -19
- package/test/image-assets.test.js +0 -76
- package/test/render.test.js +0 -150
- package/tsconfig.json +0 -10
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { Config as MarkdocConfig } from '@markdoc/markdoc';
|
|
2
|
-
import Markdoc from '@markdoc/markdoc';
|
|
3
|
-
//@ts-expect-error Cannot find module 'astro:assets' or its corresponding type declarations.
|
|
4
|
-
import { Image } from 'astro:assets';
|
|
5
|
-
|
|
6
|
-
// Separate module to only import `astro:assets` when
|
|
7
|
-
// `experimental.assets` flag is set in a project.
|
|
8
|
-
// TODO: merge with `./default-config.ts` when `experimental.assets` is baselined.
|
|
9
|
-
export const experimentalAssetsConfig: MarkdocConfig = {
|
|
10
|
-
nodes: {
|
|
11
|
-
image: {
|
|
12
|
-
attributes: {
|
|
13
|
-
...Markdoc.nodes.image.attributes,
|
|
14
|
-
__optimizedSrc: { type: 'Object' },
|
|
15
|
-
},
|
|
16
|
-
transform(node, config) {
|
|
17
|
-
const attributes = node.transformAttributes(config);
|
|
18
|
-
const children = node.transformChildren(config);
|
|
19
|
-
|
|
20
|
-
if (node.type === 'image' && '__optimizedSrc' in node.attributes) {
|
|
21
|
-
const { __optimizedSrc, ...rest } = node.attributes;
|
|
22
|
-
return new Markdoc.Tag(Image, { ...rest, src: __optimizedSrc }, children);
|
|
23
|
-
} else {
|
|
24
|
-
return new Markdoc.Tag('img', attributes, children);
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import type { Node } from '@markdoc/markdoc';
|
|
2
|
-
import Markdoc from '@markdoc/markdoc';
|
|
3
|
-
import type { AstroConfig, AstroIntegration, ContentEntryType, HookParameters } from 'astro';
|
|
4
|
-
import fs from 'node:fs';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import { isValidUrl, MarkdocError, parseFrontmatter, prependForwardSlash } from './utils.js';
|
|
7
|
-
// @ts-expect-error Cannot find module 'astro/assets' or its corresponding type declarations.
|
|
8
|
-
import { emitESMImage } from 'astro/assets';
|
|
9
|
-
import { bold, red } from 'kleur/colors';
|
|
10
|
-
import type * as rollup from 'rollup';
|
|
11
|
-
import { applyDefaultConfig } from './default-config.js';
|
|
12
|
-
import { loadMarkdocConfig } from './load-config.js';
|
|
13
|
-
|
|
14
|
-
type SetupHookParams = HookParameters<'astro:config:setup'> & {
|
|
15
|
-
// `contentEntryType` is not a public API
|
|
16
|
-
// Add type defs here
|
|
17
|
-
addContentEntryType: (contentEntryType: ContentEntryType) => void;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default function markdocIntegration(legacyConfig: any): AstroIntegration {
|
|
21
|
-
if (legacyConfig) {
|
|
22
|
-
// eslint-disable-next-line no-console
|
|
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
|
-
return {
|
|
31
|
-
name: '@astrojs/markdoc',
|
|
32
|
-
hooks: {
|
|
33
|
-
'astro:config:setup': async (params) => {
|
|
34
|
-
const { config: astroConfig, addContentEntryType } = params as SetupHookParams;
|
|
35
|
-
|
|
36
|
-
const configLoadResult = await loadMarkdocConfig(astroConfig);
|
|
37
|
-
const userMarkdocConfig = configLoadResult?.config ?? {};
|
|
38
|
-
|
|
39
|
-
function getEntryInfo({ fileUrl, contents }: { fileUrl: URL; contents: string }) {
|
|
40
|
-
const parsed = parseFrontmatter(contents, fileURLToPath(fileUrl));
|
|
41
|
-
return {
|
|
42
|
-
data: parsed.data,
|
|
43
|
-
body: parsed.content,
|
|
44
|
-
slug: parsed.data.slug,
|
|
45
|
-
rawData: parsed.matter,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
addContentEntryType({
|
|
49
|
-
extensions: ['.mdoc'],
|
|
50
|
-
getEntryInfo,
|
|
51
|
-
async getRenderModule({ entry, viteId }) {
|
|
52
|
-
const ast = Markdoc.parse(entry.body);
|
|
53
|
-
const pluginContext = this;
|
|
54
|
-
const markdocConfig = applyDefaultConfig(userMarkdocConfig, { entry });
|
|
55
|
-
|
|
56
|
-
const validationErrors = Markdoc.validate(ast, markdocConfig).filter((e) => {
|
|
57
|
-
// Ignore `variable-undefined` errors.
|
|
58
|
-
// Variables can be configured at runtime,
|
|
59
|
-
// so we cannot validate them at build time.
|
|
60
|
-
return e.error.id !== 'variable-undefined';
|
|
61
|
-
});
|
|
62
|
-
if (validationErrors.length) {
|
|
63
|
-
throw new MarkdocError({
|
|
64
|
-
message: [
|
|
65
|
-
`**${String(entry.collection)} → ${String(entry.id)}** failed to validate:`,
|
|
66
|
-
...validationErrors.map((e) => e.error.id),
|
|
67
|
-
].join('\n'),
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (astroConfig.experimental.assets) {
|
|
72
|
-
await emitOptimizedImages(ast.children, {
|
|
73
|
-
astroConfig,
|
|
74
|
-
pluginContext,
|
|
75
|
-
filePath: entry._internal.filePath,
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const code = {
|
|
80
|
-
code: `import { jsx as h } from 'astro/jsx-runtime';
|
|
81
|
-
import { applyDefaultConfig } from '@astrojs/markdoc/default-config';
|
|
82
|
-
import { Renderer } from '@astrojs/markdoc/components';
|
|
83
|
-
import * as entry from ${JSON.stringify(viteId + '?astroContent')};${
|
|
84
|
-
configLoadResult
|
|
85
|
-
? `\nimport userConfig from ${JSON.stringify(configLoadResult.fileUrl.pathname)};`
|
|
86
|
-
: ''
|
|
87
|
-
}${
|
|
88
|
-
astroConfig.experimental.assets
|
|
89
|
-
? `\nimport { experimentalAssetsConfig } from '@astrojs/markdoc/experimental-assets-config';`
|
|
90
|
-
: ''
|
|
91
|
-
}
|
|
92
|
-
const stringifiedAst = ${JSON.stringify(
|
|
93
|
-
/* Double stringify to encode *as* stringified JSON */ JSON.stringify(ast)
|
|
94
|
-
)};
|
|
95
|
-
export async function Content (props) {
|
|
96
|
-
const config = applyDefaultConfig(${
|
|
97
|
-
configLoadResult
|
|
98
|
-
? '{ ...userConfig, variables: { ...userConfig.variables, ...props } }'
|
|
99
|
-
: '{ variables: props }'
|
|
100
|
-
}, { entry });${
|
|
101
|
-
astroConfig.experimental.assets
|
|
102
|
-
? `\nconfig.nodes = { ...experimentalAssetsConfig.nodes, ...config.nodes };`
|
|
103
|
-
: ''
|
|
104
|
-
}
|
|
105
|
-
return h(Renderer, { stringifiedAst, config }); };`,
|
|
106
|
-
};
|
|
107
|
-
return code;
|
|
108
|
-
},
|
|
109
|
-
contentModuleTypes: await fs.promises.readFile(
|
|
110
|
-
new URL('../template/content-module-types.d.ts', import.meta.url),
|
|
111
|
-
'utf-8'
|
|
112
|
-
),
|
|
113
|
-
});
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Emits optimized images, and appends the generated `src` to each AST node
|
|
121
|
-
* via the `__optimizedSrc` attribute.
|
|
122
|
-
*/
|
|
123
|
-
async function emitOptimizedImages(
|
|
124
|
-
nodeChildren: Node[],
|
|
125
|
-
ctx: {
|
|
126
|
-
pluginContext: rollup.PluginContext;
|
|
127
|
-
filePath: string;
|
|
128
|
-
astroConfig: AstroConfig;
|
|
129
|
-
}
|
|
130
|
-
) {
|
|
131
|
-
for (const node of nodeChildren) {
|
|
132
|
-
if (
|
|
133
|
-
node.type === 'image' &&
|
|
134
|
-
typeof node.attributes.src === 'string' &&
|
|
135
|
-
shouldOptimizeImage(node.attributes.src)
|
|
136
|
-
) {
|
|
137
|
-
// Attempt to resolve source with Vite.
|
|
138
|
-
// This handles relative paths and configured aliases
|
|
139
|
-
const resolved = await ctx.pluginContext.resolve(node.attributes.src, ctx.filePath);
|
|
140
|
-
|
|
141
|
-
if (resolved?.id && fs.existsSync(new URL(prependForwardSlash(resolved.id), 'file://'))) {
|
|
142
|
-
const src = await emitESMImage(
|
|
143
|
-
resolved.id,
|
|
144
|
-
ctx.pluginContext.meta.watchMode,
|
|
145
|
-
ctx.pluginContext.emitFile,
|
|
146
|
-
{ config: ctx.astroConfig }
|
|
147
|
-
);
|
|
148
|
-
node.attributes.__optimizedSrc = src;
|
|
149
|
-
} else {
|
|
150
|
-
throw new MarkdocError({
|
|
151
|
-
message: `Could not resolve image ${JSON.stringify(
|
|
152
|
-
node.attributes.src
|
|
153
|
-
)} from ${JSON.stringify(ctx.filePath)}. Does the file exist?`,
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
await emitOptimizedImages(node.children, ctx);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function shouldOptimizeImage(src: string) {
|
|
162
|
-
// Optimize anything that is NOT external or an absolute path to `public/`
|
|
163
|
-
return !isValidUrl(src) && !src.startsWith('/');
|
|
164
|
-
}
|
package/src/load-config.ts
DELETED
|
@@ -1,102 +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 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
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
|
-
};
|
package/test/entry-prop.test.js
DELETED
|
@@ -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,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,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
|
-
}
|