Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Adammatthiesen committed Dec 13, 2024
1 parent 32c1219 commit e902da9
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 65 deletions.
8 changes: 8 additions & 0 deletions packages/studiocms_core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import i18nDTSOutput from './stubs/i18n-dts';
import libDtsFileOutput from './stubs/lib';
import sdkDtsFile from './stubs/sdk';

/**
* **StudioCMS Core Integration**
*
* @param options StudioCMS Configuration
* @returns AstroIntegration
*
* @see [StudioCMS Docs](https://docs.studiocms.dev) for more information on how to use StudioCMS.
*/
export function studioCMSCore(options: StudioCMSConfig): AstroIntegration {
return {
name: pkgName,
Expand Down
60 changes: 52 additions & 8 deletions packages/studiocms_renderers/src/index.ts
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 };
57 changes: 0 additions & 57 deletions packages/studiocms_renderers/src/integration.ts

This file was deleted.

8 changes: 8 additions & 0 deletions packages/studiocms_robotstxt/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ const defaultConfig: RobotsConfig = {
],
};

/**
* **Robots.txt Integration**
*
* A simple integration to generate a `robots.txt` file for your Astro project.
*
* @param astroConfig Robots Configuration
* @returns AstroIntegration
*/
export default function createRobotsIntegration(astroConfig: RobotsConfig): AstroIntegration {
let config: AstroConfig;
let finalSiteMapHref: string;
Expand Down

0 comments on commit e902da9

Please sign in to comment.