@rmdes/indiekit-endpoint-syndicate 1.0.0-beta.42 → 1.0.0-beta.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/controllers/syndicate.js +4 -2
- package/lib/utils.js +10 -8
- package/package.json +1 -1
|
@@ -239,14 +239,16 @@ export const syndicateController = {
|
|
|
239
239
|
`[syndication] Syndicated: ${result.url} (${result.syndicatedUrls.length} target(s))`,
|
|
240
240
|
);
|
|
241
241
|
} catch (error) {
|
|
242
|
+
const message =
|
|
243
|
+
error instanceof Error ? error.message : String(error);
|
|
242
244
|
results.push({
|
|
243
245
|
url: postData.properties?.url,
|
|
244
246
|
success: false,
|
|
245
|
-
error:
|
|
247
|
+
error: message,
|
|
246
248
|
});
|
|
247
249
|
|
|
248
250
|
console.error(
|
|
249
|
-
`[syndication] Failed: ${postData.properties?.url} - ${
|
|
251
|
+
`[syndication] Failed: ${postData.properties?.url} - ${message}`,
|
|
250
252
|
);
|
|
251
253
|
}
|
|
252
254
|
|
package/lib/utils.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Get post data for a single post
|
|
3
3
|
* @param {object} postsCollection - Posts database collection
|
|
4
4
|
* @param {string} url - URL of existing post (optional)
|
|
5
|
-
* @returns {Promise<object>} Post data for given URL else
|
|
5
|
+
* @returns {Promise<object>} Post data for given URL else oldest post awaiting syndication
|
|
6
6
|
*/
|
|
7
7
|
export const getPostData = async (postsCollection, url) => {
|
|
8
8
|
if (url) {
|
|
@@ -15,7 +15,8 @@ export const getPostData = async (postsCollection, url) => {
|
|
|
15
15
|
// deleted once every target has returned a URL, and replaced with the
|
|
16
16
|
// targets that failed otherwise. Posts already syndicated to some of their
|
|
17
17
|
// targets are therefore still awaiting the rest, and `syndicateToTargets`
|
|
18
|
-
// skips the ones already done.
|
|
18
|
+
// skips the ones already done. Oldest first, so a backlog is syndicated in
|
|
19
|
+
// the order it was published.
|
|
19
20
|
const items = await postsCollection
|
|
20
21
|
.find({
|
|
21
22
|
"properties.mp-syndicate-to": {
|
|
@@ -25,7 +26,7 @@ export const getPostData = async (postsCollection, url) => {
|
|
|
25
26
|
$ne: "draft",
|
|
26
27
|
},
|
|
27
28
|
})
|
|
28
|
-
.sort({ "properties.published":
|
|
29
|
+
.sort({ "properties.published": 1 })
|
|
29
30
|
.limit(1)
|
|
30
31
|
.toArray();
|
|
31
32
|
|
|
@@ -63,12 +64,13 @@ export const getAllPostData = async (postsCollection) => {
|
|
|
63
64
|
*/
|
|
64
65
|
export const hasSyndicationUrl = (syndicatedUrls, syndicateTo) => {
|
|
65
66
|
return syndicatedUrls.some((url) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return syndicateTo.includes(origin);
|
|
69
|
-
} catch {
|
|
67
|
+
// `syndication` is stored as given, so may hold values that aren’t URLs
|
|
68
|
+
if (!URL.canParse(url)) {
|
|
70
69
|
return false;
|
|
71
70
|
}
|
|
71
|
+
|
|
72
|
+
const { origin } = new URL(url);
|
|
73
|
+
return syndicateTo.includes(origin);
|
|
72
74
|
});
|
|
73
75
|
};
|
|
74
76
|
|
|
@@ -208,7 +210,7 @@ export const syndicateToTargets = async (
|
|
|
208
210
|
} catch (error) {
|
|
209
211
|
// Add failed syndication target to list of failed targets
|
|
210
212
|
failedTargets.push(target.info.uid);
|
|
211
|
-
console.error(error
|
|
213
|
+
console.error(error);
|
|
212
214
|
}
|
|
213
215
|
}
|
|
214
216
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rmdes/indiekit-endpoint-syndicate",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.44",
|
|
4
4
|
"description": "Syndication endpoint for Indiekit. Fork of @indiekit/endpoint-syndicate with batch syndication support and bug fixes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"indiekit",
|