summaryrefslogtreecommitdiff
path: root/packages/integrations/markdoc/src/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/markdoc/src/utils.ts')
-rw-r--r--packages/integrations/markdoc/src/utils.ts33
1 files changed, 8 insertions, 25 deletions
diff --git a/packages/integrations/markdoc/src/utils.ts b/packages/integrations/markdoc/src/utils.ts
index 002d2238f..1fd896d52 100644
--- a/packages/integrations/markdoc/src/utils.ts
+++ b/packages/integrations/markdoc/src/utils.ts
@@ -1,28 +1,4 @@
-import matter from 'gray-matter';
-import type { ErrorPayload as ViteErrorPayload } from 'vite';
-
-/**
- * Match YAML exception handling from Astro core errors
- * @see 'astro/src/core/errors.ts'
- */
-export function parseFrontmatter(fileContents: string, filePath: string) {
- try {
- // `matter` is empty string on cache results
- // clear cache to prevent this
- (matter as any).clearCache();
- return matter(fileContents);
- } catch (e: any) {
- if (e.name === 'YAMLException') {
- const err: Error & ViteErrorPayload['err'] = e;
- err.id = filePath;
- err.loc = { file: e.id, line: e.mark.line + 1, column: e.mark.column };
- err.message = e.reason;
- throw err;
- } else {
- throw e;
- }
- }
-}
+import type { ComponentConfig } from './config.js';
/**
* Matches AstroError object with types like error codes stubbed out
@@ -97,3 +73,10 @@ export function hasContentFlag(viteId: string, flag: string): boolean {
const flags = new URLSearchParams(viteId.split('?')[1] ?? '');
return flags.has(flag);
}
+
+/** Identifier for components imports passed as `tags` or `nodes` configuration. */
+export const componentConfigSymbol = Symbol.for('@astrojs/markdoc/component-config');
+
+export function isComponentConfig(value: unknown): value is ComponentConfig {
+ return typeof value === 'object' && value !== null && componentConfigSymbol in value;
+}