feat(news): 正文结构化 + 站内出口 + 实时阅读时长(Batch 2 内页证据密度)

Batch 2 的实现本体。补的是「内容」不是「语法」:`/news` 与 `/insights`
此前各只有 250 字左右的正文。

① 两篇公开正文 238/313 字 → 914/758 字,全部从既有真源派生(METHODOLOGY
   四阶段 / SERVICES 四组 / PRODUCTS 六款 / commitments.ts 响应承诺),
   **零新增客户案例、零新增效果数字**。
② 详情页正文由整块 `whitespace-pre-line` 改为小标题 + 段落
   (`parseArticleBlocks`,三条判据:单行 + ≤20 字 + 不以句末标点收尾 ——
   误判成标题比漏判更糟)。
③ 正文末尾新增站内公开入口(`NEWS_RELATED_LINKS`)。此前详情页是死胡同,
   只有「返回列表」与「预约咨询」。href 由单测**双向**反查:既命中
   PRODUCTS/SERVICES 常量,又要求文件系统里 page.tsx 真实存在。
④ 阅读时长由正文字数实时算出(450 字/分钟),不手写不落库。
⑤ `/insights` 卡片显式写出「收录于」哪个原生栏目。
   **不新增 `/insights/[slug]`** —— 聚合页只能读、不能拥有别的模型的实体,
   复制内容会造成 canonical 冲突。

判别性测试:`news-article.test.ts` 11 例 + `news-detail-content-v3.test.tsx` 4 例
(负对照:关掉解析器 ⇒ 3 条转红)+ e2e UJ-04/UJ-10 三条新断言
(负对照:注回整块渲染后 UJ-04 转红)。
This commit is contained in:
zhangxiang committed 2026-11-25 09:01:10 +08:00
1 parent 9c4dd576d5
commit 59e31c3f6e
12 files changed
+514 -18

No files matched your search

+7
View File
@@ -337,6 +337,13 @@ test.describe('UJ-04 Mobile: 新闻读者浏览旅程(列表 → 详情 →
const detailText = await detailContent.textContent();
expect(detailText!.length).toBeGreaterThan(50);
// Batch 2(内页证据密度):正文有结构,且末尾有站内公开入口(与桌面 UJ-04 同判据)
expect(await detailContent.locator('h2').count()).toBeGreaterThanOrEqual(2);
const relatedLinks = page.getByTestId('news-related-links');
await expect(relatedLinks).toBeVisible();
expect(await relatedLinks.locator('a').count()).toBeGreaterThanOrEqual(3);
await expect(page.getByTestId('news-reading-minutes')).toContainText('分钟');
// === Step 4: 通过面包屑返回新闻列表 ===
// news-detail-content-v3.tsx:68-71 恒渲染 breadcrumb nav 中的「新闻动态」链接
const breadcrumbNewsLink = page.locator('nav[aria-label="breadcrumb"] a[href="/news"]');
+14
View File
@@ -358,6 +358,20 @@ test.describe('UJ-04: 新闻读者浏览旅程(列表 → 详情 → 返回)
const detailText = await detailContent.textContent();
expect(detailText!.length).toBeGreaterThan(50);
// Batch 2(内页证据密度):正文有**结构**,不是一整坨 pre-line 文本。
// 判据取「≥2 个小标题」而不是硬编码标题文案 —— 改标题是编辑动作,不该让用例红;
// 把 parseArticleBlocks 退回整块渲染才会红(那时 h2 数为 0)。
const articleH2 = detailContent.locator('h2');
expect(await articleH2.count()).toBeGreaterThanOrEqual(2);
// 正文末尾的站内公开入口:此前详情页是死胡同(只有返回列表 + 预约咨询)。
const relatedLinks = page.getByTestId('news-related-links');
await expect(relatedLinks).toBeVisible();
expect(await relatedLinks.locator('a').count()).toBeGreaterThanOrEqual(3);
// 阅读时长由正文字数算出(不是手写标注)
await expect(page.getByTestId('news-reading-minutes')).toContainText('分钟');
// === Step 4: 通过面包屑返回新闻列表 ===
// news-detail-content-v3.tsx:68-71 恒渲染 breadcrumb nav 中的「新闻动态」链接
const breadcrumbNewsLink = page.locator('nav[aria-label="breadcrumb"] a[href="/news"]');
@@ -56,4 +56,26 @@ describe('洞察筛选器的分母纪律', () => {
expect(screen.getAllByTestId('insight-card-methodology')).toHaveLength(1);
expect(screen.queryAllByTestId('insight-card-writing')).toHaveLength(0);
});
it('卡片显式写出「收录于」哪个原生栏目(聚合页不冒充文章的所有者)', () => {
render(<InsightsContent entries={[METH, WRITING]} />);
const channels = screen.getAllByTestId('insight-channel').map((el) => el.textContent);
expect(channels).toHaveLength(2);
expect(channels.some((t) => t?.includes('方法论'))).toBe(true);
expect(channels.some((t) => t?.includes('技术与观点'))).toBe(true);
});
it('只有算了阅读时长的条目才显示分钟数(页面型条目不留「约 0 分钟」)', () => {
render(
<InsightsContent
entries={[
{ ...METH, readingMinutes: undefined },
{ ...WRITING, readingMinutes: 3 },
]}
/>,
);
const badges = screen.getAllByTestId('insight-reading-minutes');
expect(badges).toHaveLength(1);
expect(badges[0]!.textContent).toContain('约 3 分钟');
});
});
@@ -19,6 +19,11 @@ export interface InsightEntry {
date: string;
href: string;
industry?: string;
/**
* 阅读时长(分钟)。由正文实际字数算出(`src/lib/news-article.ts`),不是手写标注。
* 页面型条目(方法论)没有单篇正文,留空 ⇒ 卡片不显示该标签,而不是显示「约 0 分钟」。
*/
readingMinutes?: number;
}
const KIND_LABEL: Record<InsightKind, string> = {
@@ -27,6 +32,25 @@ const KIND_LABEL: Record<InsightKind, string> = {
writing: '技术与观点',
};
/**
* 每条洞察的**内容归属地**。
*
* 为什么要明说(2026-11-25 Batch 2):本页是聚合枢纽,但它展示的文章实际住在其
* 原生栏目里——技术观点在 `/news`、方法论在 `/methodology`、客户成果在 `/cases`。
* 此前卡片直接链到 `/news/<slug>`,而页面上没有任何地方说明这件事,
* 读者点「技术与观点」却落到「新闻动态」,看起来像跳错页;
* 想按路径族找 `/insights/<slug>` 的检查也永远命中 0。
*
* **不做 `/insights/[slug]` 的理由**:那会把同一个 ContentItem 同时挂在两个 URL 下,
* 制造 canonical 冲突——与本仓 `navigation.ts` 的「轴 = 视图,模型 = 真源」不变式冲突。
* 正确做法是把归属地写在脸上,而不是复制一份内容。
*/
const KIND_CHANNEL: Record<InsightKind, { label: string }> = {
methodology: { label: '方法论' },
case: { label: '客户成果' },
writing: { label: '技术与观点(新闻动态)' },
};
/**
* 洞察枢纽 —— 对标 Bain「Our Latest Insights」/ Porsche「In Focus: News & Trends」。
*
@@ -110,6 +134,11 @@ export default function InsightsContent({ entries }: { entries: InsightEntry[] }
{entry.industry && (
<span className="text-xs text-text-muted">· {entry.industry}</span>
)}
{entry.readingMinutes && (
<span className="text-xs text-text-muted tabular-nums" data-testid="insight-reading-minutes">
· 约 {entry.readingMinutes} 分钟
</span>
)}
{entry.date && (
<span className="ml-auto text-xs text-text-muted tabular-nums">{entry.date}</span>
)}
@@ -118,6 +147,10 @@ export default function InsightsContent({ entries }: { entries: InsightEntry[] }
{entry.excerpt && (
<p className="mt-2 text-sm text-text-secondary leading-relaxed">{entry.excerpt}</p>
)}
{/* 归属地显式写出:本页是聚合视图,文章本体住在原生栏目里(见 KIND_CHANNEL 注释) */}
<p className="mt-3 text-xs text-text-muted" data-testid="insight-channel">
收录于{KIND_CHANNEL[entry.kind].label}
</p>
<span className="mt-4 inline-flex items-center gap-1 text-sm font-medium text-text-primary group-hover:text-brand-ink">
阅读
<ArrowRight className="w-4 h-4" aria-hidden="true" />
+3
View File
@@ -2,6 +2,7 @@ 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 { readingMinutes } from '@/lib/news-article';
import InsightsContent, { type InsightEntry } from './insights-content';
export const metadata: Metadata = {
@@ -31,6 +32,8 @@ async function buildEntries(): Promise<InsightEntry[]> {
excerpt: data.excerpt || '',
date: data.date || '',
href: `/news/${data.id || item.slug}`,
// 阅读时长由正文实际字数算出,与详情页顶部那枚标签同源(src/lib/news-article.ts)
readingMinutes: readingMinutes(data.content),
};
});
@@ -0,0 +1,85 @@
/**
* 新闻详情页的三条 UI 契约(Batch 2「内页证据密度」,2026-11-25):
* 1. 正文按「小标题 + 段落」渲染,而不是整块 `whitespace-pre-line`(扩写后后者会把
* 「我们是谁」「我们不承诺什么」与正文糊成同字号);
* 2. 正文末尾提供**站内公开入口**(此前详情页是死胡同,只有返回列表与预约咨询);
* 3. 阅读时长由正文字数实时算出,不手写。
*
* 每条都能失败:把 parseArticleBlocks 换回整块 pre-line、删掉 related links 区块、
* 把 readingMinutes 写死成常量,对应断言各自转红。
*/
import { describe, it, expect, jest } from '@jest/globals';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import NewsDetailContentV3 from './news-detail-content-v3';
import { NEWS, NEWS_RELATED_LINKS } from '@/lib/constants/news';
import { parseArticleBlocks } from '@/lib/news-article';
jest.mock('@/components/ui/scroll-reveal', () => ({
ScrollReveal: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));
jest.mock('@/components/ui/static-link', () => ({
StaticLink: ({ children, href, ...rest }: { children: React.ReactNode; href: string; [k: string]: unknown }) => (
<a href={href} {...rest}>{children}</a>
),
}));
jest.mock('@/components/ui/cta-button', () => ({
CTAButton: ({ children, href }: { children: React.ReactNode; href: string }) => <a href={href}>{children}</a>,
}));
jest.mock('@/components/ui/page-decoration', () => ({
SectionLabel: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
EASE_OUT: [0.22, 1, 0.36, 1],
}));
jest.mock('framer-motion', () => ({
motion: { div: ({ children }: { children: React.ReactNode }) => <div>{children}</div> },
}));
const realNews = NEWS[0]!;
describe('NewsDetailContentV3 —— 正文结构与出口', () => {
it('正文小标题渲染成 h2,段落渲染成 p(不再是一整块 pre-line 文本)', () => {
const { container } = render(<NewsDetailContentV3 news={realNews} />);
const headings = parseArticleBlocks(realNews.content).filter((b) => b.kind === 'heading');
// 前提:源文真的有标题(否则下面的断言是空转)
expect(headings.length).toBeGreaterThan(0);
const h2Texts = Array.from(container.querySelectorAll('h2')).map((el) => el.textContent);
for (const h of headings) {
expect(h2Texts).toContain(h.text);
}
});
it('正文里出现站内公开入口,且链接数 = 真源条数', () => {
render(<NewsDetailContentV3 news={realNews} />);
const block = screen.getByTestId('news-related-links');
expect(block).toBeInTheDocument();
const anchors = block.querySelectorAll('a');
expect(anchors).toHaveLength(NEWS_RELATED_LINKS.length);
for (const link of NEWS_RELATED_LINKS) {
expect(block.querySelector(`a[href="${link.href}"]`)).toBeTruthy();
}
});
it('阅读时长由正文字数算出,而不是写死的数字', () => {
const { unmount } = render(<NewsDetailContentV3 news={realNews} />);
const long = screen.getByTestId('news-reading-minutes').textContent ?? '';
unmount();
// 同一组件喂一篇**极短**正文,分钟数必须变小(写死常量时这条会红)
const shortNews = { ...realNews, content: '很短。' };
render(<NewsDetailContentV3 news={shortNews} />);
const short = screen.getByTestId('news-reading-minutes').textContent ?? '';
expect(long).toMatch(/约 \d+ 分钟/);
expect(short).toMatch(/约 1 分钟/);
expect(long).not.toBe(short);
});
it('粘贴进 HTML 标签的旧数据不会被当成标签渲染(按纯文本输出)', () => {
// CMS 里既有行可能有 `<p>` 包裹(e2e/cms-workflow 造的就是这种)。
// 组件走纯文本渲染 ⇒ 用户看到的是字面量,而不是被解析出的 DOM。
const news = { ...realNews, content: '<p>旧的 HTML 包装</p>' };
const { container } = render(<NewsDetailContentV3 news={news} />);
expect(container.querySelector('p > p')).toBeNull();
expect(screen.getByText('<p>旧的 HTML 包装</p>')).toBeInTheDocument();
});
});
@@ -5,10 +5,11 @@ import { StaticLink } from '@/components/ui/static-link';
import { CTAButton } from '@/components/ui/cta-button';
import { CTA_LABELS } from '@/lib/constants/cta-labels';
import { Badge } from '@/components/ui/badge';
import { Calendar, ArrowLeft, Newspaper } from 'lucide-react';
import { Calendar, ArrowLeft, Newspaper, ArrowUpRight } from 'lucide-react';
import { SectionLabel, EASE_OUT } from '@/components/ui/page-decoration';
import { motion } from 'framer-motion';
import type { NewsItem } from '@/lib/constants/news';
import { NEWS_RELATED_LINKS, type NewsItem } from '@/lib/constants/news';
import { parseArticleBlocks, readingMinutes } from '@/lib/news-article';
function RelatedNewsCard({ news, index }: { news: NewsItem; index: number }) {
return (
@@ -58,6 +59,8 @@ interface NewsDetailContentV3Props {
}
export default function NewsDetailContentV3({ news, relatedNews = [] }: NewsDetailContentV3Props) {
// 正文结构(标题 / 段落)在渲染期解析,不改数据模型 —— 理由见 src/lib/news-article.ts 顶部注释。
const blocks = parseArticleBlocks(news.content);
return (
<div className="min-h-screen bg-bg-primary text-ink overflow-x-hidden">
@@ -83,11 +86,15 @@ export default function NewsDetailContentV3({ news, relatedNews = [] }: NewsDeta
{news.title}
</h1>
<div className="flex items-center gap-6 mt-8 text-text-muted text-sm">
<div className="flex flex-wrap items-center gap-6 mt-8 text-text-muted text-sm">
<div className="flex items-center gap-2">
<Calendar className="w-4 h-4" />
{news.date}
</div>
{/* 阅读时长由正文字数实时算出(src/lib/news-article.ts),不是手写标注 */}
<span className="tabular-nums" data-testid="news-reading-minutes">
约 {readingMinutes(news.content)} 分钟
</span>
</div>
<div className="mt-10 h-px bg-gradient-to-r from-brand/50 via-border-primary to-transparent" />
@@ -122,8 +129,51 @@ export default function NewsDetailContentV3({ news, relatedNews = [] }: NewsDeta
</div>
{/* Article Content */}
<div className="text-text-secondary text-base sm:text-lg leading-[1.9] whitespace-pre-line">
{news.content}
<div className="text-text-secondary text-base sm:text-lg leading-[1.9]">
{blocks.map((block, i) =>
block.kind === 'heading' ? (
<h2
key={i}
className="mt-12 mb-4 text-xl sm:text-2xl font-bold text-text-primary tracking-tight first:mt-0"
>
{block.text}
</h2>
) : (
// 段落用 `whitespace-pre-line` 保留源文里的手工换行(列表项、序号行),
// 块与块之间的分隔改由 `<p>` 的 margin 承担 —— 与整块 pre-line 的区别就在这里。
<p key={i} className="mt-5 first:mt-0 whitespace-pre-line">
{block.text}
</p>
),
)}
</div>
{/* 正文提到的公开入口 —— 详情页此前是一条死胡同(只有「返回列表」与「预约咨询」) */}
<div className="mt-16 sm:mt-20 pt-10 border-t border-border-primary" data-testid="news-related-links">
<SectionLabel>继续阅读</SectionLabel>
{/* `list-plain` 不是装饰:globals 的 `ul li::before` 给所有列表加品牌红菱形,
四个入口各一颗就是 4 处红触达点凭空多出来(面积纪律按区算)。 */}
<ul className="list-plain grid gap-px bg-border-primary sm:grid-cols-2">
{NEWS_RELATED_LINKS.map((link) => (
<li key={link.href} className="bg-bg-primary">
<StaticLink
href={link.href}
className="group flex h-full flex-col gap-2 p-5 transition-colors duration-hover hover:bg-bg-secondary"
>
<span className="flex items-start justify-between gap-3">
<span className="text-base font-semibold text-text-primary leading-snug">
{link.title}
</span>
<ArrowUpRight
className="mt-0.5 h-4 w-4 shrink-0 text-brand-ink"
aria-hidden="true"
/>
</span>
<span className="text-sm text-text-secondary leading-relaxed">{link.reason}</span>
</StaticLink>
</li>
))}
</ul>
</div>
</ScrollReveal>
+2
View File
@@ -19,8 +19,10 @@ export {
PRODUCTS,
type Product,
NEWS,
NEWS_RELATED_LINKS,
type NewsItem,
type NewsCategory,
type NewsRelatedLink,
type TeamMember,
METHODOLOGY,
type MethodologyPhase,
+1 -1
View File
@@ -6,7 +6,7 @@ export { STATS, type StatItem } from './stats';
export { SERVICES } from './services';
export { PRODUCTS, type Product } from './products';
export type { StandaloneProduct } from './standalone-products';
export { NEWS, type NewsItem, type NewsCategory } from './news';
export { NEWS, NEWS_RELATED_LINKS, type NewsItem, type NewsCategory, type NewsRelatedLink } from './news';
export type { TeamMember } from './team';
export { METHODOLOGY, type MethodologyPhase } from './methodology';
export { SOLUTIONS, type Solution } from './solutions';
+101 -12
View File
@@ -10,6 +10,57 @@ export interface NewsItem {
content: string;
}
/**
* 新闻详情页底部的「相关公开入口」。
*
* 为什么需要这块(2026-11-25 Batch 2「内页证据密度」):
* 详情页此前是**一条死胡同**——正文读完只剩「返回新闻列表」与「预约咨询」两个出口,
* 文中提到的四阶段方法论、能力组、产品矩阵在站内都有正式页面,却没有任何链接指向它们。
* 结果是一个只有 250 字正文的页面,靠两个按钮承担全部导航。
*
* 数据纪律:
* - 链接目标**必须是既有路由**,不新造页面;由 `news.test.ts` 逐个反查 products/services
* 常量与既有固定路由,避免写成 /services/xxx 这种不存在的地址。
* - `reason` 只陈述该页已有的公开内容,不新增事实主张(零编造)。
*/
export interface NewsRelatedLink {
href: string;
title: string;
reason: string;
}
export const NEWS_RELATED_LINKS: NewsRelatedLink[] = [
{
href: '/methodology',
title: '实施方法论:从诊断到优化的四阶段',
reason: '诊断评估、战略规划、落地实施、持续优化各自的交付物清单',
},
{
href: '/services/consulting',
title: '战略咨询',
reason: '转型路线图设计与技术选型评估',
},
{
href: '/services/software',
title: '企业软件',
reason: 'ERP、CRM、BI 等核心系统的实施与定制化开发',
},
{
href: '/products',
title: '产品矩阵',
reason: '六款企业套装与一款独立产品的能力说明',
},
];
/**
* 公开新闻条目 —— 站内「技术与观点」这一路的唯一真源(CMS `news` 模型的 seed 输入)。
*
* ⚠ 条数不是随便定的:`e2e/user-journey.spec.ts` 与 `e2e/mobile-user-journeys.spec.ts`
* 把「公司新闻 1 篇 / 研发动态 1 篇 / 全部 2 篇」写成硬断言(N-27 纪律:不许用
* `if (count > 0)` 把契约吞掉)。新增条目=改契约,必须同批改那两个 spec 与 `categories`
* 常量,否则红的会是一条判据正确的用例。同理,`excerpt` 会进首页洞察区与列表卡,
* 改它就要重采首页基线;`content` 只进详情页,改它只需重采 `news-detail` 那 5 张。
*/
export const NEWS: NewsItem[] = [
{
id: 'company-founded',
@@ -18,13 +69,37 @@ export const NEWS: NewsItem[] = [
date: '2026-01-15',
category: '公司新闻',
image: '/images/news/founding.webp',
content: `2026年1月15日,四川睿新致远科技有限公司在成都龙泉驿区幸福路12号正式成立。公司拥有一支专业的技术团队。
content: `2026 年 1 月 15 日,四川睿新致远科技有限公司在成都龙泉驿区幸福路 12 号完成工商注册,正式成立。
公司专注于信息技术服务与解决方案,致力于为企业提供全方位的数字化转型支持。成立之初,公司就确立了"专注科技创新,驱动智慧未来"的企业使命。
我们是谁
公司创始人表示:"我们将以客户需求为导向,以技术创新为驱动,为企业提供高质量的数字化解决方案,助力企业在数字经济时代实现转型升级。"
睿新致远是一家面向中国成长型企业的数字化转型服务与产品公司。所谓成长型企业,指业务已经跑起来、但还不具备大型企业 IT 预算与组织规模的那一类:系统在变多,数据在变散,决策仍然靠经验。我们的定位是这一类企业的同行者——先理解业务,再谈系统。
公司正积极拓展业务合作,业务范围涵盖软件开发、云服务、数据分析、信息安全等多个领域。`,
我们怎么工作
我们把自己的工作拆成四个阶段,每个阶段都要求有可交付的书面产物,而不是只交口头结论:
1. 诊断评估:调研业务流程、盘点 IT 基础设施与数据资产,产出转型成熟度评估报告与关键痛点清单。
2. 战略规划:把评估结果对齐业务目标,产出转型战略规划书、技术架构蓝图与分阶段实施计划。
3. 落地实施:分阶段推进,每个迭代都交付可衡量的业务价值,而不是等到最后一次性上线。
4. 持续优化:交付之后继续陪跑,把维护与迭代能力留在企业自己的团队手里。
四个阶段各自的核心活动与交付物清单,在我们的方法论页面完整公开,不藏在方案书里。
我们提供什么
服务侧有四组能力:战略咨询、企业软件、技术服务与 AI 赋能。产品侧有六款企业套装——ERP、CRM、CMS、BI、SDS、OA——以及一款面向专业领域的独立产品。产品支持本地服务器、私有云与混合云三种部署方式,并适配信创环境。
我们不承诺什么
不承诺未经测算的收益数字;不用「行业最佳实践」四个字代替具体方案;不在没有客户授权、没有完成验证的情况下,把任何项目写成案例。
为什么把口径写这么细
数字化转型这行最容易失真的不是技术,是预期。一句「效率提升 40%」印在海报上很便宜,写进验收条款里很贵。我们的做法是给每个数字标明口径:它是目标、是团队历史、还是已核验的结果——这三种说法在页面上用不同的角注区分,不混用。这个习惯从成立第一天就定下来,也写进了方法论。
接下来
公司目前处于首批客户共创阶段:与早期客户一起打磨产品与交付流程,公开案例会在获得客户授权、并完成验证之后发布。如果你正处在「系统越来越多、数据越来越散」的阶段,欢迎带着具体场景来谈——我们先给判断,再谈方案。`,
},
{
id: 'digital-transformation-solution',
@@ -33,16 +108,30 @@ export const NEWS: NewsItem[] = [
date: '2026-02-20',
category: '研发动态',
image: '/images/news/solution.webp',
content: `近日,四川睿新致远科技有限公司正式启动企业数字化转型解决方案的研发工作,该方案将整合云计算、大数据、人工智能等前沿技术,为中小企业提供一站式的数字化升级服务。
content: `2026 年 2 月,我们启动了企业数字化转型解决方案的研发。它不是再做一个通用套件,而是把「诊断 → 规划 → 实施 → 优化」这套方法论,做成一套可复用的交付框架。
该解决方案规划包括:
1. 数字化诊断:全面评估企业数字化现状,识别转型痛点
2. 方案设计:根据企业实际情况,量身定制数字化转型方案
3. 系统实施:专业团队负责系统部署和数据迁移
4. 运维支持:提供持续技术支持服务
为什么先做框架,而不是先堆功能
公司技术总监表示:"我们的目标是让每一家企业都能享受到数字化带来的便利,无论企业规模大小,都能找到适合自己的数字化转型路径。"
成长型企业的数字化项目,很少败在功能不够,多半败在三个地方:需求没有边界、数据没有归口、上线没有验收标准。这三件事都不是加功能能解决的。所以我们先定义每个环节的输入、输出与验收判据:
1. 数字化诊断:评估现状数字化程度、识别业务断点,输出诊断报告与机会优先级矩阵。
2. 方案设计:按企业实际业务流与预算约束设计方案,输出系统蓝图与分阶段实施计划。
3. 系统实施:部署、配置与数据迁移,输出上线清单与验收记录。
4. 运维支持:上线后的持续支持与迭代,输出问题台账与优化建议。
目前,该解决方案正在积极研发中,我们诚邀有意向的企业参与早期体验计划,您的反馈将帮助我们打造更贴合需求的产品。`,
研发中的另一个重点:多环境适配
同一套方案要能在本地服务器、私有云、混合云上跑通,并适配信创环境(国产操作系统与数据库)。这不是一句交付承诺,而是架构约束——凡是依赖单一云厂商托管服务的设计,在私有化场景下会直接失效,所以这一条在框架层就要先排除掉。
关于「一站式」的自我约束
「一站式」很容易变成一句什么都覆盖的废话。我们的口径是:一站式指从诊断到运维的接口由我们统一负责,而不是指所有环节都必须由我们的人来做。企业已有的系统、已有的团队,优先复用,不推倒重来。
怎么算做完了
方案会先在可衡量的小范围内跑通,再扩大范围。每个阶段结束都要有书面交付物与验收记录;没有验收标准的模块,不进入交付范围。这条规则同时约束我们自己——不接受「先上线再说」。
早期体验计划仍在开放
我们正在寻找首批共建企业:由你提出真实场景,我们一起做诊断与小范围验证,你的反馈直接进入产品设计。公开案例会在获得授权并完成验证之后发布。`,
},
] as const;
+120
View File
@@ -0,0 +1,120 @@
/**
* 新闻正文结构解析的三条判据(每条都能失败):
* 1. 小标题被识别;
* 2. **以标点收尾的长句不会被误判成标题**(误判的代价:一整句正文被放大成 h2);
* 3. 空输入 / 只有空白的输入返回空数组(不是 `[{kind:'paragraph',text:''}]`)。
*
* 另附两个契约守卫(来自 Batch 2「内页证据密度」):
* - 每篇正文的厚度下限 —— 防止后续改动把正文悄悄退回一二百字;
* - 相关入口的 href 必须指向**真实存在的路由**(新造一个 /services/xxx 是零编造)。
*/
import { describe, it, expect } from '@jest/globals';
import { existsSync } from 'fs';
import path from 'path';
import { parseArticleBlocks, articleCharCount, TITLE_MAX_LEN } from './news-article';
import { NEWS, NEWS_RELATED_LINKS } from './constants/news';
import { PRODUCTS } from './constants/products';
import { SERVICES } from './constants/services';
const REPO_ROOT = path.resolve(__dirname, '../..');
describe('parseArticleBlocks', () => {
it('识别小标题与段落,并保持源文顺序', () => {
const blocks = parseArticleBlocks('我们是谁\n\n这是一段正文,讲我们是谁。\n\n我们怎么工作\n\n分四个阶段推进。');
expect(blocks.map((b) => b.kind)).toEqual(['heading', 'paragraph', 'heading', 'paragraph']);
expect(blocks[0]).toEqual({ kind: 'heading', text: '我们是谁' });
});
it('以句末标点收尾的短块**不得**被判成标题(否则整句变 h2)', () => {
// 长度 13 字 ≤ TITLE_MAX_LEN,唯一能阻止它变成标题的就是「以标点收尾」这条判据。
const text = '这四个阶段都要求书面产物。';
expect(text.length).toBeLessThanOrEqual(TITLE_MAX_LEN);
const blocks = parseArticleBlocks(text);
expect(blocks).toHaveLength(1);
expect(blocks[0]!.kind).toBe('paragraph');
});
it('跨行的块不得被判成标题(标题不换行)', () => {
const blocks = parseArticleBlocks('短句\n另一个短句');
expect(blocks).toHaveLength(1);
expect(blocks[0]!.kind).toBe('paragraph');
});
it('超过长度上限的块不得被判成标题', () => {
const long = '一'.repeat(TITLE_MAX_LEN + 1);
const blocks = parseArticleBlocks(long);
expect(blocks[0]!.kind).toBe('paragraph');
});
it('空输入 / 纯空白返回空数组,不返回一个空段落', () => {
expect(parseArticleBlocks('')).toEqual([]);
expect(parseArticleBlocks(null)).toEqual([]);
expect(parseArticleBlocks(undefined)).toEqual([]);
expect(parseArticleBlocks(' \n\n \n ')).toEqual([]);
});
});
describe('articleCharCount', () => {
it('去掉空白后计字符(不把缩进算成正文厚度)', () => {
expect(articleCharCount('一 二\n\t三')).toBe(3);
expect(articleCharCount('')).toBe(0);
});
});
describe('NEWS 正文厚度与相关入口契约', () => {
/** 下限取 600:现有两篇实测都在 900+,门槛是「防退回」而不是「凑字数」。 */
const MIN_BODY_CHARS = 600;
it('每篇正文都达到厚度下限(防后续改动悄悄退回短正文)', () => {
for (const item of NEWS) {
const n = articleCharCount(item.content);
expect({ id: item.id, chars: n >= MIN_BODY_CHARS }).toEqual({ id: item.id, chars: true });
}
});
it('每篇正文都含至少两个小标题(结构真的解析出来了,不是一整坨段落)', () => {
for (const item of NEWS) {
const headings = parseArticleBlocks(item.content).filter((b) => b.kind === 'heading');
expect({ id: item.id, headings: headings.length >= 2 }).toEqual({ id: item.id, headings: true });
}
});
it('相关入口的 href 全部指向真实存在的页面(零编造:不新造路由)', () => {
const productHrefs = new Set(PRODUCTS.map((p) => `/products/${p.id}`));
const serviceHrefs = new Set(SERVICES.map((s) => `/services/${s.id}`));
const staticHrefs = new Set(['/methodology', '/products', '/services', '/insights', '/news', '/contact', '/about']);
const unknown = NEWS_RELATED_LINKS
.map((l) => l.href)
// 动态详情路由:在 products 常量里能找到对应 id 才算存在
.filter((href) => {
const m = /^\/(products|services)\/(.+)$/.exec(href);
if (m) {
return m[1] === 'products' ? !productHrefs.has(href) : !serviceHrefs.has(href);
}
return !staticHrefs.has(href);
});
expect(unknown).toEqual([]);
});
it('相关入口引用的页面文件真实存在(App Router 里没这个目录就是 404)', () => {
const toDir = (href: string) => {
const m = /^\/(products|services)\/(.+)$/.exec(href);
if (m) return path.join(REPO_ROOT, 'src/app/(marketing)', m[1]!, '[id]');
return path.join(REPO_ROOT, 'src/app/(marketing)', href.replace(/^\//, ''));
};
for (const link of NEWS_RELATED_LINKS) {
const dir = toDir(link.href);
expect({ href: link.href, exists: existsSync(path.join(dir, 'page.tsx')) }).toEqual({
href: link.href,
exists: true,
});
}
});
it('相关入口每条都写了 reason(不留只有一个标题的空壳链接)', () => {
for (const link of NEWS_RELATED_LINKS) {
expect(link.reason.trim().length).toBeGreaterThan(4);
}
});
});
+71
View File
@@ -0,0 +1,71 @@
/**
* 新闻正文的轻量结构解析(Batch 2「内页证据密度」,2026-11-25)。
*
* 背景:`news` 模型的 `content` 是**纯文本**字段(CMS `richtext` 但渲染侧一直按
* `whitespace-pre-line` 整块输出)。正文从 250 字扩到千字级之后,这个渲染方式会让
* 「我们是谁 / 我们怎么工作 / 我们不承诺什么」这类小标题与正文同字号同字重糊成一片,
* 读者只能靠肉眼找换行 —— 页面高度上去了,可读性反而下来了。
*
* 为什么不改数据模型:`content` 是全站唯一真源,`prisma/seed.ts`、admin 编辑器、
* 既有 CMS 行都按纯文本存。为一个渲染细节引入结构化字段(`sections[]`)会让
* 存量数据与编辑器同时失效,代价远大于收益。
*
* 因此在这里做**可判定的最小结构**:只识别「小标题」,其余一律当段落。
* 判据刻意保守 —— 误判成标题比漏判更糟(会把一整句正文放大成 h2),所以同时要求:
* 1. 块内只有一行(标题不会换行);
* 2. 长度 ≤ TITLE_MAX_LEN;
* 3. 不以句末标点结尾(正文句子几乎总以标点收尾)。
* 三条判据各有负例,见 news-article.test.ts。
*/
/** 标题长度上限。中文咨询文案的小标题实测 4–12 字;给到 20 留余量,仍远低于最短正文句。 */
export const TITLE_MAX_LEN = 20;
/** 句末/分句标点:以它们收尾的块一定是正文,不是标题。 */
const SENTENCE_END_RE = /[。!?;:,、,.;:!?))】」』…—]$/;
export type ArticleBlock =
| { kind: 'heading'; text: string }
| { kind: 'paragraph'; text: string };
/** 纯函数:把一个 `content` 字符串切成标题/段落的顺序块。空输入 ⇒ 空数组。 */
export function parseArticleBlocks(content: string | null | undefined): ArticleBlock[] {
if (!content) return [];
const chunks = content
.replace(/\r\n/g, '\n')
.split(/\n{2,}/)
.map((c) => c.trim())
.filter((c) => c.length > 0);
return chunks.map((chunk) => {
const isSingleLine = !chunk.includes('\n');
const looksLikeTitle =
isSingleLine && chunk.length <= TITLE_MAX_LEN && !SENTENCE_END_RE.test(chunk);
return looksLikeTitle
? ({ kind: 'heading', text: chunk } as const)
: ({ kind: 'paragraph', text: chunk } as const);
});
}
/**
* 正文字数(按中文习惯去掉空白后计字符)。用于「正文厚度」门禁:
* 单位不是"字数要够多才专业",而是**防止正文在后续改动里悄悄退回一二百字**。
*/
export function articleCharCount(content: string | null | undefined): number {
if (!content) return 0;
return content.replace(/\s/g, '').length;
}
/** 中文阅读速度取 450 字/分钟(咨询/技术类文本的保守下沿),向下取整但至少 1 分钟。 */
const CHARS_PER_MINUTE = 450;
/**
* 预估阅读时长(分钟)。用途是给读者一个「这篇要不要现在读」的判断,
* 不是给搜索引擎看的元数据 —— 因此由正文字数**实时算出**,不落库、不手写,
* 正文一改它跟着改,不会出现「标注 3 分钟、实际 8 分钟」的漂移。
*/
export function readingMinutes(content: string | null | undefined): number {
const chars = articleCharCount(content);
return Math.max(1, Math.round(chars / CHARS_PER_MINUTE));
}