x
This commit is contained in:
1 parent
04987eebac
commit
b641acbeb7
3 files changed
+22
-35
No files matched your search
@@ -4,7 +4,6 @@ import { generateSeoMetadata } from '@/lib/seo'
|
|||||||
|
|
||||||
import DynamicPageRenderer from '@/components/dynamic/DynamicPageRenderer'
|
import DynamicPageRenderer from '@/components/dynamic/DynamicPageRenderer'
|
||||||
import { getCategoriesResult, getCmsPageResult } from '@/lib/cms'
|
import { getCategoriesResult, getCmsPageResult } from '@/lib/cms'
|
||||||
import { splitCmsLayoutSections } from '@/lib/cms-sections'
|
|
||||||
|
|
||||||
// lang is extracted from params
|
// lang is extracted from params
|
||||||
const reservedSlugs = new Set([
|
const reservedSlugs = new Set([
|
||||||
@@ -88,28 +87,14 @@ export default async function CmsCustomPage({ params }: { params: Promise<{ slug
|
|||||||
if (!page.isPublished) notFound()
|
if (!page.isPublished) notFound()
|
||||||
|
|
||||||
const categories = categoriesResult.ok ? categoriesResult.data : []
|
const categories = categoriesResult.ok ? categoriesResult.data : []
|
||||||
const sections = page.sections?.filter((section) => section.isActive) ?? []
|
const sections = (page.sections ?? [])
|
||||||
|
.filter((section) => section.isActive)
|
||||||
if (!categoriesResult.ok) {
|
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
|
||||||
console.error(`[website-cms] categories unavailable for CMS page "${slug}": ${categoriesResult.error}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
const { announcementSections, heroSections, bottomSections } = splitCmsLayoutSections(sections)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="min-h-[70vh] bg-surface-page text-text-main">
|
<main className="min-h-[70vh] bg-surface-page text-text-main">
|
||||||
{sections.length > 0 ? (
|
{sections.length > 0 ? (
|
||||||
<>
|
<DynamicPageRenderer sections={sections} categories={categories} lang={lang} />
|
||||||
{announcementSections.length > 0 && (
|
|
||||||
<DynamicPageRenderer sections={announcementSections} categories={categories} lang={lang} />
|
|
||||||
)}
|
|
||||||
{heroSections.length > 0 && (
|
|
||||||
<DynamicPageRenderer sections={heroSections} categories={categories} lang={lang} />
|
|
||||||
)}
|
|
||||||
{bottomSections.length > 0 && (
|
|
||||||
<DynamicPageRenderer sections={bottomSections} categories={categories} lang={lang} />
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
) : (
|
) : (
|
||||||
<div className="mx-auto max-w-4xl px-6 py-24 text-center">
|
<div className="mx-auto max-w-4xl px-6 py-24 text-center">
|
||||||
<p className="text-xs font-bold uppercase tracking-[0.28em] text-brand-primary"></p>
|
<p className="text-xs font-bold uppercase tracking-[0.28em] text-brand-primary"></p>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import type { Metadata } from 'next'
|
|||||||
import { generateSeoMetadata } from '@/lib/seo'
|
import { generateSeoMetadata } from '@/lib/seo'
|
||||||
import DynamicPageRenderer from '@/components/dynamic/DynamicPageRenderer'
|
import DynamicPageRenderer from '@/components/dynamic/DynamicPageRenderer'
|
||||||
import { getCategories, getCmsPage, getStoreSettings } from '@/lib/cms'
|
import { getCategories, getCmsPage, getStoreSettings } from '@/lib/cms'
|
||||||
import { splitCmsLayoutSections } from '@/lib/cms-sections'
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
params: Promise<{ lang: string }>
|
params: Promise<{ lang: string }>
|
||||||
@@ -46,23 +45,14 @@ export default async function HomePage({ params }: Props) {
|
|||||||
getCmsPage('home', lang),
|
getCmsPage('home', lang),
|
||||||
])
|
])
|
||||||
|
|
||||||
const sections = page?.sections ?? []
|
const sections = (page?.sections ?? [])
|
||||||
const { announcementSections, heroSections, bottomSections } = splitCmsLayoutSections(sections)
|
.filter((section) => section.isActive)
|
||||||
|
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-surface-page text-text-main">
|
<div className="min-h-screen bg-surface-page text-text-main">
|
||||||
{sections.length > 0 ? (
|
{sections.length > 0 ? (
|
||||||
<>
|
<DynamicPageRenderer sections={sections} categories={categories} lang={lang} />
|
||||||
{announcementSections.length > 0 && (
|
|
||||||
<DynamicPageRenderer sections={announcementSections} categories={categories} lang={lang} />
|
|
||||||
)}
|
|
||||||
{heroSections.length > 0 && (
|
|
||||||
<DynamicPageRenderer sections={heroSections} categories={categories} lang={lang} />
|
|
||||||
)}
|
|
||||||
{bottomSections.length > 0 && (
|
|
||||||
<DynamicPageRenderer sections={bottomSections} categories={categories} lang={lang} />
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
) : (
|
) : (
|
||||||
<section className="mx-auto flex min-h-[70vh] max-w-5xl flex-col items-center justify-center px-6 text-center">
|
<section className="mx-auto flex min-h-[70vh] max-w-5xl flex-col items-center justify-center px-6 text-center">
|
||||||
<p className="mb-4 ui-eyebrow">
|
<p className="mb-4 ui-eyebrow">
|
||||||
|
|||||||
@@ -1,14 +1,26 @@
|
|||||||
import type { PageSection } from '@homaroma/types'
|
import type { PageSection } from '@homaroma/types'
|
||||||
|
|
||||||
const announcementTypes = new Set(['ANNOUNCEMENT_BAR', 'ANNOUNCEMENT_BAR_MINIMAL'])
|
const announcementTypes = new Set(['ANNOUNCEMENT_BAR', 'ANNOUNCEMENT_BAR_MINIMAL'])
|
||||||
const heroTypes = new Set(['HERO', 'BANNER'])
|
const heroTypes = new Set([
|
||||||
|
'HERO',
|
||||||
|
'HERO_V2',
|
||||||
|
'HERO_VIDEO',
|
||||||
|
'HERO_CAROUSEL',
|
||||||
|
'HERO_ARTICLE',
|
||||||
|
'HERO_MINIMAL',
|
||||||
|
'HERO_SPLIT_MINIMAL',
|
||||||
|
'HERO_VIDEO_MINIMAL',
|
||||||
|
'BANNER',
|
||||||
|
])
|
||||||
|
|
||||||
function sectionType(section: PageSection) {
|
function sectionType(section: PageSection) {
|
||||||
return section.type.toUpperCase()
|
return section.type.toUpperCase()
|
||||||
}
|
}
|
||||||
|
|
||||||
export function splitCmsLayoutSections(sections: PageSection[]) {
|
export function splitCmsLayoutSections(sections: PageSection[]) {
|
||||||
const activeSections = sections.filter((section) => section.isActive)
|
const activeSections = sections
|
||||||
|
.filter((section) => section.isActive)
|
||||||
|
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
announcementSections: activeSections.filter((section) => announcementTypes.has(sectionType(section))),
|
announcementSections: activeSections.filter((section) => announcementTypes.has(sectionType(section))),
|
||||||
|
|||||||
Reference in new issue
Block a user