{
  "name": "App Wizard Academy — Publisher (Multi-Site)",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "publish-approved-drafts-all-sites",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2.1,
      "position": [-624, 96],
      "id": "webhook-trigger",
      "name": "Webhook",
      "webhookId": "publish-approved-drafts-all-sites"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT d.id, d.slug, d.title, d.content_markdown, sc.github_owner, sc.github_repo, sc.vercel_deploy_hook FROM drafts d JOIN site_config sc ON sc.id = d.site_id WHERE d.status = 'approved' AND d.published_at IS NULL ORDER BY d.created_at ASC;",
        "additionalFields": {}
      },
      "name": "Get Approved Drafts (All Sites)",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [-384, 96],
      "id": "get-approved-drafts",
      "credentials": {
        "postgres": { "id": "REPLACE_WITH_YOUR_CREDENTIAL_ID", "name": "YOUR_POSTGRES_OR_SUPABASE_CREDENTIAL" }
      }
    },
    {
      "parameters": {
        "functionCode": "return items.map(item => {\n  const d = item.json;\n  const frontmatter = `---\\ntitle: \"${d.title}\"\\ndate: \"${new Date().toISOString().slice(0,10)}\"\\n---\\n\\n`;\n  return {\n    json: {\n      id: d.id,\n      filePath: `content/posts/${d.slug}.md`,\n      fileContent: frontmatter + d.content_markdown,\n      github_owner: d.github_owner,\n      github_repo: d.github_repo,\n      vercel_deploy_hook: d.vercel_deploy_hook\n    }\n  };\n});"
      },
      "name": "Build Markdown File",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [-144, 96],
      "id": "build-markdown-file"
    },
    {
      "parameters": {
        "resource": "file",
        "operation": "edit",
        "owner": "={{ $json.github_owner }}",
        "repository": "={{ $json.github_repo }}",
        "filePath": "={{ $json.filePath }}",
        "fileContent": "={{ $json.fileContent }}",
        "commitMessage": "=Publish: {{ $json.filePath }}"
      },
      "name": "Commit to GitHub",
      "type": "n8n-nodes-base.github",
      "typeVersion": 1,
      "position": [96, 96],
      "id": "commit-to-github",
      "credentials": {
        "githubApi": { "id": "REPLACE_WITH_YOUR_CREDENTIAL_ID", "name": "YOUR_GITHUB_CREDENTIAL" }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $json.vercel_deploy_hook }}",
        "options": {}
      },
      "name": "Deploy Site",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [336, 96],
      "id": "deploy-site"
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=UPDATE drafts SET status = 'published', published_at = NOW() WHERE id = '{{ $('Build Markdown File').item.json.id }}';",
        "additionalFields": {}
      },
      "name": "Mark Published",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [576, 96],
      "id": "mark-published",
      "credentials": {
        "postgres": { "id": "REPLACE_WITH_YOUR_CREDENTIAL_ID", "name": "YOUR_POSTGRES_OR_SUPABASE_CREDENTIAL" }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={ \"success\": true, \"published\": \"{{ $('Build Markdown File').item.json.filePath }}\" }",
        "options": {}
      },
      "name": "Respond",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [816, 96],
      "id": "respond"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [[{ "node": "Get Approved Drafts (All Sites)", "type": "main", "index": 0 }]]
    },
    "Get Approved Drafts (All Sites)": {
      "main": [[{ "node": "Build Markdown File", "type": "main", "index": 0 }]]
    },
    "Build Markdown File": {
      "main": [[{ "node": "Commit to GitHub", "type": "main", "index": 0 }]]
    },
    "Commit to GitHub": {
      "main": [[{ "node": "Deploy Site", "type": "main", "index": 0 }]]
    },
    "Deploy Site": {
      "main": [[{ "node": "Mark Published", "type": "main", "index": 0 }]]
    },
    "Mark Published": {
      "main": [[{ "node": "Respond", "type": "main", "index": 0 }]]
    }
  },
  "pinData": {},
  "active": false,
  "settings": { "executionOrder": "v1" },
  "versionId": "empire-engine-publisher-multi-site-v1",
  "meta": { "instanceId": "empire-engine-template" },
  "id": "empire-engine-publisher-multi-site",
  "tags": []
}
