【n8n系列教程5】分享:每日AI总结L站热门贴,并推送到你的Notion或博客

请先看完免费部署教程:

也可以使用官网的,但官网的仅14天试用,可以用临时邮箱薅

效果展示:

自动推送到Notion 中:

自动推送到Notion Next博客中:

效果演示:11月06日 LinuxDo每日热门消息速递(并无任何引流想法,纯作为演示,如违规请提醒我)

工作流展示:

:wave:工作流JSON代码 (复制粘贴导入)

{
  "name": "Linux热门速递",
  "nodes": [
    {
      "parameters": {
        "modelName": "models/gemini-1.5-pro-002",
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        940,
        160
      ],
      "id": "8378b8dc-b2c1-4e70-bcf8-19fd05540334",
      "name": "Google Gemini Chat Model",
      "notesInFlow": true,
      "credentials": {
        "googlePalmApi": {
          "id": "UfZRTL45gYb4TiMq",
          "name": "Google Gemini(PaLM) Api account 4"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// 获取输入内容\nconst inputText = $('Gemini总结').first().json.text;\n\n// 用来存储最终的输出项\nlet outputItems = [];\n\n// 正则表达式匹配每一行,包括 #、##、###、- 和其他段落\nconst lines = inputText.split('\\n');\n\n// 当前段落存储变量\nlet currentText = '';\nlet currentType = 'paragraph';  // 默认类型是paragraph\n\n// 逐行处理文本\nlines.forEach(line => {\n    // 移除多余的空格\n    const trimmedLine = line.trim();\n\n    // 如果该行是标题\n    if (trimmedLine.startsWith('# ')) {\n        // 处理当前段落并推送\n        if (currentText) {\n            outputItems.push({ text: currentText.trim(), type: currentType });\n        }\n        currentText = trimmedLine.replace('# ', '');  // 去掉 # 符号\n        currentType = 'heading_1';  // 设置类型为 heading_1\n    } else if (trimmedLine.startsWith('## ')) {\n        if (currentText) {\n            outputItems.push({ text: currentText.trim(), type: currentType });\n        }\n        currentText = trimmedLine.replace('## ', '');  // 去掉 ## 符号\n        currentType = 'heading_2';  // 设置类型为 heading_2\n    } else if (trimmedLine.startsWith('### ')) {\n        if (currentText) {\n            outputItems.push({ text: currentText.trim(), type: currentType });\n        }\n        currentText = trimmedLine.replace('### ', '');  // 去掉 ### 符号\n        currentType = 'heading_3';  // 设置类型为 heading_3\n    } else if (trimmedLine.startsWith('- ')) {\n        if (currentText) {\n            outputItems.push({ text: currentText.trim(), type: currentType });\n        }\n        currentText = trimmedLine.replace('- ', '');  // 去掉 - 符号\n        currentType = 'bulleted_list_item';  // 设置类型为 bulleted_list_item\n    } else if (trimmedLine) {\n        // 处理常规段落\n        if (currentText) {\n            outputItems.push({ text: currentText.trim(), type: currentType });\n        }\n        currentText = trimmedLine;\n        currentType = 'paragraph';  // 设置类型为 paragraph\n    }\n});\n\n// 最后一次匹配完成后,处理剩余的内容\nif (currentText) {\n    outputItems.push({ text: currentText.trim(), type: currentType });\n}\n\n// 输出结果\nreturn outputItems.map(item => ({ json: item }));\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1380,
        0
      ],
      "id": "1eeb220f-9ad4-42f9-9734-bfeeda75a65e",
      "name": "分段分类"
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "value": "你的notion数据表格地址",
          "mode": "url"
        },
        "title": "LinuxDo",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "category|select",
              "selectValue": "知行合一"
            },
            {
              "key": "date|date",
              "date": "={{ $now.format('yyyy/MM/dd') }}"
            },
            {
              "key": "slug|rich_text",
              "textContent": "=LinuxDo-{{ $execution.id }}"
            },
            {
              "key": "status|select",
              "selectValue": "Published"
            },
            {
              "key": "tags|multi_select",
              "multiSelectValue": [
                "新闻"
              ]
            },
            {
              "key": "title|title",
              "title": "={{ $now.format('MM月dd日') }} LinuxDo每日热门消息速递"
            },
            {
              "key": "type|select",
              "selectValue": "Post"
            },
            {
              "key": "summary|rich_text",
              "textContent": "={{ $now.format('yyyy-MM月dd日') }}LinuxDo论坛热门消息速递"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        1200,
        0
      ],
      "id": "4c479164-9f7d-47d3-89b7-ac5a28cd6cec",
      "name": "创建博客",
      "executeOnce": true,
      "retryOnFail": true,
      "notesInFlow": true,
      "credentials": {
        "notionApi": {
          "id": "XVdzqw1H8HYyzjNp",
          "name": "Notion Blog"
        }
      }
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=以下为L站的帖子的内容\n{{ $json.text }}",
        "messages": {
          "messageValues": [
            {
              "message": "你是论坛内容分析助手。针对每篇帖子,请严格按以下的格式提供简明扼要的分析:\n\n# xx(序号).原标题:\n- 🖋️作者:作者名\n- 🔗链接:原链接\n\n### 📊内容分析:\n- 📌核心内容:用简洁的几个句子全面概括相应帖子内容\n- 🔑重要信息:列出2-3个关键点\n- 💡实用价值:提取可操作的信息(如有)\n\n\n处理原则:\n- 保持简洁,避免冗长\n- 只提取最关键的信息\n- 突出实用性内容\n- 如涉及资源,标注使用条件\n- 如涉及技术,标注关键参数\n\n注意:\n- 输出格式统一,方便阅读\n- 重要信息优先"
            }
          ]
        }
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.4,
      "position": [
        860,
        0
      ],
      "id": "6f36db4d-837a-4337-821b-4e5c8fe0227b",
      "name": "Gemini总结",
      "retryOnFail": true,
      "notesInFlow": true
    },
    {
      "parameters": {
        "jsCode": "// 获取上一节点传递过来的 items\nconst items = $input.all();\n\n// 创建一个空字符串,用来存储合并后的文本\nlet text = \"\";\n\n// 遍历所有的 items,并提取出所需的信息\nitems.forEach((item, index) => {\n    // 获取当前 item 的信息\n    const creator = item.json.creator;\n    const title = item.json.title;\n    const link = item.json.link;\n    const contentSnippet = item.json.contentSnippet;\n\n    // 按照指定格式将每个 item 的信息拼接\n    text += `第${index + 1}篇帖子标题:${title} \\n 第${index + 1}篇帖子作者:${creator} \\n 第${index + 1}篇帖子链接:${link} \\n 第${index + 1}篇帖子内容:${contentSnippet} \\n\\n`;\n});\n\n// 将合并后的字符串赋值给 text 变量\nreturn {\n    text: text.trim() // 去除最后的多余换行\n};\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        680,
        0
      ],
      "id": "849901aa-add7-4ef2-bb70-d63612715e2a",
      "name": "提取有效内容",
      "retryOnFail": true
    },
    {
      "parameters": {
        "url": "https://linux.do/top.rss?period=daily",
        "options": {}
      },
      "type": "n8n-nodes-base.rssFeedRead",
      "typeVersion": 1.1,
      "position": [
        540,
        0
      ],
      "id": "8bf7f51b-99a5-4242-a806-cab1715d6088",
      "name": "读取L站热门消息",
      "retryOnFail": true
    },
    {
      "parameters": {
        "resource": "block",
        "blockId": {
          "__rl": true,
          "value": "={{ $('创建博客').item.json.url }}",
          "mode": "url"
        },
        "blockUi": {
          "blockValues": [
            {
              "type": "heading_1",
              "textContent": "={{ $('分段分类').item.json.text }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        2080,
        -80
      ],
      "id": "bb650ccc-4f45-4a16-bc8e-8602bd9e3e56",
      "name": "追加大标题",
      "executeOnce": true,
      "retryOnFail": true,
      "credentials": {
        "notionApi": {
          "id": "XVdzqw1H8HYyzjNp",
          "name": "Notion Blog"
        }
      }
    },
    {
      "parameters": {
        "resource": "block",
        "blockId": {
          "__rl": true,
          "value": "={{ $('创建博客').item.json.url }}",
          "mode": "url"
        },
        "blockUi": {
          "blockValues": [
            {
              "type": "heading_2",
              "textContent": "={{ $('分段分类').item.json.text }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        2080,
        80
      ],
      "id": "f805d3db-04e7-4086-ba24-1eb0ee234fd4",
      "name": "追加中标题",
      "executeOnce": true,
      "retryOnFail": true,
      "credentials": {
        "notionApi": {
          "id": "XVdzqw1H8HYyzjNp",
          "name": "Notion Blog"
        }
      }
    },
    {
      "parameters": {
        "resource": "block",
        "blockId": {
          "__rl": true,
          "value": "={{ $('创建博客').item.json.url }}",
          "mode": "url"
        },
        "blockUi": {
          "blockValues": [
            {
              "type": "heading_3",
              "textContent": "={{ $('分段分类').item.json.text }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        2080,
        240
      ],
      "id": "2d818715-9a89-413e-ab23-7a3ae90feabf",
      "name": "追加小标题",
      "executeOnce": true,
      "retryOnFail": true,
      "credentials": {
        "notionApi": {
          "id": "XVdzqw1H8HYyzjNp",
          "name": "Notion Blog"
        }
      }
    },
    {
      "parameters": {
        "resource": "block",
        "blockId": {
          "__rl": true,
          "value": "={{ $('创建博客').item.json.url }}",
          "mode": "url"
        },
        "blockUi": {
          "blockValues": [
            {
              "type": "bulleted_list_item",
              "textContent": "={{ $('分段分类').item.json.text }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        2080,
        400
      ],
      "id": "6d74abf8-7750-4227-9b6e-d18f4496735f",
      "name": "追加列表",
      "executeOnce": true,
      "retryOnFail": true,
      "credentials": {
        "notionApi": {
          "id": "XVdzqw1H8HYyzjNp",
          "name": "Notion Blog"
        }
      }
    },
    {
      "parameters": {
        "resource": "block",
        "blockId": {
          "__rl": true,
          "value": "={{ $('创建博客').item.json.url }}",
          "mode": "url"
        },
        "blockUi": {
          "blockValues": [
            {
              "textContent": "={{ $('分段分类').item.json.text }}"
            }
          ]
        }
      },
      "type": "n8n-nodes-base.notion",
      "typeVersion": 2.2,
      "position": [
        2080,
        560
      ],
      "id": "e4dae2e7-1367-4461-9399-2f30ac39063a",
      "name": "追加段落",
      "executeOnce": true,
      "retryOnFail": true,
      "credentials": {
        "notionApi": {
          "id": "XVdzqw1H8HYyzjNp",
          "name": "Notion Blog"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $('分段分类').item.json.type }}",
                    "rightValue": "heading_1",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "heading_1"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "be6a7a47-4362-4d7c-a105-9a55776a5d17",
                    "leftValue": "={{ $('分段分类').item.json.type }}",
                    "rightValue": "heading_2",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "heading_2"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "d66f787f-9248-4a94-81ef-2f75f72503fc",
                    "leftValue": "={{ $('分段分类').item.json.type }}",
                    "rightValue": "heading_3",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "heading_3"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "3ecc08e6-3a1d-4667-80c4-37ef0873cdc5",
                    "leftValue": "={{ $('分段分类').item.json.type }}",
                    "rightValue": "bulleted_list_item",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "bulleted_list_item"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "0ba72b7a-6f10-4b90-bdba-1c0eba95e0c5",
                    "leftValue": "={{ $('分段分类').item.json.type }}",
                    "rightValue": "paragraph",
                    "operator": {
                      "type": "string",
                      "operation": "equals",
                      "name": "filter.operator.equals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "paragraph"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        1800,
        -40
      ],
      "id": "5b979216-0fe6-43c5-87ac-5f8186d84981",
      "name": "语句分类"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        1580,
        0
      ],
      "id": "1494c4f1-ae95-4b6d-9ee6-1ffb403af4d1",
      "name": "轮循",
      "retryOnFail": true
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 1
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        380,
        0
      ],
      "id": "4705ca54-a999-43e3-8750-a7b001252416",
      "name": "每天运行一次",
      "notesInFlow": true
    }
  ],
  "pinData": {},
  "connections": {
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Gemini总结",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "分段分类": {
      "main": [
        [
          {
            "node": "轮循",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "创建博客": {
      "main": [
        [
          {
            "node": "分段分类",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini总结": {
      "main": [
        [
          {
            "node": "创建博客",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "提取有效内容": {
      "main": [
        [
          {
            "node": "Gemini总结",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "读取L站热门消息": {
      "main": [
        [
          {
            "node": "提取有效内容",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "追加大标题": {
      "main": [
        [
          {
            "node": "轮循",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "追加中标题": {
      "main": [
        [
          {
            "node": "轮循",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "追加小标题": {
      "main": [
        [
          {
            "node": "轮循",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "追加列表": {
      "main": [
        [
          {
            "node": "轮循",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "追加段落": {
      "main": [
        [
          {
            "node": "轮循",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "语句分类": {
      "main": [
        [
          {
            "node": "追加大标题",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "追加中标题",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "追加小标题",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "追加列表",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "追加段落",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "轮循": {
      "main": [
        [],
        [
          {
            "node": "语句分类",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "每天运行一次": {
      "main": [
        [
          {
            "node": "读取L站热门消息",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "463e9dc0-579e-4a57-aff8-93dca99a1b56",
  "meta": {
    "instanceId": "273cb072730a54351e245b85466131b67e03b4084264c10b9a2f40e05554ac84"
  },
  "id": "mC58320NUZgQLvGA",
  "tags": []
}

简单配置好notion和Gemini相关API后,即可实现每日推送。
工作流每个节点我都有中文解释,就不作继续讲解了。
若想推送每周热贴内容,同理,在rss read里稍作修改:改成period=weekly

AI使用免费的Gemini pro或Gemini flash均可

58 Likes

感谢大佬分享

1 Like

感谢分享,正在考虑部署这个,就看到大佬教程了

出个tg聚合的?

此贴必火,我说的

感谢分享,mark一下

感谢佬友分享,这就去玩玩 :bili_057:

想了想,还是放出效果演示网站,我这博客网站不怎么写文章 :face_with_open_eyes_and_hand_over_mouth:因为免费部署着玩的,大家不用关注

thumbs up!

前排围观支持一下

感谢大佬分享

感谢分享很棒

感谢大佬分享

感谢分享,我每次总结的新闻不超过10条,甚至5条以内,不像演示网页中有几十条,这是什么原因? :rofl:

感谢佬友分享

应该是AI模型的原因,你使用的什么模型?

找到原因了,用new-api中转openrouter模型会出各种问题,而直接用原始api就能获得30个结果。我看日志可以获取正确补全数据,但是下一步处理AI返回答案的时候会出错

配置notion的key


交个作业,美汁汁,感谢佬友的分享

1 Like

牛牛牛牛牛!