···3333- **Name** — from WordPress site title, Yoast SEO, or a custom value
3434- **Description** — from WordPress tagline, Yoast SEO, or a custom value
3535- **Icon** — from WordPress site icon or a custom upload
3636-- **Theme colors** — background, foreground, accent, and accent foreground
3737-- **Discoverability** — opt in or out of discovery feeds
3636+- **Theme colors** — background, foreground, accent, and accent foreground. NOTE: these are used by other ATProto platforms to style your content, not on your WordPress site.
3737+- **Discoverability** — opt in or out of discovery feeds. NOTE: these are used by other ATProto platforms to show your publication in algorithmic feeds, not on your WordPress site.
38383939The plugin also serves a `.well-known/site.standard.publication` endpoint that returns the AT-URI of your publication record.
4040
+144
assets/js/settings.js
···9999 });
100100 }
101101102102+ function initBackfill() {
103103+ var $button = $("#wireservice-backfill-start");
104104+ var $progress = $("#wireservice-backfill-progress");
105105+ var $fill = $progress.find(".wireservice-progress-bar-fill");
106106+ var $status = $("#wireservice-backfill-status");
107107+ var $results = $("#wireservice-backfill-results");
108108+ var batchSize = 5;
109109+110110+ if (!$button.length) {
111111+ return;
112112+ }
113113+114114+ $button.on("click", function () {
115115+ $button.prop("disabled", true);
116116+ $progress.show();
117117+ $results.hide().empty();
118118+ $fill.css("width", "0%");
119119+ $status.text("Counting posts...");
120120+121121+ $.post(wireserviceBackfill.ajaxUrl, {
122122+ action: "wireservice_backfill_count",
123123+ nonce: wireserviceBackfill.nonce,
124124+ })
125125+ .done(function (response) {
126126+ if (!response.success) {
127127+ $status.text("Failed to count posts.");
128128+ $button.prop("disabled", false);
129129+ return;
130130+ }
131131+132132+ var postIds = response.data.post_ids;
133133+ var total = postIds.length;
134134+135135+ if (total === 0) {
136136+ $status.text("All posts are already synced.");
137137+ $progress.hide();
138138+ $button.prop("disabled", false);
139139+ return;
140140+ }
141141+142142+ var processed = 0;
143143+ var succeeded = 0;
144144+ var errors = [];
145145+146146+ // Chunk post IDs into batches.
147147+ var batches = [];
148148+ for (var i = 0; i < postIds.length; i += batchSize) {
149149+ batches.push(postIds.slice(i, i + batchSize));
150150+ }
151151+152152+ function processBatch(index) {
153153+ if (index >= batches.length) {
154154+ // Done.
155155+ var pct = "100%";
156156+ $fill.css("width", pct);
157157+158158+ var summary = succeeded + " of " + total + " posts synced.";
159159+ $status.text(summary);
160160+161161+ if (errors.length > 0) {
162162+ var html =
163163+ '<details class="wireservice-backfill-errors"><summary>' +
164164+ errors.length +
165165+ " failed</summary><ul>";
166166+ for (var e = 0; e < errors.length; e++) {
167167+ html +=
168168+ "<li><strong>" +
169169+ $("<span>").text(errors[e].title).html() +
170170+ "</strong>: " +
171171+ $("<span>").text(errors[e].error).html() +
172172+ "</li>";
173173+ }
174174+ html += "</ul></details>";
175175+ $results.html(html).show();
176176+ }
177177+178178+ $button.prop("disabled", false);
179179+ return;
180180+ }
181181+182182+ $status.text(
183183+ "Syncing posts... (" + processed + " of " + total + ")"
184184+ );
185185+186186+ $.post(wireserviceBackfill.ajaxUrl, {
187187+ action: "wireservice_backfill_batch",
188188+ nonce: wireserviceBackfill.nonce,
189189+ post_ids: batches[index],
190190+ })
191191+ .done(function (response) {
192192+ if (response.success && response.data.results) {
193193+ for (var r = 0; r < response.data.results.length; r++) {
194194+ var result = response.data.results[r];
195195+ processed++;
196196+ if (result.success) {
197197+ succeeded++;
198198+ } else {
199199+ errors.push(result);
200200+ }
201201+ }
202202+ } else {
203203+ // Count the entire batch as failed.
204204+ processed += batches[index].length;
205205+ for (var f = 0; f < batches[index].length; f++) {
206206+ errors.push({
207207+ title: "Post #" + batches[index][f],
208208+ error: "Batch request failed.",
209209+ });
210210+ }
211211+ }
212212+213213+ var pct = Math.round((processed / total) * 100) + "%";
214214+ $fill.css("width", pct);
215215+216216+ processBatch(index + 1);
217217+ })
218218+ .fail(function () {
219219+ processed += batches[index].length;
220220+ for (var f = 0; f < batches[index].length; f++) {
221221+ errors.push({
222222+ title: "Post #" + batches[index][f],
223223+ error: "Request failed.",
224224+ });
225225+ }
226226+227227+ var pct = Math.round((processed / total) * 100) + "%";
228228+ $fill.css("width", pct);
229229+230230+ processBatch(index + 1);
231231+ });
232232+ }
233233+234234+ processBatch(0);
235235+ })
236236+ .fail(function () {
237237+ $status.text("Failed to start backfill.");
238238+ $button.prop("disabled", false);
239239+ });
240240+ });
241241+ }
242242+102243 $(document).ready(function () {
103244 toggleCustomField(
104245 "wireservice_pub_name_source",
···116257117258 // Initialize color pickers.
118259 $(".wireservice-color-picker").wpColorPicker();
260260+261261+ // Initialize backfill.
262262+ initBackfill();
119263 });
120264})(jQuery);