ChatGPT创意写作AI 评分 · 待评分AI 辅助编辑·未发现明显提示词注入风险n8n.io

用 n8n 自动为博客文章分类和打标签:GPT-4 + GitHub + Google Sheets

从 GitHub 仓库读取 Markdown 文章 → 与 Google Sheets 历史记录比对找出新文章 → AI Agent 分析内容并输出结构化分类与标签建议 → 结果追加到 Google Sheets 供审阅

有一点经验步骤流程提示词贴士
给谁
拥有 GitHub 托管静态博客(Astro/Next.js 等)的内容创作者、SEO 人员或开发团队,希望用 AI 自动维护文章元数据。
你会得到
自动识别仓库中尚未分析的新文章,由 AI 读取 frontmatter 与正文后给出 categories 和 tags 建议,并记录到 Google Sheets,避免重复处理。
你需要
n8n · GitHub · Google Sheets

硬约束

前置条件:n8n 实例;已配置 openAiApi、githubApi、googleSheetsOAuth2Api 三种凭证。Google Sheets 需预先创建列:FileName、Categories、Proposed Categories、Tags、Proposed Tags。GitHub 仓库需存放 .md/.mdx 博客文章。费用取决于 OpenAI API 调用量与 n8n 托管方式。

他们做了什么

作者 argone 在 n8n 上发布了一个官方模板,用于自动为托管在 GitHub 上的 Astro/Next.js 静态博客文章分配 categories 和 tags。工作流以 Form Trigger 启动,并行读取 Google Sheets 历史记录与 GitHub 仓库文件列表,通过 Code 节点差集运算找出尚未分析的新文章,再经 AI Agent(OpenAI GPT-4.1-mini + LangChain Memory + Structured Output Parser)逐篇分析 frontmatter 与正文,最后将建议结果追加到 Google Sheets。模板内含多个 Sticky Note 解释各段逻辑。

效果如何

来源未提供具体运行次数或准确率数据。模板页面显示总浏览量 319 次(截至采集时),未报告实际处理文章数或标签一致性指标。

值得知道

1. 模板默认模型为 gpt-4.1-mini,但节点参数中 model 字段支持切换为 gpt-4.1 或 gpt-4(需用户自行在 OpenAI Chat Model 节点选择)。 2. 工作流仅将建议写入 Google Sheets,不会自动修改 GitHub 文件;如需自动回写,需用户自行添加 GitHub Commit 节点。 3. AI Agent 的 systemMessage 包含一篇具体文章示例(Grace Hopper/debug),实际使用时该示例仅作格式参考,Agent 会处理传入的真实文章内容。 4. 两个 Code 节点的 JS 代码分别负责去重与差集计算,属于核心过滤逻辑,缺失会导致重复分析。 5. 本站未对该工作流进行实际导入与运行验证(reproduction=not_tested),搭建后请先用单篇文章测试 Switch 分支与 Sheets 输出。

n8n 工作流模板

结构已检查 · 未实际运行

下载后在 n8n 选择“Import from File”,或复制 JSON 后粘贴到编辑器。先配置自己的账号,再用测试数据运行;模板默认未启用。

配置与测试清单

需要绑定的凭证

  • OpenAI Chat Model 节点:绑定OpenAI API 凭证。
  • List posts/articles/pages 节点:绑定GitHub API 凭证。
  • Append rows with posts / article analysis 节点:绑定Google Sheets OAuth2 凭证。
  • Get post/article file 节点:绑定GitHub API 凭证。
  • Get row(s) in sheet 节点:绑定Google Sheets OAuth2 凭证。

需要替换的配置

  • 源模板来自 n8n 公开库 #9983(约 29 个节点)。导入后先保持未启用,核对触发器、表达式与外部 API 端点。
  • Sticky Note 中的说明仅供参考;按自己的账号、表结构或频道 ID 替换占位配置。

测试输入与预期结果

  • 在测试环境手动执行一次主路径,确认每个需凭证的节点已连接且无鉴权错误。
  • 用一条合成/脱敏样例数据跑通,核对输出字段与下游写入目标,再考虑生产启用。

模板处理说明

  • 已移除原作者凭证绑定、webhookId 与执行数据,工作流设为未启用;节点、连线与原文提示词保持原样。未在 n8n 中实际运行。
  • 未改业务逻辑;运行前请自行核对密钥、配额与隐私合规。

模板获取日期: 2026-10-24

步骤

  1. 准备数据源:读取 Google Sheets 与 GitHub 文件列表

    在 n8n 中并行执行两条分支: 1) 用 Google Sheets 节点读取已有分析记录(Get row(s) in sheet),随后通过 Code 节点提取 FileName 并去重,再用 Aggregate 节点将路径列表聚合为 googlesheetsPaths 数组。 2) 用 GitHub 节点列出指定仓库目录下的 .md/.mdx 文件(List posts/articles/pages),再用 Aggregate 节点聚合为 githubPaths 数组。 应看到:两个数组分别包含 Google Sheets 已记录的文件名和 GitHub 仓库当前全部文章路径。

  2. 比对并找出新文章

    使用 Merge 节点将两个数组合并,随后通过 Code 节点(Check new repo files for AI processing)计算差集:取 githubPaths 中不在 googlesheetsPaths 里的路径。接着用 Switch 节点判断结果是否为空。 - 若结果为空(无新文章),流程走向 Form 节点显示 "List is empty"。 - 若结果非空,继续下一步。 应看到:仅包含未分析文章路径的数组进入后续流程。

    运行提示词 · 来源原文。n8n Code 节点「Check new repo files for AI processing」的 JS Code 字段

    const allItems = $input.all();
    
    // Extract arrays 
    const googlePaths = allItems.find(i => i.json.googlesheetsPaths)?.json.googlesheetsPaths || [];
    const githubPaths = allItems.find(i => i.json.githubPaths)?.json.githubPaths || [];
    
    // Compute difference: elements in githubPaths not in googlesheetsPaths
    const difference = githubPaths.filter(path => !googlePaths.includes(path));
    
    // Return as n8n item array
    return difference.map(path => ({ json: { path } }));
  3. 逐篇获取文章内容

    对新文章路径数组使用 Split In Batches 节点(Loop Over Posts/Pages)逐条处理。每条路径传入 GitHub 节点(Get post/article file),动态读取 $json.path 对应的文件内容。 应看到:每个批次输出一篇文章的完整 Markdown 原文(含 frontmatter 与正文)。

  4. AI Agent 分析并生成分类与标签建议

    将文章内容送入 AI Agent 节点。该节点连接: - OpenAI Chat Model(模型选 gpt-4.1-mini,responseFormat 设为 json_object) - Simple Memory(contextWindowLength=2,用于保持多轮上下文一致性) - Structured Output Parser(约束输出格式) Agent 的 systemMessage 中定义了任务:解析 frontmatter,基于内容给出新的 categories 和 tags,并以指定 JSON 格式返回。

    运行提示词 · 来源原文。n8n AI Agent 节点的 Options > System Message 字段

    You are a helpful assistant which helps to assign proper tags and categories for post. Example of post is added in section <post>.  
    
    Each post has a section which starts with "---" and ands with next ocurance of "---". This section is metadata which describes the post. After second ocurance of "---" file has a content. 
    
    Read tags and categories and assign them to <tags> and <categories> variables used later in response.
    
    Based on content please provide categories assigned to <new_assigned_categories> and tags list assigned to <new_assigned_tags> as example below:
    
    <example>
    categories: ["business"] 
    tags: ["DigitalGirls", "ITPioneers", "WomenInIT", "IT", "FemalePower", "Debugging", "GraceHopper"] 
    </example>
    
    Final result should be post with updated metadata passed to variable <content>.
    
    <post> 
    --- 
    title: "Where Did the Term ‘Debug’ Come From? – Women in IT" 
    pubDate: 2024-07-23 description: "Did you know that the term ‘debug’ was coined by Admiral Grace Hopper?" 
    categories: ["business"] 
    tags: ["DigitalGirls", "ITPioneers", "WomenInIT", "IT", "FemalePower", "Debugging", "GraceHopper"] 
    coverImage: "@assets/2024-07-23-skad-sie-wzielo-okreslenie-debug-kobiety-w-it.jpeg" 
    ---
    
    Did you know that the term debug was coined by Admiral Grace Hopper?
    While working on the Mark II computer at Harvard University, a moth got trapped in a relay, interfering with the machine’s operation. Removing the dead insect was humorously referred to by Admiral Hopper as debugging.
    
    PS. After a conversation with Wioletta Klimczak, I got my hands on the book “Digital Girls. Pioneers of Polish Computer Science” by Karolina Wasielewska. The story above comes from that book. It’s proof that women are an important part of the IT world!
    
    #DigitalGirls #ITPioneers #WomenInIT #IT #FemalePower #Debugging #GraceHopper
    </post>
  5. 解析结构化输出并映射到表格字段

    AI Agent 的输出经 Structured Output Parser 约束为如下 JSON Schema: { "old_categories": ["category1"], "categories": ["category1","category2"], "old_tags": ["tag1","tag2"], "tags": ["tag1","tag2","tag3","tag4"] } 在 Append rows 节点中,将字段映射到 Google Sheets 对应列: - FileName = {{ $('Get post/article file').item.json.path }} - Categories = {{ JSON.stringify($json.output.old_categories) }} - Proposed Categories = {{ JSON.stringify($json.output.categories) }} - Tags = {{ JSON.stringify($json.output.old_tags) }} - Proposed Tags = {{ JSON.stringify($json.output.tags) }} 应看到:新行被追加到 Google Sheets,包含原文与建议值。

    搭建指导 · 来源原文。Structured Output Parser 节点的 JSON Schema Example 字段;AI Agent 输出须符合此格式

    {
      "old_categories": ["category1"],
      "categories": ["category1","category2"],
      "old_tags": ["tag1","tag2"],
      "tags": ["tag1","tag2","tag3","tag4"]
    }
  6. 循环处理直至完成

    Split In Batches 节点控制循环:每处理完一篇,返回 Loop Over Posts/Pages 继续下一批次。全部完成后,流程走向 Form 节点显示 "Categories and tags added"。 应看到:所有新文章均已在 Google Sheets 生成对应记录。

  7. 审阅与可选回写(建议)

    在 Google Sheets 中人工审阅 Proposed Categories 与 Proposed Tags 列。确认无误后,可手动更新博客 frontmatter,或扩展工作流加入 GitHub Commit 节点实现自动回写(来源提及为可定制方向,非本模板默认行为)。

可复制提示词

搭建指导 · 本站建议版本。交给搭建助手,先确认输入和权限

这一段是提示词,页面不会在这里插入广告。

你是一位熟悉 n8n 与静态网站内容管理的搭建助手。请根据以下信息协助用户复现该工作流:

1. 前置检查:确认用户已拥有 n8n 实例、OpenAI API Key、GitHub 仓库访问权限、Google Sheets OAuth2 凭证。
2. 指导用户在 Google Sheets 创建五列:FileName、Categories、Proposed Categories、Tags、Proposed Tags。
3. 从模板 https://n8n.io/workflows/9983/ 导入工作流后,更新 GitHub 节点的 owner/repository/filePath 为用户实际仓库路径。
4. 在 AI Agent 节点中,systemMessage 已包含任务定义与示例;如需调整分类风格,可修改该字段,但保留 Structured Output Parser 的 JSON 约束。
5. 首次运行建议使用 Form Trigger 手动触发,观察 Switch 分支与 Google Sheets 输出是否符合预期。

注意:本提示词为编辑建议的搭建启动词,非节点运行时提示词。

如需调整分类风格,优先修改 AI Agent 的 systemMessage,并确保输出仍匹配 Structured Output Parser 的 JSON Schema。

来源

Auto-categorize blog posts with OpenAI GPT-4, GitHub, and Google Sheets for Astro/Next.js · argone · n8n.io · 2025-10-21

留言与反馈

试过这个方法吗?分享效果、遇到的问题或改进建议。留言审核后公开,请勿填写敏感信息。

正在加载…

    相关用例