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/config.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/config.ts')
-rw-r--r-- | packages/integrations/markdoc/src/config.ts | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/packages/integrations/markdoc/src/config.ts b/packages/integrations/markdoc/src/config.ts index 04a81c612..0a2870e23 100644 --- a/packages/integrations/markdoc/src/config.ts +++ b/packages/integrations/markdoc/src/config.ts @@ -5,11 +5,19 @@ import type { NodeType, Schema, } from '@markdoc/markdoc'; -import _Markdoc from '@markdoc/markdoc'; import type { AstroInstance } from 'astro'; +import _Markdoc from '@markdoc/markdoc'; import { heading } from './heading-ids.js'; +import { isRelativePath } from '@astrojs/internal-helpers/path'; +import { componentConfigSymbol } from './utils.js'; -type Render = AstroInstance['default'] | string; +export type Render = ComponentConfig | AstroInstance['default'] | string; +export type ComponentConfig = { + type: 'package' | 'local'; + path: string; + namedExport?: string; + [componentConfigSymbol]: true; +}; export type AstroMarkdocConfig<C extends Record<string, any> = Record<string, any>> = Omit< MarkdocConfig, @@ -30,3 +38,16 @@ export const nodes = { ...Markdoc.nodes, heading }; export function defineMarkdocConfig(config: AstroMarkdocConfig): AstroMarkdocConfig { return config; } + +export function component(pathnameOrPkgName: string, namedExport?: string): ComponentConfig { + return { + type: isNpmPackageName(pathnameOrPkgName) ? 'package' : 'local', + path: pathnameOrPkgName, + namedExport, + [componentConfigSymbol]: true, + }; +} + +function isNpmPackageName(pathname: string) { + return !isRelativePath(pathname) && !pathname.startsWith('/'); +} |