diff options
author | 2023-06-27 15:05:17 -0400 | |
---|---|---|
committer | 2023-06-27 15:05:17 -0400 | |
commit | fb7af551148f5ca6c4f98a4e556c8948c5690919 (patch) | |
tree | 7c65c758ead74ee129bc958279a6cf02e931cb4d /packages/integrations/markdoc/src/utils.ts | |
parent | 8821f0504845b351247ce6c1e2ae581a71806209 (diff) | |
download | astro-fb7af551148f5ca6c4f98a4e556c8948c5690919.tar.gz astro-fb7af551148f5ca6c4f98a4e556c8948c5690919.tar.zst astro-fb7af551148f5ca6c4f98a4e556c8948c5690919.zip |
feat: New Markdoc `render` API (#7468)
* feat: URL support for markdoc tags
* refactor: move to separate file
* feat: support URL for markdoc nodes
* feat: support `extends` with URL
* chore: changeset
* fix: bad AstroMarkdocConfig type
* fix: experimentalAssetsConfig missing
* fix: correctly merge runtime config
* chore: formatting
* deps: astro internal helpers
* feat: component() util, new astro bundling
* chore: remove now unused code
* todo: missing hint
* fix: import.meta.url type error
* wip: test nested collection calls
* feat: resolve paths from project root
* refactor: move getHeadings() to runtime module
* fix: broken collectHeadings
* test: update fixture configs
* chore: remove suggestions. Out of scope!
* fix: throw outside esbuild
* refactor: shuffle imports around
* Revert "wip: test nested collection calls"
This reverts commit 9354b3cf9222fd65b974b0cddf4e7a95ab3cd2b2.
* chore: revert back to mjs config
* chore: add jsdocs to stringified helpers
* fix: restore updated changeset
---------
Co-authored-by: bholmesdev <bholmesdev@gmail.com>
Diffstat (limited to 'packages/integrations/markdoc/src/utils.ts')
-rw-r--r-- | packages/integrations/markdoc/src/utils.ts | 33 |
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; +} |