1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
| { "name": "自动同步公众号文章工作流", "nodes": [ { "parameters": {}, "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [ -1540, 180 ], "id": "5a254125-e659-40e4-b4ff-785d341941e5", "name": "When clicking ‘Execute workflow’" }, { "parameters": { "assignments": { "assignments": [ { "id": "1aead2d8-db32-4837-a7bc-4f654b159db4", "name": "biz", "value": "[\"MzIzNjc1NzUzMw==\",\"MzI3MTA0MTk1MA==\",\"MzA3MzI4MjgzMw==\"]", "type": "array" }, { "id": "3152a413-b0db-4206-a571-c80df9a90b2b", "name": "name", "value": "[\"量子位\",\"新智元\",\"机器之心\"]", "type": "array" }, { "id": "742495c8-fb2c-4664-8fb0-91dea7d4ce94", "name": "key", "value": "极致了ID【需改为自己的】", "type": "string" } ] }, "options": {} }, "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [ -1320, 180 ], "id": "bbe2617a-d9a4-4d01-aac5-a0523aafa230", "name": "Edit Fields" }, { "parameters": { "options": {} }, "type": "n8n-nodes-base.splitInBatches", "typeVersion": 3, "position": [ -660, 180 ], "id": "e7eb8ed5-0da1-40c5-a26f-ce52a4aeef5f", "name": "Loop Over Items" }, { "parameters": { "method": "POST", "url": "https://www.dajiala.com/fbmain/monitor/v3/post_history", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Content-Type", "value": "application/json" } ] }, "sendBody": true, "specifyBody": "json", "jsonBody": "={\n \"biz\": \"{{ $json.key }}\",\n \"url\": \"\",\n \"name\": \"{{ $json.value }}\",\n \"page\": 1,\n \"key\": \"{{ $('Edit Fields').item.json.key }}\",\n \"verifycode\": \"\"\n}", "options": { "redirect": { "redirect": {} } } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ -440, 100 ], "id": "9f4cde6a-561e-4251-abcb-dd5f5091a430", "name": "HTTP Request" }, { "parameters": { "url": "={{ $json.url }}", "sendHeaders": true, "headerParameters": { "parameters": [ { "name": "Accept", "value": "*/*" }, { "name": "Accept-Encoding", "value": "deflate, gzip" }, { "name": "User-Agent", "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36" }, { "name": "Host", "value": "mp.weixin.qq.com" } ] }, "options": {} }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 0, 0 ], "id": "fdcf74f5-ce95-41d3-9fa1-9d4320160b0b", "name": "HTTP Request1" }, { "parameters": { "operation": "extractHtmlContent", "extractionValues": { "values": [ { "key": "data", "cssSelector": "#page-content" } ] }, "options": {} }, "type": "n8n-nodes-base.html", "typeVersion": 1.2, "position": [ 220, 0 ], "id": "a2b2458c-b9db-4f4d-a320-46260906cc92", "name": "HTML" }, { "parameters": {}, "type": "n8n-nodes-base.limit", "typeVersion": 1, "position": [ -880, 180 ], "id": "00347ab9-2584-4a24-8758-5e5eaf7af2cb", "name": "Limit" }, { "parameters": { "fieldToSplitOut": "data", "options": {} }, "type": "n8n-nodes-base.splitOut", "typeVersion": 1, "position": [ -220, 100 ], "id": "8b84e033-3f81-4162-a775-117a24f70142", "name": "Split Out1" }, { "parameters": { "jsCode": "/**\n * 将Markdown文本转换为纯文本\n * @param {string} markdown - 输入的Markdown格式文本\n * @returns {string} - 转换后的纯文本字符串\n */\nfunction markdownToText(markdown) {\n if (!markdown) return '';\n\n let text = markdown;\n\n // 移除代码块\n text = text.replace(/```[\\s\\S]*?```/g, '');\n text = text.replace(/`([^`]+)`/g, '$1');\n\n // 移除标题符号\n text = text.replace(/^#{1,6}\\s+/gm, '');\n\n // 移除粗体和斜体\n text = text.replace(/[*_]{2}([^*_]+)[*_]{2}/g, '$1'); // 粗体\n text = text.replace(/[*_]([^*_]+)[*_]/g, '$1'); // 斜体\n\n // 处理链接\n text = text.replace(/\\[([^\\]]+)\\]\\([^)]+\\)/g, '$1'); // [文本](链接)\n text = text.replace(/\\[([^\\]]+)\\]\\[[^\\]]*\\]/g, '$1'); // [文本][引用]\n\n // 移除图片标记\n text = text.replace(/!\\[([^\\]]*?)\\]\\([^)]+\\)/g, '$1');\n \n // 处理各种非标准格式的图片标记\n text = text.replace(/!图片\\s*\\)/g, '');\n text = text.replace(/!图片\\s*$/g, '');\n text = text.replace(/!图片[\\s\\S]*?\\)/g, '');\n text = text.replace(/^\\s*\\)\\s*$/gm, '');\n text = text.replace(/^\\s*$/gm, '');\n\n // 处理列表\n text = text.replace(/^[\\s]*[\\-*+]\\s+/gm, ''); // 无序列表\n text = text.replace(/^[\\s]*\\d+\\.\\s+/gm, ''); // 有序列表\n\n // 处理引用\n text = text.replace(/^\\s*>\\s+/gm, '');\n\n // 处理水平分割线\n text = text.replace(/^\\s*[-*_]{3,}\\s*$/gm, '\\n');\n\n // 移除SVG相关标签及其内容\n text = text.replace(/<svg[^>]*>(([\\s\\S]*?)<\\/svg>)?/gi, '');\n \n // 增强SVG标签清理\n const svgElements = 'svg|rect|circle|path|line|polygon|polyline|g|defs|use|symbol|ellipse|text|image|clipPath|mask|pattern|filter|marker|linearGradient|radialGradient|stop|tspan|textPath|animate|animateMotion|animateTransform|set|foreignObject|switch|desc|title|metadata';\n text = text.replace(new RegExp(`<(${svgElements})(\\\\s[^>]*)?\\\\/?>`,'gi'), '');\n text = text.replace(new RegExp(`<\\\\/(${svgElements})>`,'gi'), '');\n \n // 移除单独的SVG标签片段\n text = text.replace(/[\\s']+(?:rect|circle|path|g|svg|defs|use|symbol)\\s*\\/?/gi, ' ');\n text = text.replace(/[\\s']+\\/(?:rect|circle|path|g|svg|defs|use|symbol)\\s*/gi, ' ');\n \n // 移除括号内的SVG标签片段\n text = text.replace(/\\([^\\)]*?(?:rect|circle|path|g|svg)[^\\)]*?\\)/gi, '');\n \n // 清理SVG属性和标签片段\n text = text.replace(/['\"\\s]+(fill|x|y|width|height|rx|ry|cx|cy|r|d|points|viewBox|xmlns)=['\"]?[^'\">\\s]*['\"]?/gi, ' ');\n text = text.replace(/\\s+(?:\\/)?(?:rect|circle|path|g|svg|defs|use|symbol|ellipse|text)(?:\\s+|\\/)/gi, ' ');\n text = text.replace(/\\s+\\/(?:rect|circle|path|g|svg|defs|use|symbol|ellipse|text)(?:\\s+|$)/gi, ' ');\n \n // 移除SVG和HTML常见属性\n const commonAttributes = 'xmlns|version|viewBox|width|height|class|style|id|fill|stroke|d|points|transform|x|y|cx|cy|r|x1|y1|x2|y2|dx|dy|offset|gradientUnits|spreadMethod|patternUnits|patternTransform|markerWidth|markerHeight|refX|refY|orient|font-size|font-family|text-anchor|alignment-baseline|href|xlink:href|preserveAspectRatio';\n text = text.replace(new RegExp(`\\\\s+(${commonAttributes})=[\\\"\\']([^\\\"\\']*)[\\\"\\'](?:\\\\s+|$)`,'gi'), ' ');\n \n // 移除data URI和编码内容\n text = text.replace(/data:(?:[^;]+;)*(?:base64,)?[a-zA-Z0-9+/]+={0,2}/g, '');\n text = text.replace(/%[0-9a-fA-F]{2}/g, ' ');\n \n // 最终清理:移除任何剩余的SVG相关内容\n text = text.replace(/\\([^\\)]*(?:svg|rect|g|path|circle)[^\\)]*\\)/gi, '');\n text = text.replace(/'[^']*(?:svg|rect|g|path|circle)[^']*'/gi, '');\n text = text.replace(/\"[^\"]*(?:svg|rect|g|path|circle)[^\"]*\"/gi, '');\n text = text.replace(/(?:\\/)?(?:svg|rect|g|path|circle|defs|use|symbol)(?:\\/)?/gi, '');\n \n // 移除其他HTML标签\n text = text.replace(/<[^>]+>/g, '');\n\n // 处理转义字符\n text = text.replace(/\\\\([\\\\`*_{}\\[\\]()#+\\-.!])/g, '$1');\n\n // 清理多余的空行\n text = text.replace(/\\n\\s*\\n/g, '\\n\\n');\n text = text.replace(/^\\s+|\\s+$/g, '');\n\n return text;\n}\n\n/**\n * 将文本按指定长度分段\n * @param {string} text - 输入文本\n * @param {number} segmentLength - 每段文本的最大长度\n * @returns {string[]} - 分段后的文本数组\n */\nfunction splitTextIntoSegments(text, segmentLength = 1800) {\n const segments = [];\n let remainingText = text;\n\n while (remainingText.length > 0) {\n if (remainingText.length <= segmentLength) {\n segments.push(remainingText);\n break;\n }\n\n let endIndex = segmentLength;\n // 尝试在句子或段落边界处分段\n const nextParagraph = remainingText.indexOf('\\n\\n', endIndex - 100);\n const nextSentence = remainingText.indexOf('. ', endIndex - 100);\n\n if (nextParagraph !== -1 && nextParagraph < endIndex + 100) {\n endIndex = nextParagraph;\n } else if (nextSentence !== -1 && nextSentence < endIndex + 100) {\n endIndex = nextSentence + 1;\n }\n\n segments.push(remainingText.substring(0, endIndex).trim());\n remainingText = remainingText.substring(endIndex).trim();\n }\n\n return segments;\n}\n\n// 获取所有输入数据项\nconst inputItems = $input.all();\nconst results = [];\n\n// 遍历处理每个输入数据项\nfor (let i = 0; i < inputItems.length; i++) {\n const currentItem = inputItems[i];\n const markdownInput = currentItem.json.data;\n \n if (!markdownInput) {\n // 如果没有数据,跳过这个项目\n continue;\n }\n \n const plainText = markdownToText(markdownInput);\n const textSegments = splitTextIntoSegments(plainText);\n\n // 将文本段落转换为规范的block对象格式\n const blocks = textSegments.map(segment => ({\n object: 'block',\n type: 'paragraph',\n paragraph: {\n rich_text: [\n {\n type: 'text',\n annotations: {\n bold: false,\n strikethrough: false,\n underline: false,\n italic: false,\n code: false,\n color: 'default'\n },\n text: {\n content: segment\n }\n }\n ]\n }\n }));\n\n // 只返回blocks字段\n results.push({\n json: {\n blocks: blocks\n }\n });\n}\n\nreturn results;\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ 440, 0 ], "id": "aa48ed34-8002-42c1-84e4-8412ccbc994a", "name": "将Markdown文本转换为纯文本" }, { "parameters": { "method": "PATCH", "url": "=https://api.notion.com/v1/blocks/{{ $json.id }}/children", "authentication": "predefinedCredentialType", "nodeCredentialType": "notionApi", "sendBody": true, "bodyParameters": { "parameters": [ { "name": "children", "value": "={{ $json.blocks }}" } ] }, "options": { "batching": { "batch": { "batchSize": 1, "batchInterval": 5000 } } } }, "type": "n8n-nodes-base.httpRequest", "typeVersion": 4.2, "position": [ 880, 180 ], "id": "d90ab579-1acf-4e0f-a6f5-b3bf30df1787", "name": "HTTP Request2", "credentials": { "notionApi": { "id": "p9ESbt4TrdVy1Eq0", "name": "Notion account" } }, "onError": "continueRegularOutput" }, { "parameters": { "mode": "combine", "combineBy": "combineByPosition", "options": {} }, "type": "n8n-nodes-base.merge", "typeVersion": 3.2, "position": [ 660, 100 ], "id": "f8cda93f-baa4-4f00-8323-f18ed5768cbc", "name": "Merge" }, { "parameters": { "jsCode": "const array1 = $input.first().json.biz;\nconst array2 = $input.first().json.name;\nconst combined = [];\n\nfor (let i = 0; i < array1.length; i++) {\n combined.push({\n key: array1[i],\n value: array2[i]\n });\n}\n\nreturn combined.map(item => ({ json: item }));\n" }, "type": "n8n-nodes-base.code", "typeVersion": 2, "position": [ -1100, 180 ], "id": "44c229a5-fb2a-49db-a037-d35cc816f145", "name": "Code" }, { "parameters": { "content": "## 文章同步完成后动作\n- 发送Telegram通知\n- 执行内容加工工作流,如:日报工作流、小红书发布工作流等", "height": 360, "color": 6 }, "type": "n8n-nodes-base.stickyNote", "position": [ -720, 20 ], "typeVersion": 1, "id": "c8a3ef38-5ccf-41db-b97f-2e6c9bc2251d", "name": "Sticky Note" }, { "parameters": { "resource": "databasePage", "databaseId": { "__rl": true, "value": "22c977e7-bf54-80fe-8606-e6291091d347", "mode": "list", "cachedResultName": "AI资讯", "cachedResultUrl": "https://www.notion.so/22c977e7bf5480fe8606e6291091d347" }, "title": "={{ $json.title }}", "propertiesUi": { "propertyValues": [ { "key": "标题|title", "title": "={{ $json.title }}" }, { "key": "url|rich_text", "textContent": "={{ $json.url }}" }, { "key": "时间|rich_text", "textContent": "={{ $json.post_time_str }}" }, { "key": "来源|rich_text", "textContent": "={{ $('Loop Over Items').item.json.value }}" } ] }, "options": {} }, "type": "n8n-nodes-base.notion", "typeVersion": 2.2, "position": [ 380, 200 ], "id": "76a42023-6d48-49e9-8e2d-bcb83fac8469", "name": "Create a database page", "credentials": { "notionApi": { "id": "p9ESbt4TrdVy1Eq0", "name": "Notion account" } } } ], "pinData": {}, "connections": { "When clicking ‘Execute workflow’": { "main": [ [ { "node": "Edit Fields", "type": "main", "index": 0 } ] ] }, "Edit Fields": { "main": [ [ { "node": "Code", "type": "main", "index": 0 } ] ] }, "Loop Over Items": { "main": [ [], [ { "node": "HTTP Request", "type": "main", "index": 0 } ] ] }, "HTTP Request": { "main": [ [ { "node": "Split Out1", "type": "main", "index": 0 } ] ] }, "HTTP Request1": { "main": [ [ { "node": "HTML", "type": "main", "index": 0 } ] ] }, "HTML": { "main": [ [ { "node": "将Markdown文本转换为纯文本", "type": "main", "index": 0 } ] ] }, "Limit": { "main": [ [ { "node": "Loop Over Items", "type": "main", "index": 0 } ] ] }, "Split Out1": { "main": [ [ { "node": "HTTP Request1", "type": "main", "index": 0 }, { "node": "Create a database page", "type": "main", "index": 0 } ] ] }, "将Markdown文本转换为纯文本": { "main": [ [ { "node": "Merge", "type": "main", "index": 0 } ] ] }, "Merge": { "main": [ [ { "node": "HTTP Request2", "type": "main", "index": 0 } ] ] }, "Code": { "main": [ [ { "node": "Limit", "type": "main", "index": 0 } ] ] }, "HTTP Request2": { "main": [ [ { "node": "Loop Over Items", "type": "main", "index": 0 } ] ] }, "Create a database page": { "main": [ [ { "node": "Merge", "type": "main", "index": 1 } ] ] } }, "active": false, "settings": { "executionOrder": "v1" }, "versionId": "cd2c82a4-1f94-406d-88c1-844e20e7f548", "meta": { "templateCredsSetupCompleted": true, "instanceId": "ee5a0f120935b4b9d760798993ffeb282a815d20023e81bf0157ea4e4d3aad64" }, "id": "kn2URDK94wsWOj4F", "tags": [] }
|