Skip to content

Commit

Permalink
Refactor Astro Markdown rendering logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Adammatthiesen committed Dec 22, 2024
1 parent 02c207f commit 68171ad
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/studiocms_renderers/src/lib/contentRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// import { logger } from '@it-astro:logger:studiocms-renderer';
import { logger } from '@it-astro:logger:studiocms-renderer';
import rendererConfig from 'studiocms:renderer/config';
import renderAstroMD from './astro-remark';
import renderMarkDoc from './markdoc';
Expand Down Expand Up @@ -29,21 +29,27 @@ const { renderer } = rendererConfig;
export async function contentRenderer(content: string): Promise<string> {
switch (renderer) {
case 'astro':
// logger.debug('Using built-in renderer: astro remark');
logger.debug('Using built-in renderer: astro remark');
return await renderAstroMD(content);
case 'markdoc':
// logger.debug('Using built-in renderer: markdoc');
logger.debug('Using built-in renderer: markdoc');
return await renderMarkDoc(content);
case 'mdx':
// logger.debug('Using built-in renderer: mdx');
logger.debug('Using built-in renderer: mdx');
return await renderAstroMDX(content);
default:
if (renderer.renderer) {
// logger.debug(`Using custom renderer: ${renderer.name}`);
try {
logger.debug(`Using custom renderer: ${renderer.name}`);
return await renderer.renderer(content);
} catch (e) {
if (e instanceof Error) {
logger.error(
`Error rendering with ${renderer.name}: ${e.message}, falling back to astro remark\n\n${e.stack}`
);
}
logger.error(`Error rendering with ${renderer.name}: ${e}, falling back to astro remark`);
return await renderAstroMD(content);
}
// logger.debug('Using built-in renderer: astro remark');
return await renderAstroMD(content);
}
}

Expand Down

0 comments on commit 68171ad

Please sign in to comment.