Refactor CMS to handle ContentLayer and WordPress platforms
This commit refactors the CMS to handle two platforms: ContentLayer and WordPress. The CMS layer is abstracted into a core package, and separate implementations for each platform are created. This change allows the app to switch the CMS type based on environment variable, which can improve the flexibility of content management. It also updates several functions in the `server-sitemap.xml` route to accommodate these changes and generate sitemaps based on the CMS client. Further, documentation content and posts have been relocated to align with the new structure. Notably, this refactor is a comprehensive update to the way the CMS is structured and managed.
This commit is contained in:
36
packages/cms/core/src/create-cms-client.ts
Normal file
36
packages/cms/core/src/create-cms-client.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { CmsClient } from './cms-client';
|
||||
import { CmsType } from './cms.type';
|
||||
|
||||
/**
|
||||
* Creates a CMS client based on the specified type.
|
||||
*
|
||||
* @param {CmsType} type - The type of CMS client to create. Defaults to the value of the CMS_CLIENT environment variable.
|
||||
* @returns {Promise<CmsClient>} A Promise that resolves to the created CMS client.
|
||||
* @throws {Error} If the specified CMS type is unknown.
|
||||
*/
|
||||
export async function createCmsClient(
|
||||
type: CmsType = process.env.CMS_CLIENT as CmsType,
|
||||
): Promise<CmsClient> {
|
||||
switch (type) {
|
||||
case 'contentlayer':
|
||||
return getContentLayerClient();
|
||||
|
||||
case 'wordpress':
|
||||
return getWordpressClient();
|
||||
|
||||
default:
|
||||
throw new Error(`Unknown CMS type: ${type}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function getContentLayerClient() {
|
||||
const { ContentlayerClient } = await import('@kit/contentlayer');
|
||||
|
||||
return new ContentlayerClient();
|
||||
}
|
||||
|
||||
async function getWordpressClient() {
|
||||
const { WordpressClient } = await import('@kit/wordpress');
|
||||
|
||||
return new WordpressClient();
|
||||
}
|
||||
Reference in New Issue
Block a user