localgreenchain/pages/[...slug].tsx
Claude 507df5912f
Deploy GrowerAdvisoryAgent (Agent 10) and fix type errors
- Add GrowerAdvisoryAgent test file
- Fix PlantChain constructor initialization order (plantIndex before genesis block)
- Fix blockchain.getChain() calls to use blockchain.chain property
- Add PropagationType export to blockchain types
- Fix SoilComposition.type property references (was soilType)
- Fix ClimateConditions.temperatureDay property references (was avgTemperature)
- Fix ClimateConditions.humidityAverage property references (was avgHumidity)
- Fix LightingConditions.naturalLight.hoursPerDay nested access
- Add 'critical' severity to QualityReport issues
- Add 'sqm' unit to PlantingRecommendation.quantityUnit
- Fix GrowerAdvisoryAgent growthMetrics property access
- Update TypeScript to v5 for react-hook-form compatibility
- Enable downlevelIteration in tsconfig for Map iteration
- Fix crypto Buffer type issues in anonymity.ts
- Fix zones.tsx status type comparison
- Fix next.config.js images.domains filter
- Rename [[...slug]].tsx to [...slug].tsx to resolve routing conflict
2025-11-23 00:44:58 +00:00

112 lines
2.8 KiB
TypeScript

import * as React from "react"
import {
GetStaticPathsContext,
GetStaticPathsResult,
GetStaticPropsContext,
GetStaticPropsResult,
} from "next"
import Head from "next/head"
import { useRouter } from "next/router"
import { DrupalNode } from "next-drupal"
import { drupal } from "lib/drupal"
import { getMenus } from "lib/get-menus"
import { absoluteURL } from "lib/utils/absolute-url"
import { getParams } from "lib/get-params"
import { Node } from "components/node"
import { Layout, LayoutProps } from "components/layout"
import { Meta } from "components/meta"
const RESOURCE_TYPES = ["node--page", "node--landing_page", "node--article"]
interface NodePageProps extends LayoutProps {
node: DrupalNode
}
export default function NodePage({ node, menus }: NodePageProps) {
const router = useRouter()
return (
<Layout menus={menus}>
<Meta title={node.title} tags={node.metatag} path={node.path?.alias} />
<Head>
{node.content_translations?.map((translation, index) =>
translation.langcode !== router.locale ? (
<link
key={index}
rel="alternate"
hrefLang={translation.langcode}
href={absoluteURL(translation.path)}
/>
) : null
)}
</Head>
<Node node={node} />
</Layout>
)
}
export async function getStaticPaths(
context: GetStaticPathsContext
): Promise<GetStaticPathsResult> {
return {
paths: await drupal.getStaticPathsFromContext(RESOURCE_TYPES, context, {
params: {
filter: {
"field_site.meta.drupal_internal__target_id":
process.env.DRUPAL_SITE_ID,
},
},
}),
fallback: "blocking",
}
}
export async function getStaticProps(
context: GetStaticPropsContext
): Promise<GetStaticPropsResult<NodePageProps>> {
const path = await drupal.translatePathFromContext(context)
if (!path || !RESOURCE_TYPES.includes(path.jsonapi.resourceName)) {
return {
notFound: true,
}
}
const type = path.jsonapi.resourceName
const node = await drupal.getResourceFromContext<DrupalNode>(path, context, {
params: getParams(type),
})
if (!node || (!context.preview && node?.status === false)) {
return {
notFound: true,
}
}
// Load initial view data.
if (type === "node--landing_page") {
for (const section of node.field_sections) {
if (section.type === "paragraph--view" && section.field_view) {
const view = await drupal.getView(section.field_view, {
params: {
include: "field_location,field_images.field_media_image",
},
})
section.field_view = {
name: section.field_view,
...view,
}
}
}
}
return {
props: {
node,
menus: await getMenus(context),
},
}
}