{
  "name": "Weekly sitemap new and removed URLs (Skillaisle)",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "cronExpression",
              "expression": "0 9 * * 1"
            }
          ]
        }
      },
      "id": "c4d2e6f8-0003-4000-8000-000000000001",
      "name": "Mondays 09:00",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "c4d2e6f8-0003-4000-8000-0000000000c1",
              "name": "sitemap_url",
              "value": "https://example.com/sitemap.xml",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "c4d2e6f8-0003-4000-8000-000000000002",
      "name": "Config",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        0
      ]
    },
    {
      "parameters": {
        "url": "={{ $json.sitemap_url }}",
        "options": {
          "response": {
            "response": {
              "responseFormat": "text"
            }
          }
        }
      },
      "id": "c4d2e6f8-0003-4000-8000-000000000003",
      "name": "Fetch sitemap",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        480,
        0
      ]
    },
    {
      "parameters": {
        "jsCode": "const cfg = $('Config').first().json;\nconst raw = String($json.data ?? $json.body ?? '');\nconst urls = [...new Set([...raw.matchAll(/<loc>\\s*([^<\\s]+)\\s*<\\/loc>/gi)].map(m => m[1].trim()))].sort();\nconst store = $getWorkflowStaticData('global');\nconst key = 'urls:' + cfg.sitemap_url;\nconst prev = store[key];\nconst now = new Date().toISOString();\nconst lines = [`# Sitemap changes`, '', `Sitemap: ${cfg.sitemap_url}`, `Checked: ${now}`, `URLs now: ${urls.length}`, ''];\nlet added = [], removed = [];\nif (!Array.isArray(prev)) {\n  lines.push('First run: baseline saved. Changes will show from the next run.');\n} else {\n  const before = new Set(prev);\n  const after = new Set(urls);\n  added = urls.filter(u => !before.has(u));\n  removed = prev.filter(u => !after.has(u));\n  lines.push(`## Added (${added.length})`, ...(added.length ? added.map(u => `- ${u}`) : ['- none']), '');\n  lines.push(`## Removed (${removed.length})`, ...(removed.length ? removed.map(u => `- ${u}`) : ['- none']));\n}\nif (urls.length === 0) lines.push('', 'Warning: no <loc> entries found. Check that the URL is a sitemap, not a sitemap index or an HTML page.');\nelse store[key] = urls;\nreturn [{ json: { report: lines.join('\\n'), total: urls.length, added: added.length, removed: removed.length } }];"
      },
      "id": "c4d2e6f8-0003-4000-8000-000000000004",
      "name": "Compare with last run",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        720,
        0
      ]
    },
    {
      "parameters": {
        "operation": "toText",
        "sourceProperty": "report",
        "options": {
          "fileName": "sitemap-changes.md"
        }
      },
      "id": "c4d2e6f8-0003-4000-8000-000000000005",
      "name": "Report file",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        960,
        0
      ]
    }
  ],
  "connections": {
    "Mondays 09:00": {
      "main": [
        [
          {
            "node": "Config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config": {
      "main": [
        [
          {
            "node": "Fetch sitemap",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch sitemap": {
      "main": [
        [
          {
            "node": "Compare with last run",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compare with last run": {
      "main": [
        [
          {
            "node": "Report file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {}
}
