@chrisburnell/eleventy-cache-webmentions 2.1.6 → 2.1.7
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"68a403136c61abd104ade94e69ba62":"1"},{"cachedAt":
|
|
1
|
+
[{"68a403136c61abd104ade94e69ba62":"1"},{"cachedAt":1723704454029,"type":"2"},"json"]
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
const fetch = require("node-fetch");
|
|
2
2
|
const sanitizeHTML = require("sanitize-html");
|
|
3
|
-
const uniqBy = require("lodash
|
|
3
|
+
const uniqBy = require("lodash.uniqby");
|
|
4
4
|
const { AssetCache } = require("@11ty/eleventy-fetch");
|
|
5
|
+
const chalk = require("chalk");
|
|
5
6
|
|
|
6
7
|
const absoluteURL = (url, domain) => {
|
|
7
8
|
try {
|
|
8
9
|
return new URL(url, domain).toString();
|
|
9
10
|
} catch (e) {
|
|
10
|
-
console.
|
|
11
|
-
`Trying to convert ${
|
|
11
|
+
console.error(
|
|
12
|
+
`Trying to convert ${chalk.bold(
|
|
13
|
+
url,
|
|
14
|
+
)} to be an absolute url with base ${chalk.bold(
|
|
15
|
+
domain,
|
|
16
|
+
)} and failed.`,
|
|
12
17
|
);
|
|
13
18
|
return url;
|
|
14
19
|
}
|
|
@@ -141,10 +146,10 @@ const performFetch = async (options, webmentions, url) => {
|
|
|
141
146
|
|
|
142
147
|
if (!options.key in feed) {
|
|
143
148
|
console.log(
|
|
144
|
-
`[${hostname(options.domain)}] ${
|
|
149
|
+
`${chalk.grey(`[${hostname(options.domain)}]`)} ${
|
|
145
150
|
options.key
|
|
146
|
-
} was not found as a key in the response from ${
|
|
147
|
-
options.feed,
|
|
151
|
+
} was not found as a key in the response from ${chalkf.bold(
|
|
152
|
+
hostname(options.feed),
|
|
148
153
|
)}!`,
|
|
149
154
|
);
|
|
150
155
|
return Promise.reject(response);
|
|
@@ -203,10 +208,10 @@ const performFetch = async (options, webmentions, url) => {
|
|
|
203
208
|
})
|
|
204
209
|
.catch((error) => {
|
|
205
210
|
console.log(
|
|
206
|
-
|
|
207
|
-
options.domain
|
|
208
|
-
)}
|
|
209
|
-
options.feed,
|
|
211
|
+
`${chalk.grey(
|
|
212
|
+
`[${hostname(options.domain)}]`,
|
|
213
|
+
)} Something went wrong with your request to ${chalk.bold(
|
|
214
|
+
hostname(options.feed),
|
|
210
215
|
)}!`,
|
|
211
216
|
error,
|
|
212
217
|
);
|
|
@@ -232,7 +237,10 @@ const fetchWebmentions = async (options) => {
|
|
|
232
237
|
);
|
|
233
238
|
}
|
|
234
239
|
|
|
235
|
-
let asset = new AssetCache(
|
|
240
|
+
let asset = new AssetCache(
|
|
241
|
+
options.uniqueKey || `webmentions-${hostname(options.domain)}`,
|
|
242
|
+
options.directory,
|
|
243
|
+
);
|
|
236
244
|
asset.ensureDir();
|
|
237
245
|
|
|
238
246
|
let webmentions = [];
|
|
@@ -250,6 +258,7 @@ const fetchWebmentions = async (options) => {
|
|
|
250
258
|
// If there is a cached file but it is outside of expiry, fetch fresh
|
|
251
259
|
// results since the most recent Webmention
|
|
252
260
|
if (!asset.isCacheValid(options.refresh ? "0s" : options.duration)) {
|
|
261
|
+
const performanceStart = process.hrtime();
|
|
253
262
|
// Get the received date of the most recent Webmention, if it exists
|
|
254
263
|
const since = webmentions.length ? getReceived(webmentions[0]) : false;
|
|
255
264
|
// Build the URL for the fetch request
|
|
@@ -307,12 +316,16 @@ const fetchWebmentions = async (options) => {
|
|
|
307
316
|
|
|
308
317
|
await asset.save(webmentions, "json");
|
|
309
318
|
|
|
319
|
+
const performance = process.hrtime(performanceStart);
|
|
320
|
+
|
|
310
321
|
// Add a console message with the number of fetched and processed Webmentions, if any
|
|
311
322
|
if (webmentionsCachedLength < webmentions.length) {
|
|
312
323
|
console.log(
|
|
313
|
-
`[${hostname(options.domain)}] ${
|
|
314
|
-
webmentions.length - webmentionsCachedLength
|
|
315
|
-
} new Webmentions fetched into cache
|
|
324
|
+
`${chalk.grey(`[${hostname(options.domain)}]`)} ${chalk.bold(
|
|
325
|
+
webmentions.length - webmentionsCachedLength,
|
|
326
|
+
)} new Webmentions fetched into cache in ${chalk.bold(
|
|
327
|
+
(performance[0] + performance[1] / 1e9).toFixed(3) + "s",
|
|
328
|
+
)}.`,
|
|
316
329
|
);
|
|
317
330
|
}
|
|
318
331
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrisburnell/eleventy-cache-webmentions",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.7",
|
|
4
4
|
"description": "Cache webmentions using eleventy-fetch and make them available to use in collections, layouts, pages, etc. in Eleventy.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
],
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@11ty/eleventy-fetch": "^4.0.1",
|
|
55
|
-
"
|
|
55
|
+
"chalk": "^4.1.2",
|
|
56
|
+
"lodash.uniqby": "^4.7.0",
|
|
56
57
|
"node-fetch": "2.6.7",
|
|
57
58
|
"sanitize-html": "^2.13.0"
|
|
58
59
|
},
|