Skip to content

Instantly share code, notes, and snippets.

@ranafaraz
Last active August 14, 2025 18:51
Show Gist options
  • Save ranafaraz/a048a45716b20b60383c0ef324ba3ae1 to your computer and use it in GitHub Desktop.
Save ranafaraz/a048a45716b20b60383c0ef324ba3ae1 to your computer and use it in GitHub Desktop.
A workflow to post content on wordpress using gemini.
{
"name": "MVP WP Compare (Gemini <1000w Autopublish)",
"nodes": [
{ "parameters": {}, "id": "1", "name": "Manual", "type": "n8n-nodes-base.manualTrigger", "typeVersion": 1, "position": [140, -260] },
{ "parameters": { "triggerTimes": { "item": [ { "mode": "everyDay", "hour": 0, "minute": 0 } ] } }, "id": "2", "name": "Cron", "type": "n8n-nodes-base.cron", "typeVersion": 1, "position": [140, -60] },
{
"parameters": {
"functionCode": "return [{ json: {\n wpBaseUrl: $env.WP_BASE_URL || \"https://example.com\",\n feedUrl: \"https://news.google.com/rss?hl=en&gl=US&ceid=US:en\",\n maxItems: 3,\n minContentChars: 600,\n geminiModel: \"gemini-1.5-pro\",\n temp: 0.2,\n maxOutputTokens: 950,\n postStatus: \"publish\"\n}}];"
},
"id": "3",
"name": "Config",
"type": "n8n-nodes-base.function",
"typeVersion": 2,
"position": [360, -160]
},
{ "parameters": { "feedUrl": "={{$json.feedUrl}}" }, "id": "4", "name": "RSS", "type": "n8n-nodes-base.rssFeedRead", "typeVersion": 1, "position": [580, -160] },
{ "parameters": { "maxItems": "={{$items('Config')[0].json.maxItems}}" }, "id": "5", "name": "Limit", "type": "n8n-nodes-base.limit", "typeVersion": 1, "position": [780, -160] },
{ "parameters": { "url": "={{$json[\"link\"]}}", "responseFormat": "string" }, "id": "6", "name": "Fetch", "type": "n8n-nodes-base.httpRequest", "typeVersion": 4, "position": [980, -160] },
{
"parameters": {
"operation": "extractHtmlContent",
"sourceData": "json",
"jsonProperty": "data",
"extractionValues": { "values": [ { "key": "text", "cssSelector": "article, main, .post-content, .entry-content, p", "returnValue": "text", "returnArray": true } ] }
},
"id": "7",
"name": "HTML2Text",
"type": "n8n-nodes-base.html",
"typeVersion": 1,
"position": [1180, -160]
},
{
"parameters": {
"functionCode": "const cfg=$items('Config')[0].json; const arr=Array.isArray($json.text)?$json.text:[]; const body=arr.map(t=>(t||'').trim()).filter(Boolean).join('\\n\\n'); if((body||'').length<cfg.minContentChars){return [];} const url=($json.link||'').replace(/^http:\\/\\//,'https://'); const domain=url.replace(/^https?:\\/\\/(www\\.)?/,'').split('/')[0].toLowerCase(); return [{json:{cfg, title:$json.title||'', url, domain, body}}];"
},
"id": "8",
"name": "Prep",
"type": "n8n-nodes-base.function",
"typeVersion": 2,
"position": [1380, -160]
},
{
"parameters": { "functionCode": "const cfg=$json.cfg; const sources=items.map(i=>({title:i.json.title,url:i.json.url,domain:i.json.domain,body:i.json.body})); return [{json:{cfg,sources}}];" },
"id": "9",
"name": "Pack",
"type": "n8n-nodes-base.function",
"typeVersion": 2,
"position": [1580, -160]
},
{
"parameters": {
"method": "POST",
"url": "={{'https://generativelanguage.googleapis.com/v1beta/models/' + $json.cfg.geminiModel + ':generateContent?key=' + $env.GEMINI_API_KEY}}",
"sendBody": true,
"jsonParameters": true,
"bodyParametersJson": "{\n \"contents\":[{\"parts\":[{\"text\":\"Write a CRITICAL COMPARATIVE blog post from SOURCES (JSON array provided). Output ONLY JSON with keys: {\\\\n \\\\\\\"title\\\\\\\":\\\\\\\"...\\\\\\\",\\\\n \\\\\\\"slug\\\\\\\":\\\\\\\"kebab-case\\\\\\\",\\\\n \\\\\\\"excerpt\\\\\\\":\\\\\\\"18-25 words\\\\\\\",\\\\n \\\\\\\"markdown\\\\\\\":\\\\\\\"...\\\\\\\"\\\\n}\\\\nRules: neutral tone; include a TL;DR blockquote; include a head-to-head table (>=5 rows); use inline [n] citations; NO HTML in markdown; total length < 950 words.\\\\nSOURCES: {{$json.sources}}\"}]}],\n \"generationConfig\": { \"temperature\": {{$json.cfg.temp}}, \"maxOutputTokens\": {{$json.cfg.maxOutputTokens}} }\n}"
},
"id": "10",
"name": "Gemini",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4,
"position": [1780, -160]
},
{
"parameters": {
"functionCode": "const cfg=$json.cfg; const text=$json?.candidates?.[0]?.content?.parts?.[0]?.text||''; let post; try{post=JSON.parse(text);}catch(e){const m=text.match(/\\{[\\s\\S]*\\}/); if(m) post=JSON.parse(m[0]); else throw new Error('Gemini JSON parse failed');} post.title=post.title||'Untitled'; post.slug=(post.slug||post.title.toLowerCase().replace(/[^a-z0-9]+/g,'-').replace(/(^-|-$)/g,'')).split('-').slice(0,8).join('-'); post.excerpt=(post.excerpt||'').split(/\\s+/).slice(0,25).join(' '); const words=(post.markdown||'').trim().split(/\\s+/).filter(Boolean); if(words.length>990){ post.markdown=words.slice(0,990).join(' ');} return [{json:{cfg,post}}];"
},
"id": "11",
"name": "Normalize",
"type": "n8n-nodes-base.function",
"typeVersion": 2,
"position": [1980, -160]
},
{ "parameters": { "mode": "mdToHtml", "text": "={{$json.post.markdown}}", "destinationKey": "html" }, "id": "12", "name": "Md2Html", "type": "n8n-nodes-base.markdown", "typeVersion": 1, "position": [2180, -160] },
{
"parameters": {
"method": "POST",
"url": "={{($json.cfg.wpBaseUrl||'').replace(/\\/$/,'') + '/wp-json/wp/v2/posts'}}",
"sendBody": true,
"jsonParameters": true,
"bodyParametersJson": "{\n \"title\": \"={{$json.post.title}}\",\n \"content\": \"={{$json.html}}\",\n \"status\": \"={{$json.cfg.postStatus}}\",\n \"slug\": \"={{$json.post.slug}}\",\n \"excerpt\": \"={{$json.post.excerpt}}\"\n}"
},
"id": "13",
"name": "Post",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4,
"position": [2380, -160]
}
],
"connections": {
"Manual": { "main": [[{ "node": "Config", "type": "main", "index": 0 }]] },
"Cron": { "main": [[{ "node": "Config", "type": "main", "index": 0 }]] },
"Config": { "main": [[{ "node": "RSS", "type": "main", "index": 0 }]] },
"RSS": { "main": [[{ "node": "Limit", "type": "main", "index": 0 }]] },
"Limit": { "main": [[{ "node": "Fetch", "type": "main", "index": 0 }]] },
"Fetch": { "main": [[{ "node": "HTML2Text", "type": "main", "index": 0 }]] },
"HTML2Text": { "main": [[{ "node": "Prep", "type": "main", "index": 0 }]] },
"Prep": { "main": [[{ "node": "Pack", "type": "main", "index": 0 }]] },
"Pack": { "main": [[{ "node": "Gemini", "type": "main", "index": 0 }]] },
"Gemini": { "main": [[{ "node": "Normalize", "type": "main", "index": 0 }]] },
"Normalize": { "main": [[{ "node": "Md2Html", "type": "main", "index": 0 }]] },
"Md2Html": { "main": [[{ "node": "Post", "type": "main", "index": 0 }]] }
},
"active": false,
"settings": { "timezone": "Asia/Karachi" }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment