| 128 | } |
| 129 | |
| 130 | async function syncsiteStandardDocuments(client: Client, documentsToSync: DocumentToSync[]) { |
| 131 | let currentCommit = await client.xrpc(com.atproto.sync.getLatestCommit, { |
| 132 | params: { |
| 133 | did: client.assertDid, |
| 134 | }, |
| 135 | }) |
| 136 | |
| 137 | let writes = documentsToSync.map(doc => |
| 138 | //this should be an .update but having issues with it, and the records are checked before creating |
| 139 | com.atproto.repo.applyWrites.create.$build({ |
| 140 | rkey: doc.tid, |
| 141 | value: doc.document, |
| 142 | collection: site.standard.document.$nsid, |
| 143 | }), |
| 144 | ) |
| 145 | |
| 146 | await client.xrpc(com.atproto.repo.applyWrites, { |
| 147 | body: { |
| 148 | repo: client.assertDid, |
| 149 | writes, |
| 150 | swapCommit: currentCommit.body.cid, |
| 151 | }, |
| 152 | }) |
| 153 | |
| 154 | console.log('[standard-site-sync] synced all new publications') |
| 155 | } |
| 156 | |
| 157 | // Schema expects 'path' & frontmatter provides 'slug' |
| 158 | function normalizeBlogFrontmatter(frontmatter: Record<string, unknown>): Record<string, unknown> { |