-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
32c1219
commit e902da9
Showing
4 changed files
with
68 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,58 @@ | ||
import { | ||
type StudioCMSRendererConfig, | ||
StudioCMSRendererConfigSchema, | ||
} from '@studiocms/core/schemas/renderer'; | ||
import integration from './integration'; | ||
import { runtimeLogger } from '@inox-tools/runtime-logger'; | ||
import { stringify } from '@studiocms/core/lib'; | ||
import type { StudioCMSRendererConfig } from '@studiocms/core/schemas/renderer'; | ||
import type { AstroIntegration } from 'astro'; | ||
import { addVirtualImports, createResolver } from 'astro-integration-kit'; | ||
import { name as pkgName } from '../package.json'; | ||
import { rendererDTS } from './stubs/renderer'; | ||
import { rendererConfigDTS } from './stubs/renderer-config'; | ||
import { rendererAstroMarkdownDTS } from './stubs/renderer-markdownConfig'; | ||
|
||
/** | ||
* StudioCMS Renderers Integration | ||
* **StudioCMS Renderers Integration** | ||
* | ||
* @param options StudioCMS Renderer Configuration | ||
* @returns AstroIntegration | ||
* | ||
* @see [StudioCMS Docs](https://docs.studiocms.dev) for more information on how to use StudioCMS. | ||
*/ | ||
const studioCMSRenderers = integration; | ||
export function studioCMSRenderers(options: StudioCMSRendererConfig): AstroIntegration { | ||
// Create resolver relative to this file | ||
const { resolve } = createResolver(import.meta.url); | ||
|
||
// Import the Renderer Component | ||
const RendererComponent = resolve('./components/StudioCMSRenderer.astro'); | ||
return { | ||
name: pkgName, | ||
hooks: { | ||
'astro:config:setup': (params) => { | ||
// Setup the runtime logger | ||
runtimeLogger(params, { name: 'studiocms-renderer' }); | ||
|
||
// Add Virtual Imports | ||
addVirtualImports(params, { | ||
name: pkgName, | ||
imports: { | ||
'studiocms:renderer': `export { default as StudioCMSRenderer } from '${RendererComponent}';`, | ||
'studiocms:renderer/config': `export default ${stringify(options)}`, | ||
'studiocms:renderer/astroMarkdownConfig': `export default ${stringify(params.config.markdown)}`, | ||
}, | ||
}); | ||
}, | ||
'astro:config:done': ({ injectTypes }) => { | ||
// Inject Types for Renderer | ||
injectTypes(rendererDTS(RendererComponent)); | ||
|
||
// Inject Types for Renderer Config | ||
injectTypes(rendererConfigDTS()); | ||
|
||
// Inject Types for Astro Markdown Config | ||
injectTypes(rendererAstroMarkdownDTS()); | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
export default studioCMSRenderers; | ||
|
||
export { StudioCMSRendererConfigSchema, type StudioCMSRendererConfig }; | ||
export type { StudioCMSRendererConfig }; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters