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:
@@ -1,17 +1,26 @@
|
||||
import { invariant } from '@epic-web/invariant';
|
||||
import { allDocumentationPages, allPosts } from 'contentlayer/generated';
|
||||
import { getServerSideSitemap } from 'next-sitemap';
|
||||
|
||||
import { createCmsClient } from '@kit/cms';
|
||||
|
||||
import appConfig from '~/config/app.config';
|
||||
|
||||
invariant(appConfig.url, 'No NEXT_PUBLIC_SITE_URL environment variable found');
|
||||
|
||||
export async function GET() {
|
||||
const urls = getSiteUrls();
|
||||
const posts = getPostsSitemap();
|
||||
const docs = getDocsSitemap();
|
||||
const client = await createCmsClient();
|
||||
const contentItems = await client.getContentItems();
|
||||
|
||||
return getServerSideSitemap([...urls, ...posts, ...docs]);
|
||||
return getServerSideSitemap([
|
||||
...urls,
|
||||
...contentItems.map((item) => {
|
||||
return {
|
||||
loc: new URL(item.url, appConfig.url).href,
|
||||
lastmod: new Date().toISOString(),
|
||||
};
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
function getSiteUrls() {
|
||||
@@ -24,21 +33,3 @@ function getSiteUrls() {
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function getPostsSitemap() {
|
||||
return allPosts.map((post) => {
|
||||
return {
|
||||
loc: new URL(post.url, appConfig.url).href,
|
||||
lastmod: new Date().toISOString(),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function getDocsSitemap() {
|
||||
return allDocumentationPages.map((page) => {
|
||||
return {
|
||||
loc: new URL(page.url, appConfig.url).href,
|
||||
lastmod: new Date().toISOString(),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user