Refactor content fetching and enhance UI mods
Refactored content fetching in the docs and blog pages to use a new 'getDocs' function to improve code reuse. Made minor adjustments to the UI in 'makerkit/page.tsx'. This involved modifying the layout and adding conditionals to tackle optional props. Also added a new textarea component reference in the UI package.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { unstable_cache as cache } from 'next/dist/server/web/spec-extension/unstable-cache';
|
import { cache } from 'react';
|
||||||
|
|
||||||
import { createCmsClient } from '@kit/cms';
|
import { createCmsClient } from '@kit/cms';
|
||||||
import { If } from '@kit/ui/if';
|
import { If } from '@kit/ui/if';
|
||||||
|
|||||||
14
apps/web/app/(marketing)/docs/_lib/server/docs.loader.ts
Normal file
14
apps/web/app/(marketing)/docs/_lib/server/docs.loader.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import { cache } from 'react';
|
||||||
|
|
||||||
|
import { createCmsClient } from '@kit/cms';
|
||||||
|
|
||||||
|
export const getDocs = cache(async (language: string | undefined) => {
|
||||||
|
const cms = await createCmsClient();
|
||||||
|
|
||||||
|
const { items: pages } = await cms.getContentItems({
|
||||||
|
collection: 'documentation',
|
||||||
|
language,
|
||||||
|
});
|
||||||
|
|
||||||
|
return pages;
|
||||||
|
});
|
||||||
@@ -1,16 +1,12 @@
|
|||||||
import { Cms, createCmsClient } from '@kit/cms';
|
import { Cms, createCmsClient } from '@kit/cms';
|
||||||
|
|
||||||
import { DocsNavigation } from '~/(marketing)/docs/_components/docs-navigation';
|
import { DocsNavigation } from '~/(marketing)/docs/_components/docs-navigation';
|
||||||
|
import { getDocs } from '~/(marketing)/docs/_lib/server/docs.loader';
|
||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
|
|
||||||
async function DocsLayout({ children }: React.PropsWithChildren) {
|
async function DocsLayout({ children }: React.PropsWithChildren) {
|
||||||
const cms = await createCmsClient();
|
|
||||||
const { resolvedLanguage } = await createI18nServerInstance();
|
const { resolvedLanguage } = await createI18nServerInstance();
|
||||||
|
const pages = await getDocs(resolvedLanguage);
|
||||||
const { items: pages } = await cms.getContentItems({
|
|
||||||
collection: 'documentation',
|
|
||||||
language: resolvedLanguage,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={'flex'}>
|
<div className={'flex'}>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { PageBody } from '@kit/ui/page';
|
|||||||
|
|
||||||
import { SitePageHeader } from '~/(marketing)/_components/site-page-header';
|
import { SitePageHeader } from '~/(marketing)/_components/site-page-header';
|
||||||
import { DocsCards } from '~/(marketing)/docs/_components/docs-cards';
|
import { DocsCards } from '~/(marketing)/docs/_components/docs-cards';
|
||||||
|
import { getDocs } from '~/(marketing)/docs/_lib/server/docs.loader';
|
||||||
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
import { createI18nServerInstance } from '~/lib/i18n/i18n.server';
|
||||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||||
|
|
||||||
@@ -16,18 +17,9 @@ export const generateMetadata = async () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const getContentItems = cache(async (resolvedLanguage: string | undefined) => {
|
|
||||||
const client = await createCmsClient();
|
|
||||||
|
|
||||||
return client.getContentItems({
|
|
||||||
collection: 'documentation',
|
|
||||||
language: resolvedLanguage,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
async function DocsPage() {
|
async function DocsPage() {
|
||||||
const { t, resolvedLanguage } = await createI18nServerInstance();
|
const { t, resolvedLanguage } = await createI18nServerInstance();
|
||||||
const { items } = await getContentItems(resolvedLanguage);
|
const items = await getDocs(resolvedLanguage);
|
||||||
|
|
||||||
// Filter out any docs that have a parentId, as these are children of other docs
|
// Filter out any docs that have a parentId, as these are children of other docs
|
||||||
const cards = items.filter((item) => !item.parentId);
|
const cards = items.filter((item) => !item.parentId);
|
||||||
|
|||||||
@@ -109,6 +109,7 @@
|
|||||||
"./radio-group": "./src/shadcn/radio-group.tsx",
|
"./radio-group": "./src/shadcn/radio-group.tsx",
|
||||||
"./separator": "./src/shadcn/separator.tsx",
|
"./separator": "./src/shadcn/separator.tsx",
|
||||||
"./input-otp": "./src/shadcn/input-otp.tsx",
|
"./input-otp": "./src/shadcn/input-otp.tsx",
|
||||||
|
"./textarea": "./src/shadcn/textarea.tsx",
|
||||||
"./utils": "./src/utils/index.ts",
|
"./utils": "./src/utils/index.ts",
|
||||||
"./if": "./src/makerkit/if.tsx",
|
"./if": "./src/makerkit/if.tsx",
|
||||||
"./trans": "./src/makerkit/trans.tsx",
|
"./trans": "./src/makerkit/trans.tsx",
|
||||||
|
|||||||
@@ -39,37 +39,41 @@ export function PageHeader({
|
|||||||
description,
|
description,
|
||||||
mobileNavigation,
|
mobileNavigation,
|
||||||
}: React.PropsWithChildren<{
|
}: React.PropsWithChildren<{
|
||||||
title: string | React.ReactNode;
|
title?: string | React.ReactNode;
|
||||||
description?: string | React.ReactNode;
|
description?: string | React.ReactNode;
|
||||||
mobileNavigation?: React.ReactNode;
|
mobileNavigation?: React.ReactNode;
|
||||||
}>) {
|
}>) {
|
||||||
return (
|
return (
|
||||||
<div className={'flex min-h-16 items-center justify-between border-b px-4'}>
|
<div className={'flex min-h-[4.5rem] items-center justify-between px-4'}>
|
||||||
<div
|
{title ? (
|
||||||
className={
|
<div
|
||||||
'flex items-center space-x-4 lg:flex-col lg:items-start lg:space-x-0 lg:space-y-0.5'
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<div className={'flex items-center lg:hidden'}>{mobileNavigation}</div>
|
|
||||||
|
|
||||||
<h1
|
|
||||||
className={
|
className={
|
||||||
'font-heading text-xl font-semibold leading-none dark:text-white'
|
'flex items-center space-x-4 lg:flex-col lg:items-start lg:space-x-0 lg:space-y-0.5'
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{title}
|
<div className={'flex items-center lg:hidden'}>
|
||||||
</h1>
|
{mobileNavigation}
|
||||||
|
</div>
|
||||||
|
|
||||||
<h2 className={'hidden lg:block'}>
|
<h1
|
||||||
<span
|
|
||||||
className={
|
className={
|
||||||
'text-base font-normal leading-none text-muted-foreground'
|
'font-heading text-xl font-semibold leading-none dark:text-white'
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{description}
|
{title}
|
||||||
</span>
|
</h1>
|
||||||
</h2>
|
|
||||||
</div>
|
<h2 className={'hidden lg:block'}>
|
||||||
|
<span
|
||||||
|
className={
|
||||||
|
'text-base font-medium leading-none text-muted-foreground'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{description}
|
||||||
|
</span>
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user