跳到主要内容
IM智引科技

研究 / 外贸与 B2B 增长

用 AI 批量生成应用选型 Cluster 页(完整流程)

数据库建好后,如何用 AI 把数据填充成真实可发布的页面内容?这篇讲完整的批量生成流水线:从数据读取到提示词构造,到 Claude API 调用,到内容写入 Markdown 文件,再到 Astro 自动渲染为页面——全程自动化,一次性生成几十个应用场景页。

BLKTECH 编辑部2026年8月4日12 分钟难度 实战低成本ClaudeAstroNode.js

批量生成流程:读取combinations.yaml获取待生成组合→为每个组合构造含注册表规格书的提示词→调用Claude API生成内容→输出为Markdown文件到src/content/applications/→Astro自动渲染页面。整套脚本约100行Node.js,跑一次生成50个页面。

用 AI 批量生成应用选型 Cluster 页(完整流程)

数据结构设计好,模板写好,现在把它们组合成可以运行的批量生成脚本。


完整流水线

combinations.yaml + products.yaml + applications.yaml

读取所有 generate:true 的组合

为每个组合构造提示词(含注册表规格书)

调用 Claude API 生成页面内容(文字部分)

拼接 frontmatter + 生成内容 → Markdown 文件

保存到 src/content/applications/

git push → CF Pages 自动重新构建

N×M 个应用场景页面上线

生成脚本(Node.js)

// scripts/generate-pseo-pages.mjs
import fs from 'fs/promises';
import path from 'path';
import Anthropic from '@anthropic-ai/sdk';
import yaml from 'js-yaml';

const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });

// 读取数据文件
const products = yaml.load(await fs.readFile('src/data/products.yaml', 'utf8'));
const applications = yaml.load(await fs.readFile('src/data/applications.yaml', 'utf8'));
const combinations = yaml.load(await fs.readFile('src/data/combinations.yaml', 'utf8'));

// 构造注册表规格书前缀
function buildRegistrySpec(product, app) {
  const slug = `/applications/${product.slug}-${app.slug}/`;
  const pkw = `${product.name} for ${app.name}`;
  return `
## 页面写作规格书
URL: ${slug}
页面类型: cluster-app (Application Cluster)
搜索意图: Engineering (工程选型)
PKW (H1 和 Title 必须包含): ${pkw}
SKW (H2 自然包含):
  - ${product.name.toLowerCase()} ${app.slug.replace('-', ' ')} selection
  - best ${product.name.toLowerCase()} for ${app.name.toLowerCase()}
  - ${app.name.toLowerCase()} ${product.name.toLowerCase()} specification
NKW (严禁出现): manufacturer, supplier, OEM, buy, price, quote,
  what is ${product.name.toLowerCase()}, how does pump work
目标地区: en-US, en-GB, en-AU
`.trim();
}

// 构造完整提示词
function buildPrompt(product, app) {
  const spec = buildRegistrySpec(product, app);
  return `
${spec}

---

任务:写一篇面向欧美 B2B 工业买家的应用场景选型指南。

产品信息:
- 产品名称:${product.name}
- 主要优势:${product.keyAdvantages.join('; ')}
- 不适用场景:${product.notSuitableFor.join('; ')}

应用场景信息:
- 场景名称:${app.nameFull}
- 场景简介:${app.shortDescription}
- 主要挑战:${app.challenges.join('; ')}
- 关键选型参数:${app.keySelectionCriteria.map(c => `${c.parameter}: ${c.recommendation}`).join('; ')}
- 相关行业标准:${app.industryStandards.join(', ')}

请写以下内容(英文,工程选型视角):

1. **场景描述段落**(100–150词):描述这个应用场景的特点和挑战
2. **为什么选择此泵型**(100–150词):从工程角度解释为什么${product.name}适合这个场景
3. **关键技术要求**:直接输出 HTML table,包含 Parameter / Recommended Value / Why It Matters 三列,覆盖所有关键选型参数
4. **合规与认证**(50–80词):说明该场景相关的认证要求
5. **FAQ(3条)**:每条用 ### 标题提问,第一句给核心结论,引用相关行业标准

语气:专业、直接,适合欧美工业工程师阅读。美式英语。
不要用 "we are the best"、"world-class"、"leading" 等空洞词。
只输出正文内容,不包含 frontmatter。
`;
}

// 构造 frontmatter
function buildFrontmatter(product, app) {
  const slug = `${product.slug}-${app.slug}`;
  const pkw = `${product.name} for ${app.name}`;
  return `---
title: "${product.name} for ${app.name}: Selection Guide & Recommended Models"
description: "Complete guide to selecting the right ${product.name.toLowerCase()} for ${app.name.toLowerCase()} applications. Key technical requirements, material selection, certifications, and recommended models."
slug: ${slug}
contentType: guides
pillar: infra
tags:
  - ${product.name}
  - ${app.name}
  - pump selection
  - B2B
pkw: "${pkw}"
skw:
  - "${product.name.toLowerCase()} ${app.name.toLowerCase()} selection"
  - "best ${product.name.toLowerCase()} for ${app.name.toLowerCase()}"
pageType: cluster-app
relatedProduct: ${product.id}
industry: "${app.industry}"
publishedAt: ${new Date().toISOString().split('T')[0]}
updatedAt: ${new Date().toISOString().split('T')[0]}
---

`;
}

// 主执行函数
async function generatePages() {
  const toGenerate = combinations.filter(c => c.generate);
  console.log(`Generating ${toGenerate.length} pages...`);

  for (const combo of toGenerate) {
    const product = products.find(p => p.id === combo.product);
    const app = applications.find(a => a.id === combo.application);

    if (!product || !app) {
      console.warn(`Skipping: ${combo.product} × ${combo.application} (not found)`);
      continue;
    }

    const filename = `${product.slug}-${app.slug}.md`;
    const outputPath = path.join('src/content/applications', filename);

    // 跳过已存在的文件(除非加 --force 参数)
    try {
      await fs.access(outputPath);
      console.log(`Skip (exists): ${filename}`);
      continue;
    } catch {}

    console.log(`Generating: ${filename}`);

    const response = await client.messages.create({
      model: 'claude-opus-5',
      max_tokens: 2000,
      messages: [{
        role: 'user',
        content: buildPrompt(product, app),
      }],
    });

    const content = response.content[0].text;
    const frontmatter = buildFrontmatter(product, app);
    const fullContent = frontmatter + content;

    await fs.writeFile(outputPath, fullContent, 'utf8');
    console.log(`✓ Generated: ${filename}`);

    // 避免触发速率限制
    await new Promise(resolve => setTimeout(resolve, 1000));
  }

  console.log('Generation complete!');
}

generatePages().catch(console.error);

运行脚本

# 安装依赖
npm install @anthropic-ai/sdk js-yaml

# 设置 API Key
export ANTHROPIC_API_KEY=sk-ant-xxx

# 运行生成
node scripts/generate-pseo-pages.mjs

# 本地预览
npm run dev

质量审查流程

批量生成后不要直接发布,先做质量检查:

自动化检查(脚本)

// 检查每个生成文件是否包含 NKW
const NKW = ['manufacturer', 'supplier', 'OEM', 'what is', 'buy'];
for (const file of generatedFiles) {
  const content = await fs.readFile(file, 'utf8');
  const violations = NKW.filter(word =>
    content.toLowerCase().includes(word.toLowerCase())
  );
  if (violations.length > 0) {
    console.warn(`${file}: NKW violations: ${violations.join(', ')}`);
  }
}

人工抽查(10%): 随机打开10%的生成文件,确认:

  • 内容有实质性价值(不是换了关键词的废话)
  • 技术参数准确
  • HTML 表格格式正确

成本估算

生成数量 Claude API 成本(约) 时间
10 页 $0.10–0.30 10分钟
50 页 $0.50–1.50 50分钟
100 页 $1.00–3.00 ~2小时

按50页计算,最多花 $1.50,生成50篇平均1500词的应用场景指南。手工写的话,按每篇3小时,需要150小时——这就是 pSEO 的成本优势。


→ 技术参数表规范:原生 HTML <table> + LLM 可直接解析结构

NEXT ACTION / 下一步

继续系列:AI 外贸站建设全系列

把读到的方法变成一个小行动,完成后再回来迭代。

继续

RELATED / 相关推荐

接着读这些

按同一分类、系列与标签为你挑选。