chore: bump version to 2.20.1 in package.json and refactor layout and… (#404)
* chore: bump version to 2.20.1 in package.json and refactor layout and form components - Incremented application version from 2.20.0 to 2.20.1 in package.json. - Refactored RootLayout to optimize asynchronous calls and introduced getRootClassName function for better class management. - Updated font handling in getFontsClassName function to streamline class generation. - Enhanced various authentication form components by replacing Input with EmailInput and PasswordInput for improved consistency and usability. - Adjusted layout styles in AuthLayoutShell and other components for better responsiveness. * fix: improve content rendering fallback logic in ContentRenderer component - Enhanced the ContentRenderer function to explicitly check for the presence of a renderer before returning content. - Added a fallback mechanism to return raw content as React nodes when no renderer is found, improving robustness and user experience.
This commit is contained in:
committed by
GitHub
parent
116d41a284
commit
ac12c9355c
@@ -1,4 +1,5 @@
|
||||
import type { CmsType } from '@kit/cms-types';
|
||||
import { CmsType } from '@kit/cms-types';
|
||||
import { createRegistry } from '@kit/shared/registry';
|
||||
|
||||
const CMS_CLIENT = process.env.CMS_CLIENT as CmsType;
|
||||
|
||||
@@ -7,42 +8,34 @@ interface ContentRendererProps {
|
||||
type?: CmsType;
|
||||
}
|
||||
|
||||
// Create a registry for CMS client implementations
|
||||
const cmsContentRendererRegistry = createRegistry<
|
||||
React.ComponentType<ContentRendererProps>,
|
||||
CmsType
|
||||
>();
|
||||
|
||||
export async function ContentRenderer({
|
||||
content,
|
||||
type = CMS_CLIENT,
|
||||
}: ContentRendererProps) {
|
||||
const Renderer = await getContentRenderer(type);
|
||||
const Renderer = await cmsContentRendererRegistry.get(type);
|
||||
|
||||
return Renderer ? <Renderer content={content} /> : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the content renderer for the specified CMS client.
|
||||
*
|
||||
* @param {CmsType} type - The type of CMS client.
|
||||
*/
|
||||
async function getContentRenderer(type: CmsType) {
|
||||
switch (type) {
|
||||
case 'keystatic': {
|
||||
const { KeystaticContentRenderer } = await import(
|
||||
'@kit/keystatic/renderer'
|
||||
);
|
||||
|
||||
return KeystaticContentRenderer;
|
||||
}
|
||||
|
||||
case 'wordpress': {
|
||||
const { WordpressContentRenderer } = await import(
|
||||
'@kit/wordpress/renderer'
|
||||
);
|
||||
|
||||
return WordpressContentRenderer;
|
||||
}
|
||||
|
||||
default: {
|
||||
console.error(`Unknown CMS client: ${type as string}`);
|
||||
|
||||
return null;
|
||||
}
|
||||
if (Renderer) {
|
||||
return <Renderer content={content} />;
|
||||
}
|
||||
|
||||
// fallback to the raw content if no renderer is found
|
||||
return content as React.ReactNode;
|
||||
}
|
||||
|
||||
cmsContentRendererRegistry.register('keystatic', async () => {
|
||||
const { KeystaticContentRenderer } = await import('@kit/keystatic/renderer');
|
||||
|
||||
return KeystaticContentRenderer;
|
||||
});
|
||||
|
||||
cmsContentRendererRegistry.register('wordpress', async () => {
|
||||
const { WordpressContentRenderer } = await import('@kit/wordpress/renderer');
|
||||
|
||||
return WordpressContentRenderer;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user