Optimize content fetching and update configurations

Content fetching in the marketing section has been refactored to utilize the Next.js cache, which significantly improves performance. The date format of publishedAt has been updated to be more consistent across files. Code related to CSRF token, fonts, and metadata has been refactored into separate files for easier maintenance and readability.
This commit is contained in:
giancarlo
2024-04-19 19:21:54 +08:00
parent c121a3bdad
commit b71b580331
12 changed files with 116 additions and 69 deletions

View File

@@ -1,5 +1,4 @@
import { cache } from 'react';
import { unstable_cache as cache } from 'next/cache';
import { notFound } from 'next/navigation';
import { ContentRenderer, createCmsClient } from '@kit/cms';

View File

@@ -1,3 +1,5 @@
import { unstable_cache as cache } from 'next/cache';
import { createCmsClient } from '@kit/cms';
import { PageBody } from '@kit/ui/page';
@@ -14,14 +16,18 @@ export const generateMetadata = async () => {
};
};
async function DocsPage() {
const getContentItems = cache(async (resolvedLanguage: string | undefined) => {
const client = await createCmsClient();
const { t, resolvedLanguage } = await createI18nServerInstance();
const { items } = await client.getContentItems({
return client.getContentItems({
collection: 'documentation',
language: resolvedLanguage,
});
});
async function DocsPage() {
const { t, resolvedLanguage } = await createI18nServerInstance();
const { items } = await getContentItems(resolvedLanguage);
// Filter out any docs that have a parentId, as these are children of other docs
const cards = items.filter((item) => !item.parentId);