From 7d1a22a5967e1f2ec3c76a6142b0a2852db491eb Mon Sep 17 00:00:00 2001 From: zhangxiang Date: Fri, 16 Oct 2026 20:34:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(ia):=20=E4=B8=80=E7=BA=A7=E5=AF=BC?= =?UTF-8?q?=E8=88=AA=E6=94=B9=E5=AF=B9=E6=A0=87=E5=8F=8C=E8=BD=B4=EF=BC=88?= =?UTF-8?q?=E8=A1=8C=E4=B8=9A=20=C3=97=20=E8=83=BD=E5=8A=9B=20+=20?= =?UTF-8?q?=E6=B4=9E=E5=AF=9F=EF=BC=89=EF=BC=8C=E5=B9=B6=E6=8A=8A=E5=AF=BC?= =?UTF-8?q?=E8=88=AA=E7=9C=9F=E6=BA=90=E4=BB=8E=20DB=20=E8=A1=8C=E5=8F=8D?= =?UTF-8?q?=E8=BD=AC=E4=B8=BA=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 依据实测:Bain 一级导航 = Industries · Consulting Services · Digital · Insights · About · Careers, Porsche = 行业 · 实践 · 洞察 · 职业 · 关于我们 —— **两家的导航里都没有「产品」**。 咨询业按「客户的问题空间 × 本所的能力」组织,不按产品 SKU 组织。本仓此前 7 项里 产品居首,且 案例(case-study 0 行)、新闻动态(2 行) 是挂在骨架上的空渠道。 落地策略是**换标签、不换路由**:行业→既有 /solutions(solution 模型本就是行业), 能力→既有 /services(service 模型的 4 行本就是能力组)。 理由不是省事,而是避免制造重复内容:若新增 /capabilities 与 /services 并行, 同一个 ContentItem 会同时挂在两个 URL 下 —— 那是 canonical 冲突,比不改更糟。 URL 改名 + 308 留给第二批一次性处理。唯一真正新增的面是 /insights: 它聚合 news + methodology + case-study,今天没有任何单一页面做过这件事,故不构成重复。 「轴 = 视图,模型 = 真源」:本轮零新 ContentModel、零 schema、零 seed 权限测试改动。 沿用 solution/service/product 三个 code ⇒ src/lib/seed-permissions.test.ts:50 的 SUPER_ADMIN_ONLY_MODELS 断言保持绿。**这是设计选择的回报,不是没做事。** 最关键的一处:反转导航优先级 layout.tsx 原为 `(navData?.mainNav) || NAVIGATION_V2` —— **DB 行胜出、代码只兜底**。 `navigation` 的字段是泛型 json,改导航不需动 schema,听起来省事,实际是: 只改 navigation.ts 会上线一个**生产静默忽略它**的新导航。 而 footer 按 megaDropdown 的 key 取栏目 —— 新代码 key 对旧 DB key ⇒ 页脚三栏静默变空。 我在工作树里真的复现了这个状态:本地 navigation/default 行仍是旧 7 项, 它**内部完全自洽**(每个 dropdownKey 都找得到面板),所以「自洽即放行」会继续覆盖代码。 ⇒ 新校验器的标准是「它是不是这套 IA」(必须覆盖 industries/capabilities/insights 三轴), 而不是「它是不是合法 JSON」。不合格则 fail-closed 到代码 + 把原因 console.warn 出来 (渲染期不写库:Notification 是后台数据,在 RSC 里写它等于给每次首页渲染挂写副作用)。 这条有专门用例:「旧 IA 的自洽配置必须被拒」。 顺带修掉两处同族缺陷 - injectStandaloneProducts 原按 `key === 'products'` 匹配;双轴改名后该 key 不存在 ⇒ 独立产品会**静默不再注入**。改为按组 id(STANDALONE_GROUP_ID)找,组 id 比 key 稳定。 - 激活判定原来有**三套**:header 的 8 分支 per-id 阶梯(末尾落回 pathname===`/${item.id}`, 新 id industries 会拼出一个不存在的路由 ⇒ 行业永不高亮)、mobile-tab-bar 的 per-id if 阶梯(改名后每项静默返回 false ⇒ tab bar 照渲染、永不高亮 = 绿但空洞)、footer 自一套。 现统一为 lib/nav-active.ts,按 segment 切(不被 /solutionship 这类同前缀误点亮)。 撤下两个空渠道入口(含一处我自己计划里的回退,已当场纠正) - /cases 从一级导航与移动端 tab bar 撤下:case-study 0 行,点进去是空列表。 路由与模型**保留休眠**,真实授权案例到位当天即可渲染,不必二次迁移。 - 补 { id: 'all-products', href: '/products' } 进能力轴第二层: 撤「产品」时若不补这一条,/products(sitemap priority 0.9、6 个详情页的上游 hub) 就变成**没有导航入口的孤儿页** —— 那是回退不是重构。「降级」不等于「消失」, 已加守卫用例「被退出一级导航的 hub 必须在第二层仍可达」。 /insights 的三处登记(少一处就是「新页面没人扫、门禁仍然绿」的静默覆盖收缩) - sitemap.ts:新增,priority 0.8;/news 暂留(已索引),第二批 301 归并 - check:headings 的 PAGES 列表:新增(该列表是硬编码路由清单) - revalidate:新增 INSIGHTS_AFFECTED_MODELS(news/case-study/methodology) —— /insights 不在 CONTENT_TYPE_CONFIGS 的任何 listPage 里,通用推导只刷 /news、 /methodology;少登记这条的后果不是报错,而是后台发了新内容、洞察页仍端出旧 ISR 快照最长 1 小时,且没有任何门禁会红。已钉 3 正向 + 1 负向(product 变更不得刷 /insights,否则该断言恒真、失去约束力)+ 1 去重。 删除 NAVIGATION(V1):7 个 href 全是 '/'、全站零生产引用,只被 constants.test.ts 供着 —— 那 4 条用例的作用是让死码看起来「有人在用」。已改写成断言活的 NAVIGATION_V2, 并保留其原有意图(每个目的地互不相同,正是 V1 缺的那条)。 KNOWN-RED: test:visual —— 一级导航 7→4、页脚三栏改标题改取数、移动端 tab bar 换轴, header/footer 相关基线预期 churn。按计划 #10 在所有代码落地后一次性重捕(需 AUTH-VISUAL)。 待授权(本笔**未**执行,且必须执行才能对用户生效): CMS 的 navigation/default 行仍是旧 7 项。本笔的反转校验会让它 fail-closed 到代码, 所以**新导航会立即在页面上生效**(不再被旧行遮蔽),但后台那一行要改需 `npm run db:seed`(生产为独立授权动作)。seed.ts:945 直接引用 NAVIGATION_V2, 重跑即得新行 —— 本地已复跑验证过(库内 mainNav 已是 industries/capabilities/insights)。 门禁实测:type-check EXIT=0 · 全量 jest 146 套件 / 1807 例通过 · eslint --quiet 改动文件 0 error · check:grammar 9/9 及其 selftest 9/9 · check:token-twins 44/44 · check:contrast 44/44 · check:brand-token 0 违规 · e2e nav-keyboard@chromium 6 passed(含 /insights 实测 HTTP 200) --- e2e/nav-keyboard.spec.ts | 25 ++- e2e/user-journey.spec.ts | 9 +- scripts/utils/check-heading-hierarchy.ts | 2 + .../insights/insights-content.test.tsx | 59 ++++++ .../(marketing)/insights/insights-content.tsx | 177 ++++++++++++++++ src/app/(marketing)/insights/page.tsx | 75 +++++++ src/app/api/cms/revalidate/route.test.ts | 31 +++ src/app/api/cms/revalidate/route.ts | 15 ++ src/app/layout.tsx | 31 ++- src/app/sitemap.ts | 3 + src/components/layout/footer.test.tsx | 54 +++-- src/components/layout/footer.tsx | 50 +++-- src/components/layout/header.tsx | 29 +-- src/components/layout/mobile-tab-bar.test.tsx | 24 ++- src/components/layout/mobile-tab-bar.tsx | 37 ++-- src/lib/constants.test.ts | 37 ++-- src/lib/constants.ts | 4 +- src/lib/constants/index.ts | 4 +- src/lib/constants/navigation.ts | 158 +++++++++----- src/lib/nav-active.test.ts | 50 +++++ src/lib/nav-active.ts | 37 ++++ src/lib/navigation-resolution.test.ts | 192 ++++++++++++++++++ src/lib/navigation-resolution.ts | 177 ++++++++++++++++ 23 files changed, 1083 insertions(+), 197 deletions(-) create mode 100644 src/app/(marketing)/insights/insights-content.test.tsx create mode 100644 src/app/(marketing)/insights/insights-content.tsx create mode 100644 src/app/(marketing)/insights/page.tsx create mode 100644 src/lib/nav-active.test.ts create mode 100644 src/lib/nav-active.ts create mode 100644 src/lib/navigation-resolution.test.ts create mode 100644 src/lib/navigation-resolution.ts diff --git a/e2e/nav-keyboard.spec.ts b/e2e/nav-keyboard.spec.ts index 48fb1da..10462db 100644 --- a/e2e/nav-keyboard.spec.ts +++ b/e2e/nav-keyboard.spec.ts @@ -9,12 +9,20 @@ import { expectHydrated } from './hydrated'; const NAV_SELECTOR = 'nav[aria-label="主导航"]'; +// 2026-10-16:原用例把触发器标签硬编码成「产品」。决策 2 把产品退出一级导航后 +// 那个按钮不存在 ⇒ 4 条键盘用例集体判红。改用「行业」(行业轴的下拉面板是 /solutions/*, +// 与导航项自身 href 同前缀,最能顺带验证「查看全部」与面板内容同源)。 +// ⚠ 标签与面板 href 前缀必须成对改:只改标签不改 href 断言, +// 「Tab 焦点进入面板链接」那条会退化成断言一个面板里不存在的选择器。 +const DROPDOWN_LABEL = '行业'; +const PANEL_HREF_PREFIX = '/solutions/'; + function productTrigger(page: Page) { - return page.getByRole('navigation', { name: '主导航' }).getByRole('button', { name: '产品', exact: true }); + return page.getByRole('navigation', { name: '主导航' }).getByRole('button', { name: DROPDOWN_LABEL, exact: true }); } function viewAllLink(page: Page) { - return page.getByRole('link', { name: '查看全部产品' }); + return page.getByRole('link', { name: `查看全部${DROPDOWN_LABEL}` }); } async function openWithKeyboard(page: Page) { @@ -57,6 +65,7 @@ test.describe('主导航下拉的键盘可操作性', { tag: '@a11y' }, () => { // 焦点顺序实测(chromium + firefox,:3120 生产产物与 dev 目标读数一致): // 第 1 站「跳转到主要内容」跳转链接,第 2 站 logo「返回首页」,第 3 站才是本触发器。 + // (双轴改名后一级导航只剩 4 项,前三站的顺序不变,故 Tab 次数仍为 3) await page.keyboard.press('Tab'); await page.keyboard.press('Tab'); await page.keyboard.press('Tab'); @@ -71,7 +80,7 @@ test.describe('主导航下拉的键盘可操作性', { tag: '@a11y' }, () => { test.skip(browserName === 'webkit', 'WebKit 本机不响应真实 Tab 键(N-27,见上方注释)'); await openWithKeyboard(page); await page.keyboard.press('Tab'); - await expect(page.locator(`${NAV_SELECTOR} a[href^="/products/"]:focus`)).toHaveCount(1); + await expect(page.locator(`${NAV_SELECTOR} a[href^="${PANEL_HREF_PREFIX}"]:focus`)).toHaveCount(1); }); test('Escape 关闭面板并把焦点还给触发器', async ({ page }) => { @@ -98,9 +107,15 @@ test.describe('主导航下拉的键盘可操作性', { tag: '@a11y' }, () => { // 修法是把导航项自身 href 传进去(props.viewAllHref)。 // 下面这条是它的**浏览器层负对照**:单测已锁住组件契约,但「header 有没有真的把 href 传下来」 // 只有在真实渲染里才看得见 —— 少传一个 prop,单测全绿而线上静默退化。 +// 2026-10-16 双轴改名后的预期表。 +// ⚠ 这张表是**故意硬编码**的:它同时是「导航标签」「下拉存在」与「查看全部落点」三件事的 +// 交叉对账。测试里另有一条 `expect(count).toBe(Object.keys(...).length)`, +// 所以新增一个带下拉的导航项而忘了登记 ⇒ 分母守卫判红,不会"少测一个"静默放行。 +// 「产品」不再是下拉项(决策 2:产品退出一级导航),它的矩阵活在能力轴里。 const VIEW_ALL_EXPECTED: Record = { - 产品: '/products', - 解决方案: '/solutions', + 行业: '/solutions', + 能力: '/services', + 洞察: '/insights', }; test.describe('主导航「查看全部」的目的地', { tag: '@a11y' }, () => { diff --git a/e2e/user-journey.spec.ts b/e2e/user-journey.spec.ts index b7634b2..6fb4e29 100644 --- a/e2e/user-journey.spec.ts +++ b/e2e/user-journey.spec.ts @@ -36,9 +36,12 @@ async function closeCookieBanner(page: Page) { /** * 从桌面主导航的产品下拉菜单中导航到指定链接 */ -async function navigateFromProductDropdown(page: Page, linkText: string) { +// 2026-10-16 改名并泛化:一级导航不再有「产品」(决策 2),/products 的入口降级为 +// 能力轴第二层的「产品矩阵总览」。原来的 helper 硬编码 button:has-text("产品"), +// 改名后它会稳定判红 —— 这是**好事**:它证明这条旅程真的在走导航,而不是在假装。 +async function navigateFromDropdown(page: Page, dropdownLabel: string, linkText: string) { const desktopNav = page.locator('[data-testid="desktop-navigation"]').first(); - const productDropdown = desktopNav.locator('button:has-text("产品")').first(); + const productDropdown = desktopNav.locator(`button:has-text("${dropdownLabel}")`).first(); await expect(productDropdown).toBeVisible({ timeout: 5000 }); await productDropdown.hover(); await page.waitForTimeout(300); @@ -71,7 +74,7 @@ test.describe('UJ-01: 潜在客户从首页到联系表单的完整旅程', () = await expect(heroDescription).toBeVisible(); // === Step 2: 通过导航下拉菜单进入产品页面 === - await navigateFromProductDropdown(page, '查看全部产品'); + await navigateFromDropdown(page, '能力', '产品矩阵总览'); // === Step 3: 验证产品页面加载成功 === await page.waitForURL(/\/products/, { timeout: 10000 }); diff --git a/scripts/utils/check-heading-hierarchy.ts b/scripts/utils/check-heading-hierarchy.ts index 5ba630a..1c3efd7 100644 --- a/scripts/utils/check-heading-hierarchy.ts +++ b/scripts/utils/check-heading-hierarchy.ts @@ -25,6 +25,8 @@ const PAGES = [ { path: "/services", name: "服务列表" }, { path: "/services/software", name: "服务详情-软件开发" }, { path: "/news", name: "新闻列表" }, + // 双轴新增的洞察枢纽 —— 不登记就会出现「新页面没人扫,门禁仍然绿」的静默覆盖收缩 + { path: "/insights", name: "洞察枢纽" }, { path: "/contact", name: "联系我们" }, ]; diff --git a/src/app/(marketing)/insights/insights-content.test.tsx b/src/app/(marketing)/insights/insights-content.test.tsx new file mode 100644 index 0000000..56bb6e6 --- /dev/null +++ b/src/app/(marketing)/insights/insights-content.test.tsx @@ -0,0 +1,59 @@ +/** + * 洞察枢纽的两条诚实性约束(都能失败,不是给实现打气): + * 1. 筛选器只列**真的有内容**的分类 —— 本仓此前把 案例(0 行) 挂在一级导航上, + * 这条就是防它在新页面上重演。 + * 2. 0 条目必须落在"看得见的空态",而不是渲染一个空网格装作有内容。 + */ +import { describe, it, expect, jest } from '@jest/globals'; +import { render, screen, fireEvent } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import InsightsContent, { type InsightEntry } from './insights-content'; + +jest.mock('@/components/ui/static-link', () => ({ + StaticLink: ({ children, href, ...rest }: { children: React.ReactNode; href: string; [k: string]: unknown }) => ( + {children} + ), +})); +jest.mock('@/components/ui/scroll-reveal', () => ({ + ScrollReveal: ({ children }: { children: React.ReactNode }) =>
{children}
, + StaggerReveal: ({ children }: { children: React.ReactNode }) =>
{children}
, +})); +jest.mock('@/components/ui/cta-button', () => ({ + CTAButton: ({ children, href }: { children: React.ReactNode; href: string }) => ( + {children} + ), +})); + +const METH: InsightEntry = { id: 'm1', kind: 'methodology', title: '四步诊断法', excerpt: '从业务目标出发', date: '', href: '/methodology' }; +const WRITING: InsightEntry = { id: 'w1', kind: 'writing', title: '私有化部署', excerpt: '数据主权', date: '2026-08', href: '/news/1' }; + +describe('洞察筛选器的分母纪律', () => { + it('案例 0 行时,「客户成果」这个 tab 不允许出现', () => { + render(); + expect(screen.queryByRole('tab', { name: '客户成果' })).not.toBeInTheDocument(); + expect(screen.getByRole('tab', { name: '方法论' })).toBeInTheDocument(); + expect(screen.getByRole('tab', { name: '技术与观点' })).toBeInTheDocument(); + }); + + it('case-study 一旦出数,「客户成果」tab 自动出现(插槽真的能插,不是空话)', () => { + const real: InsightEntry = { + id: 'c1', kind: 'case', title: '某制造企业库存周转', excerpt: '', date: '2026-09', + href: '/cases/x', industry: '制造业', + }; + render(); + expect(screen.getByRole('tab', { name: '客户成果' })).toBeInTheDocument(); + }); + + it('完全无内容 ⇒ 走空态而不是空网格', () => { + render(); + expect(screen.getByTestId('insights-empty')).toBeInTheDocument(); + expect(screen.queryAllByTestId(/^insight-card-/)).toHaveLength(0); + }); + + it('点「方法论」后只留方法论条目(过滤真的生效,不是只改了按钮态)', () => { + render(); + fireEvent.click(screen.getByRole('tab', { name: '方法论' })); + expect(screen.getAllByTestId('insight-card-methodology')).toHaveLength(1); + expect(screen.queryAllByTestId('insight-card-writing')).toHaveLength(0); + }); +}); diff --git a/src/app/(marketing)/insights/insights-content.tsx b/src/app/(marketing)/insights/insights-content.tsx new file mode 100644 index 0000000..4cf99e9 --- /dev/null +++ b/src/app/(marketing)/insights/insights-content.tsx @@ -0,0 +1,177 @@ +'use client'; + +import { useMemo, useState } from 'react'; +import { StaticLink } from '@/components/ui/static-link'; +import { ScrollReveal } from '@/components/ui/scroll-reveal'; +import { CTAButton } from '@/components/ui/cta-button'; +import { COMPANY_INFO } from '@/lib/constants'; +import { cn } from '@/lib/utils'; +import { ArrowRight } from 'lucide-react'; + +export type InsightKind = 'methodology' | 'case' | 'writing'; + +export interface InsightEntry { + id: string; + kind: InsightKind; + title: string; + excerpt: string; + /** ISO 或 'YYYY-MM';方法论这类"页面型"条目没有日期,留空 */ + date: string; + href: string; + industry?: string; +} + +const KIND_LABEL: Record = { + methodology: '方法论', + case: '客户成果', + writing: '技术与观点', +}; + +/** + * 洞察枢纽 —— 对标 Bain「Our Latest Insights」/ Porsche「In Focus: News & Trends」。 + * + * 语法取自实测:零圆角(bain-card 现 --radius-lg = 2px)、近单色、 + * 卡片 hover 只改边框与底色(不抬升、不加阴影),成果类数字本轮不出现—— + * 因为 case-study 模型是 0 行,任何数字都得编。 + * + * 诚实性约束(可失败,见 insights-content.test.tsx): + * 1. 筛选器只列**真的有内容**的 kind。案例 0 行 ⇒ 不给「客户成果」这个 tab, + * 否则就是挂一个点开为空的频道(本仓此前 /cases 正是这样挂在一级导航上的)。 + * 2. 0 条目时的空态必须是"看得见的空态",不拿模板文案冒充内容。 + */ +export default function InsightsContent({ entries }: { entries: InsightEntry[] }) { + const presentKinds = useMemo( + () => (['methodology', 'case', 'writing'] as InsightKind[]).filter((k) => entries.some((e) => e.kind === k)), + [entries], + ); + const [active, setActive] = useState<'all' | InsightKind>('all'); + + const visible = active === 'all' ? entries : entries.filter((e) => e.kind === active); + + return ( +
+ {/* L1 —— 结论式主张,不是口号 */} +
+
+ +

洞察

+

+ 我们怎么判断、怎么交付、怎么验收 +

+

+ {COMPANY_INFO.displayName}的公开写作与方法论。凡涉及效果的数字,都会标明它是 + 目标口径、 + 团队历史还是 + 已验证结果。 +

+
+
+
+ + {/* 列表 */} +
+
+
+

全部内容

+ {/* 筛选器只列有内容的 kind:这是「不给空频道挂入口」那条约束的实现处 */} +
+ setActive('all')} /> + {presentKinds.map((k) => ( + setActive(k)} + /> + ))} +
+
+ + {visible.length === 0 ? ( + /* 空态必须是"看得见的空态" —— 不拿模板文案冒充内容 */ +
+

+ 这一类目前还没有已发布的内容。 +
+ 客户成果要等真实项目获得对外授权后才会出现在这里。 +

+
+ ) : ( +
    + {visible.map((entry) => ( +
  • + +
    + {KIND_LABEL[entry.kind]} + {entry.industry && ( + · {entry.industry} + )} + {entry.date && ( + {entry.date} + )} +
    +

    {entry.title}

    + {entry.excerpt && ( +

    {entry.excerpt}

    + )} + + 阅读 + +
    +
  • + ))} +
+ )} +
+
+ + {/* L4 CTA */} +
+
+

有具体场景想聊?

+

+ 把你的问题带来,我们先给判断,再谈方案。 +

+
+ 预约咨询 + + 查看能力组 + +
+
+
+
+ ); +} + +function FilterTab({ + label, + activeState, + onClick, +}: { + label: string; + activeState: boolean; + onClick: () => void; +}) { + return ( + + ); +} diff --git a/src/app/(marketing)/insights/page.tsx b/src/app/(marketing)/insights/page.tsx new file mode 100644 index 0000000..4351a18 --- /dev/null +++ b/src/app/(marketing)/insights/page.tsx @@ -0,0 +1,75 @@ +import { Metadata } from 'next'; +import { COMPANY_INFO } from '@/lib/constants'; +import { getPublishedItems } from '@/lib/cms/data-server'; +import type { NewsItem } from '@/lib/constants/news'; +import InsightsContent, { type InsightEntry } from './insights-content'; + +export const metadata: Metadata = { + title: `洞察 - ${COMPANY_INFO.displayName}`, + description: `${COMPANY_INFO.displayName}的方法论、技术与观点:数字化转型怎么判断、怎么交付、怎么验收。`, +}; + +// ISR 与 /news 同档;CMS 发布经 /api/cms/revalidate 主动刷新。 +// ⚠ 新路由必须同步进 revalidate 的路径表与 check:headings 的 PAGES, +// 否则「全站扫描」的分母会静默变小而门禁仍然绿。 +export const revalidate = 3600; + +/** 洞察条目 kind:news 分类沿用既有 taxonomy,方法论与案例是另外两路真源 */ +async function buildEntries(): Promise { + const [newsItems, caseItems, methodologyItems] = await Promise.all([ + getPublishedItems('news').catch(() => []), + getPublishedItems('case-study').catch(() => []), + getPublishedItems('methodology').catch(() => []), + ]); + + const news: InsightEntry[] = newsItems.map((item) => { + const data = item.data as unknown as NewsItem; + return { + id: `news-${data.id || item.slug}`, + kind: 'writing' as const, + title: data.title || item.title, + excerpt: data.excerpt || '', + date: data.date || '', + href: `/news/${data.id || item.slug}`, + }; + }); + + // 方法论:/methodology 是一个 4 阶段的页面型模型(1 行),不是逐篇内容 + const methodology: InsightEntry[] = methodologyItems.map((item) => { + const data = item.data as { title?: string; description?: string; summary?: string }; + return { + id: `methodology-${item.slug}`, + kind: 'methodology' as const, + title: data.title || item.title, + excerpt: data.description || data.summary || '', + date: '', + href: '/methodology', + }; + }); + + /** + * 案例:**当前恒为空数组**,因为 case-study 模型 0 行 + * (prisma/seeds/case-studies.ts:11 明示「首批客户共创阶段,暂无对外可验证的客户案例」)。 + * 零编造原则下这里不造任何条目;真实授权案例落库的当天,下面的 map 就开始出数, + * 前端不需要再改一行 —— 这就是「留结构化插槽」的实际含义。 + */ + const cases: InsightEntry[] = caseItems.map((item) => { + const data = item.data as { title?: string; excerpt?: string; industry?: string; publishedAt?: string }; + return { + id: `case-${item.slug}`, + kind: 'case' as const, + title: data.title || item.title, + excerpt: data.excerpt || '', + date: data.publishedAt || '', + industry: data.industry, + href: `/cases/${item.slug}`, + }; + }); + + return [...methodology, ...cases, ...news].sort((a, b) => (b.date || '').localeCompare(a.date || '')); +} + +export default async function InsightsPage() { + const entries = await buildEntries(); + return ; +} diff --git a/src/app/api/cms/revalidate/route.test.ts b/src/app/api/cms/revalidate/route.test.ts index 5e9a8ba..d212e9e 100644 --- a/src/app/api/cms/revalidate/route.test.ts +++ b/src/app/api/cms/revalidate/route.test.ts @@ -287,3 +287,34 @@ describe('POST /api/cms/revalidate', () => { expect(body.data.revalidatedPaths).toContain('/products/erp-upgrade'); }); }); + +// ── 洞察枢纽的失效映射(2026-10-16 双轴改造新增路由)────────────────────── +// /insights 不在 CONTENT_TYPE_CONFIGS 的任何 listPage 里 ⇒ 通用推导只会刷 /news、 +// /methodology。少登记这一条的后果不是报错,而是**后台发了新内容、洞察页仍端出旧 +// ISR 快照,最长 1 小时,且没有任何门禁会红**。所以正反两向都要钉住。 +describe('POST /api/cms/revalidate —— /insights 失效映射', () => { + it.each(['news', 'case-study', 'methodology'])( + '%s 变更必须同时刷 /insights', + async (modelCode) => { + const response = await POST(createMockRequest({ modelCode })); + const body = await response.json(); + + expect(response.status).toBe(200); + expect(mockRevalidatePath).toHaveBeenCalledWith('/insights'); + expect(body.data.revalidatedPaths).toContain('/insights'); + }, + ); + + // 负对照:映射不能宽到「什么都刷」——那会让这条断言恒真、失去约束力 + it('product 变更不该刷 /insights(洞察轴不读 product 模型)', async () => { + const response = await POST(createMockRequest({ modelCode: 'product', slug: 'erp' })); + expect(response.status).toBe(200); + expect(mockRevalidatePath).not.toHaveBeenCalledWith('/insights'); + }); + + it('同一 modelCode 重复调用只刷一次 /insights(去重仍成立)', async () => { + await POST(createMockRequest({ modelCode: 'news', slug: 'a' })); + const calls = mockRevalidatePath.mock.calls.filter((c) => c[0] === '/insights'); + expect(calls).toHaveLength(1); + }); +}); diff --git a/src/app/api/cms/revalidate/route.ts b/src/app/api/cms/revalidate/route.ts index 0202ba6..87b12cc 100644 --- a/src/app/api/cms/revalidate/route.ts +++ b/src/app/api/cms/revalidate/route.ts @@ -20,6 +20,12 @@ const HOME_AFFECTED_MODELS = new Set([ 'news', ]); +// 洞察枢纽 /insights 的数据来自三路真源:news(技术与观点)、case-study(客户成果,当前 0 行)、 +// methodology(方法论)。它**不在** CONTENT_TYPE_CONFIGS 的任何 listPage 里 —— +// 通用推导只会刷 /news、/methodology,于是后台发了新内容而 /insights 仍端出旧 ISR 快照, +// 最长 1 小时不可见,且没有任何门禁会红。新路由必须显式登记失效映射。 +const INSIGHTS_AFFECTED_MODELS = new Set(['news', 'case-study', 'methodology']); + interface RevalidateRequestBody { event?: string; modelCode?: string; @@ -122,6 +128,15 @@ export async function POST(request: NextRequest) { revalidatedPaths.push('/products/erp-upgrade'); } + // 洞察枢纽:三个上游模型任一变更都要刷 /insights + if ( + INSIGHTS_AFFECTED_MODELS.has(body.modelCode) && + !revalidatedPaths.includes('/insights') + ) { + revalidatePath('/insights'); + revalidatedPaths.push('/insights'); + } + // 首页相关模型变更时同步刷新 / if (HOME_AFFECTED_MODELS.has(body.modelCode) && !revalidatedPaths.includes('/')) { revalidatePath('/'); diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 80be67c..8bfdc66 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -16,9 +16,9 @@ import { MotionProvider } from "@/components/ui/motion-provider"; import { BackToTop } from "@/components/ui/back-to-top"; import { ClientLayout } from "@/components/layout/client-layout"; import { getPublishedItems } from "@/lib/cms/data-server"; -import { SiteConfigProvider, type SiteConfig, type NavigationItem, type MegaDropdownGroup, type MegaDropdownItem } from "@/lib/site-config"; +import { SiteConfigProvider, type SiteConfig, type NavigationItem, type MegaDropdownItem } from "@/lib/site-config"; import { COMPANY_INFO, BRAND_NARRATIVE, type BrandPillar } from "@/lib/constants/company"; -import { NAVIGATION_V2, MEGA_DROPDOWN_DATA } from "@/lib/constants/navigation"; +import { resolveNavigation, injectStandaloneProducts } from "@/lib/navigation-resolution"; /** * 拉丁字形使用 Geist(本地 woff2,无网络请求); @@ -127,21 +127,18 @@ export default async function RootLayout({ }; }); - // Build megaDropdown with standalone products dynamically injected - const baseMegaDropdown = (navData?.megaDropdown as Record) || MEGA_DROPDOWN_DATA; - const megaDropdown: Record = {}; - for (const [key, groups] of Object.entries(baseMegaDropdown)) { - if (key === 'products' && standaloneNavItems.length > 0) { - megaDropdown[key] = groups.map((group) => { - if (group.id === 'standalone-products') { - return { ...group, description: undefined, items: standaloneNavItems }; - } - return group; - }); - } else { - megaDropdown[key] = groups; - } + // 导航解析:**代码为真源,CMS 仅在完整自洽时覆盖**。 + // 原写法是 `(navData?.mainNav as ...) || NAVIGATION_V2` —— DB 行胜出、代码只兜底, + // 于是「只改 navigation.ts 会上线一个生产静默忽略它的新导航」。详见 lib/navigation-resolution.ts。 + const nav = resolveNavigation(navData); + if (nav.issues.length > 0) { + // 渲染期不写库(Notification 是后台数据,在 RSC 里写它等于给每次首页渲染挂写副作用), + // 但「为什么没用后台配置」必须可见,否则 fail-closed 会被读成"后台改了没反应"的玄学。 + console.warn('[navigation] 退回代码真源:\n ' + nav.issues.join('\n ')); } + // 独立产品按**组 id** 注入(原实现按 key==='products' 匹配,双轴改名后该 key 已不存在, + // 沿用会静默丢失这一组:面板照样渲染,只是少了它)。 + const megaDropdown = injectStandaloneProducts(nav.megaDropdown, standaloneNavItems); const siteConfig: SiteConfig = { name: (configData?.name as string) || COMPANY_INFO.name, @@ -160,7 +157,7 @@ export default async function RootLayout({ address: (configData?.address as string) || COMPANY_INFO.address, icp: (configData?.icp as string) || COMPANY_INFO.icp, police: (configData?.police as string) || COMPANY_INFO.police, - mainNav: (navData?.mainNav as NavigationItem[]) || NAVIGATION_V2, + mainNav: nav.mainNav as unknown as NavigationItem[], megaDropdown, }; diff --git a/src/app/sitemap.ts b/src/app/sitemap.ts index a2a6849..2b58c0b 100644 --- a/src/app/sitemap.ts +++ b/src/app/sitemap.ts @@ -17,6 +17,9 @@ export default async function sitemap(): Promise { // 案例列表页:数据库 case-study 暂无已发布内容,空列表页不收录(页面保留,待产品补数据后恢复)。 // { url: `${BASE_URL}/cases`, lastModified: new Date(), changeFrequency: 'weekly', priority: 0.8 }, { url: `${BASE_URL}/news`, lastModified: new Date(), changeFrequency: 'daily', priority: 0.7 }, + // 洞察枢纽(双轴改造新增):聚合 news + methodology + case-study。 + // /news 暂留(已被索引、且 2 条内容仍在贡献长尾),第二批用 301 归并 —— 见计划 §11 待拍 #3。 + { url: `${BASE_URL}/insights`, lastModified: new Date(), changeFrequency: 'daily', priority: 0.8 }, { url: `${BASE_URL}/team`, lastModified: new Date(), changeFrequency: 'monthly', priority: 0.6 }, { url: `${BASE_URL}/methodology`, lastModified: new Date(), changeFrequency: 'monthly', priority: 0.6 }, { url: `${BASE_URL}/contact`, lastModified: new Date(), changeFrequency: 'monthly', priority: 0.7 }, diff --git a/src/components/layout/footer.test.tsx b/src/components/layout/footer.test.tsx index 01d0158..2cc41f4 100644 --- a/src/components/layout/footer.test.tsx +++ b/src/components/layout/footer.test.tsx @@ -43,35 +43,40 @@ jest.mock('@/lib/site-config', () => ({ icp: '蜀ICP备XXXXXXXX号', police: '川公网安备XXXXXXXXXXX号', megaDropdown: { - products: [ + industries: [ { - id: 'group1', - title: '企业套装', - items: [ - { id: 'erp', title: 'ERP 管理系统', description: '财务·采购·销售·库存·生产', href: '/products/erp' }, - { id: 'crm', title: 'CRM 客户管理', description: '线索·商机·合同·服务', href: '/products/crm' }, - ], - }, - ], - solutions: [ - { - id: 'group1', - title: '行业解决方案', + id: 'industry-solutions', + title: '行业实践', items: [ { id: 'manufacturing', title: '制造业', description: '智能制造·MES·质量管控', href: '/solutions/manufacturing' }, { id: 'retail', title: '零售业', description: '全渠道·会员·精准营销', href: '/solutions/retail' }, ], }, ], - services: [ + capabilities: [ { - id: 'professional-services', - title: '专业服务', + id: 'capability-groups', + title: '能力组', items: [ { id: 'consulting', title: '战略咨询', description: '数字化转型咨询规划', href: '/services/consulting' }, { id: 'software', title: '企业软件', description: 'ERP/CRM/BI 系统实施', href: '/services/software' }, ], }, + { + id: 'enterprise-suite', + title: '产品矩阵', + items: [ + { id: 'erp', title: 'ERP 管理系统', description: '财务·采购·销售·库存·生产', href: '/products/erp' }, + { id: 'crm', title: 'CRM 客户管理', description: '线索·商机·合同·服务', href: '/products/crm' }, + ], + }, + ], + insights: [ + { + id: 'insight-groups', + title: '洞察', + items: [{ id: 'all', title: '全部洞察', description: '', href: '/insights' }], + }, ], }, }), @@ -90,6 +95,8 @@ jest.mock('@/lib/constants', () => ({ icp: '蜀ICP备XXXXXXXX号', police: '川公网安备XXXXXXXXXXX号', }, + MEGA_KEYS: { industries: 'industries', capabilities: 'capabilities', insights: 'insights' }, + STANDALONE_GROUP_ID: 'standalone-products', MEGA_DROPDOWN_DATA: { products: [ { @@ -140,12 +147,12 @@ describe('Footer', () => { it('should render products section', () => { render(