Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/[lang]/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default async function CatchAllPage({ params }: PageProps) {
isLogoSymbolism={isLogoSymbolism}
fishExplanationHtml={fishExplanation?.content ?? undefined}
childPages={childPages}
parentPath={pageSlug}
/>
)
}
8 changes: 6 additions & 2 deletions components/sections/GovernanceTOC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ import type { WPChildPage } from '@/lib/wordpress/api'

interface GovernanceTOCProps {
pages: WPChildPage[]
parentPath: string
heading?: string
description?: string
}

export default function GovernanceTOC({
pages,
parentPath,
heading,
description,
}: GovernanceTOCProps) {
if (pages.length === 0) return null

const base = parentPath && parentPath !== '/' ? `/${parentPath}` : ''

return (
<section className="py-16 sm:py-20">
<div className="cdcf-section">
Expand All @@ -33,8 +37,8 @@ export default function GovernanceTOC({
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
{pages.map((page) => (
<Link
key={page.slug}
href={page.uri}
key={page.enSlug}
href={`${base}/${page.enSlug}`}
className="group rounded-lg border border-gray-200 p-6 transition-all hover:border-cdcf-gold hover:shadow-md"
>
<h3 className="font-serif text-lg font-bold text-cdcf-navy transition-colors group-hover:text-cdcf-gold">
Expand Down
12 changes: 7 additions & 5 deletions components/sections/PageRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface PageRendererProps {
isLogoSymbolism?: boolean
fishExplanationHtml?: string
childPages?: WPChildPage[]
parentPath?: string
}

export default async function PageRenderer({
Expand All @@ -34,6 +35,7 @@ export default async function PageRenderer({
isLogoSymbolism,
fishExplanationHtml,
childPages = [],
parentPath = '/',
}: PageRendererProps) {
const template = page.template?.templateName || 'Default'
const t = await getTranslations('about')
Expand All @@ -52,9 +54,9 @@ export default async function PageRenderer({
{template === 'About' && renderAbout(page, t)}
{template === 'Projects' && renderProjects(page, projects, await getTranslations('projects'))}
{template === 'Community' && renderCommunity(page, await getTranslations('community'))}
{template === 'Blog' && renderBlog(page, posts)}
{template === 'Blog' && renderBlog(posts)}
{template === 'Contact' && renderContact(page)}
{template === 'Governance TOC' && renderGovernanceTOC(page, childPages)}
{template === 'Governance TOC' && renderGovernanceTOC(page, childPages, parentPath)}
{template === 'Default' && renderDefault(page, isLogoSymbolism, fishExplanationHtml)}

{/* CTA — shared across templates that use it */}
Expand Down Expand Up @@ -181,7 +183,7 @@ function renderCommunity(page: WPPage, t: (key: string) => string) {
)
}

function renderBlog(page: WPPage, posts: WPPost[]) {
function renderBlog(posts: WPPost[]) {
return <BlogFeed posts={posts} />
}

Expand All @@ -199,13 +201,13 @@ function renderContact(page: WPPage) {
)
}

function renderGovernanceTOC(page: WPPage, childPages: WPChildPage[]) {
function renderGovernanceTOC(page: WPPage, childPages: WPChildPage[], parentPath: string) {
return (
<>
{page.content && (
<TextSection heading="" body={page.content} />
)}
<GovernanceTOC pages={childPages} />
<GovernanceTOC pages={childPages} parentPath={parentPath} />
</>
)
}
Expand Down
18 changes: 15 additions & 3 deletions lib/wordpress/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,16 @@ export async function getAllPages(
}

export interface WPChildPage {
title: string
enSlug: string
modified: string
}

interface RawChildPage {
title: string
slug: string
uri: string
modified: string
translations?: { language: { code: string }; slug: string }[]
}

export async function getChildPages(
Expand All @@ -181,10 +187,16 @@ export async function getChildPages(
): Promise<WPChildPage[]> {
try {
const data = await wpQuery<{
pages: { nodes: WPChildPage[] }
pages: { nodes: RawChildPage[] }
}>(GET_CHILD_PAGES, { parentId: parentDatabaseId, language: langCode(locale) }, options)

return data.pages.nodes
return data.pages.nodes.map((node) => {
const enSlug =
locale === 'en'
? node.slug
: node.translations?.find((t) => t.language.code === 'EN')?.slug ?? node.slug
return { title: node.title, enSlug, modified: node.modified }
})
} catch (error) {
console.error('Failed to fetch child pages:', error)
return []
Expand Down
5 changes: 4 additions & 1 deletion lib/wordpress/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,11 @@ export const GET_CHILD_PAGES = `
nodes {
title
slug
uri
modified
translations {
language { code }
slug
}
}
}
}
Expand Down
Loading