Cron

Sitemap Güncelleme ve Arama Motoru Ping Otomasyonu

02 May 2026

Description

Sitemap.xml dosyasını iki kez kontrol eder, ardından günde iki kez yeni içerik kontrolü yapar ve değişiklik olduğunda popüler arama motorlarına ping gönderir.

Setup Guide

1. n8n ortamında yeni bir workflow oluşturun.
2. Trigger tipini **Cron** olarak ayarlayın; başlangıçta 0 0 * * * (midnight) ve 12 0 * * * (öğlen) iki kez çalışacak şekilde iki Cron düğümü ekleyin.
3. **HTTP Request** düğmesini ekleyip URL olarak `https://yourdomain.com/sitemap.xml` girin, Method: GET.
4. **Set** düğmesiyle `response.body` içeriğini `sitemapXml` değişkenine atayın.
5. **Function** düğmesi ekleyerek XML'i JSON’a dönüştürün ve `lastMod` tarihlerini bir diziye çıkarın.
6. **IF** düğmesi ile önceki çalışmadan kaydedilen hash (ör. MD5) ile yeni hash karşılaştırılır; farklı ise true, aynı ise false.
7. **Function (Prepare Ping URLs)** düğmesinde aşağıdaki arama motoru ping endpointlerini diziye ekleyin:
- https://www.google.com/ping?sitemap={{sitemapUrl}}
- https://www.bing.com/ping?sitemap={{sitemapUrl}}
- https://search.yahoo.com/ping?sitemap={{sitemapUrl}}
- https://www.ask.com/ping?sitemap={{sitemapUrl}}
- https://www.yandex.com/ping?sitemap={{sitemapUrl}}
8. **HTTP Request (Ping Engines)** düğmesini **SplitInBatches** ile döngüye alıp her bir URL’ye GET isteği gönderin.
9. Başarılı yanıtları **NoOp (Success Log)** düğmesiyle loglayın; değişiklik yoksa **NoOp (No Change Log)** ile bilgilendirin.
10. Workflow’u kaydedin ve aktif hale getirin. İlk iki çalıştırma manuel olarak tetiklenebilir (Run) ve ardından cron ile otomatik devam eder.

Workflow Preview

Loading Visualization...

JSON Code

automation.json
{
    "nodes": [
        {
            "parameters": {
                "cronExpression": "0 0 * * *",
                "timezone": "UTC"
            },
            "name": "Cron Midnight",
            "type": "n8n-nodes-base.cron",
            "typeVersion": 1,
            "position": [
                250,
                300
            ]
        },
        {
            "parameters": {
                "cronExpression": "0 12 * * *",
                "timezone": "UTC"
            },
            "name": "Cron Noon",
            "type": "n8n-nodes-base.cron",
            "typeVersion": 1,
            "position": [
                250,
                500
            ]
        },
        {
            "parameters": {
                "url": "https:\/\/yourdomain.com\/sitemap.xml",
                "method": "GET",
                "responseFormat": "string",
                "jsonParameters": false,
                "options": []
            },
            "name": "Get Sitemap",
            "type": "n8n-nodes-base.httpRequest",
            "typeVersion": 2,
            "position": [
                500,
                300
            ],
            "credentials": []
        },
        {
            "parameters": {
                "values": {
                    "string": [
                        {
                            "name": "sitemapXml",
                            "value": "={{$json[\"body\"]}}"
                        }
                    ]
                },
                "options": []
            },
            "name": "Store Sitemap",
            "type": "n8n-nodes-base.set",
            "typeVersion": 2,
            "position": [
                750,
                300
            ]
        },
        {
            "parameters": {
                "functionCode": "const crypto = require('crypto');\nconst xml2js = require('xml2js');\nconst parser = new xml2js.Parser({ explicitArray: false });\n\nreturn new Promise((resolve, reject) => {\n  parser.parseString(item.sitemapXml, (err, result) => {\n    if (err) return reject(err);\n    const urls = result?.urlset?.url ?? [];\n    const lastMods = Array.isArray(urls) ? urls.map(u => u.lastmod) : [urls.lastmod];\n    const hash = crypto.createHash('md5').update(JSON.stringify(lastMods)).digest('hex');\n    \/\/ store hash in workflow static data\n    const previous = $node[\"Store Previous Hash\"].json?.hash || '';\n    const changed = previous !== hash;\n    \/\/ update static data for next run\n    $node[\"Store Previous Hash\"].json = { hash };\n    resolve({ changed, hash, lastMods, sitemapUrl: $node[\"Get Sitemap\"].json?.url || \"https:\/\/yourdomain.com\/sitemap.xml\" });\n  });\n});",
                "outputDataType": "json"
            },
            "name": "Parse & Detect Change",
            "type": "n8n-nodes-base.function",
            "typeVersion": 2,
            "position": [
                1000,
                300
            ]
        },
        {
            "parameters": {
                "functionCode": "if (!items[0].json.changed) return [];\nconst sitemapUrl = items[0].json.sitemapUrl;\nconst engines = [\n  `https:\/\/www.google.com\/ping?sitemap=${encodeURIComponent(sitemapUrl)}`,\n  `https:\/\/www.bing.com\/ping?sitemap=${encodeURIComponent(sitemapUrl)}`,\n  `https:\/\/search.yahoo.com\/ping?sitemap=${encodeURIComponent(sitemapUrl)}`,\n  `https:\/\/www.ask.com\/ping?sitemap=${encodeURIComponent(sitemapUrl)}`,\n  `https:\/\/www.yandex.com\/ping?sitemap=${encodeURIComponent(sitemapUrl)}`,\n];\nreturn engines.map(url => ({ json: { pingUrl: url } }));",
                "outputDataType": "json"
            },
            "name": "Prepare Ping URLs",
            "type": "n8n-nodes-base.function",
            "typeVersion": 2,
            "position": [
                1250,
                300
            ]
        },
        {
            "parameters": {
                "requestMethod": "GET",
                "url": "={{$json[\"pingUrl\"]}}",
                "responseFormat": "string",
                "jsonParameters": false,
                "options": []
            },
            "name": "Ping Engine",
            "type": "n8n-nodes-base.httpRequest",
            "typeVersion": 2,
            "position": [
                1500,
                300
            ],
            "credentials": []
        },
        {
            "parameters": {
                "functionCode": "return [{ json: { message: 'Ping successful', url: $json[\"pingUrl\"] } }];"
            },
            "name": "Success Log",
            "type": "n8n-nodes-base.function",
            "typeVersion": 2,
            "position": [
                1750,
                250
            ]
        },
        {
            "parameters": {
                "functionCode": "return [{ json: { message: 'No sitemap change detected' } }];"
            },
            "name": "No Change Log",
            "type": "n8n-nodes-base.function",
            "typeVersion": 2,
            "position": [
                1750,
                350
            ]
        },
        {
            "parameters": [],
            "name": "Store Previous Hash",
            "type": "n8n-nodes-base.set",
            "typeVersion": 2,
            "position": [
                1000,
                500
            ]
        }
    ],
    "connections": {
        "Cron Midnight": {
            "main": [
                [
                    {
                        "node": "Get Sitemap",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Cron Noon": {
            "main": [
                [
                    {
                        "node": "Get Sitemap",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Get Sitemap": {
            "main": [
                [
                    {
                        "node": "Store Sitemap",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Store Sitemap": {
            "main": [
                [
                    {
                        "node": "Parse & Detect Change",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Parse & Detect Change": {
            "main": [
                [
                    {
                        "node": "IF",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "IF": {
            "main": [
                [
                    {
                        "node": "Prepare Ping URLs",
                        "type": "main",
                        "index": 0
                    }
                ],
                [
                    {
                        "node": "No Change Log",
                        "type": "main",
                        "index": 0
                    }
                ]
            ],
            "rules": [
                {
                    "condition": "={{$json[\"changed\"] === true}}"
                },
                {
                    "condition": "={{$json[\"changed\"] === false}}"
                }
            ]
        },
        "Prepare Ping URLs": {
            "main": [
                [
                    {
                        "node": "Ping Engine",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        },
        "Ping Engine": {
            "main": [
                [
                    {
                        "node": "Success Log",
                        "type": "main",
                        "index": 0
                    }
                ]
            ]
        }
    },
    "active": false,
    "settings": [],
    "id": "1"
}