@chrisburnell/eleventy-cache-webmentions 2.1.7 → 2.1.9-beta.1
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":1726308110099,"type":"2"},"json"]
|
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
const fetch = require("node-fetch");
|
|
2
2
|
const sanitizeHTML = require("sanitize-html");
|
|
3
|
-
const uniqBy = require("lodash.uniqby");
|
|
4
3
|
const { AssetCache } = require("@11ty/eleventy-fetch");
|
|
5
4
|
const chalk = require("chalk");
|
|
6
5
|
|
|
6
|
+
const defaults = {
|
|
7
|
+
refresh: false,
|
|
8
|
+
duration: "1d",
|
|
9
|
+
uniqueKey: "webmentions",
|
|
10
|
+
allowedHTML: {
|
|
11
|
+
allowedTags: ["b", "i", "em", "strong", "a"],
|
|
12
|
+
allowedAttributes: {
|
|
13
|
+
a: ["href"],
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
allowlist: [],
|
|
17
|
+
blocklist: [],
|
|
18
|
+
urlReplacements: {},
|
|
19
|
+
maximumHtmlLength: 1000,
|
|
20
|
+
maximumHtmlText: "mentioned this in",
|
|
21
|
+
};
|
|
22
|
+
|
|
7
23
|
const absoluteURL = (url, domain) => {
|
|
8
24
|
try {
|
|
9
25
|
return new URL(url, domain).toString();
|
|
@@ -118,21 +134,53 @@ const getByTypes = (webmentions, allowedTypes) => {
|
|
|
118
134
|
});
|
|
119
135
|
};
|
|
120
136
|
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
137
|
+
const removeDuplicates = (webmentions) => {
|
|
138
|
+
return [
|
|
139
|
+
...webmentions
|
|
140
|
+
.reduce((map, webmention) => {
|
|
141
|
+
const key =
|
|
142
|
+
webmention === null || webmention === undefined
|
|
143
|
+
? webmention
|
|
144
|
+
: getSource(webmention);
|
|
145
|
+
if (!map.has(key)) {
|
|
146
|
+
map.set(key, webmention);
|
|
147
|
+
}
|
|
148
|
+
return map;
|
|
149
|
+
}, new Map())
|
|
150
|
+
.values(),
|
|
151
|
+
];
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const processBlocklist = (webmentions, blocklist) => {
|
|
155
|
+
return webmentions.filter((webmention) => {
|
|
156
|
+
let url = getSource(webmention);
|
|
157
|
+
let source = getSource(webmention);
|
|
158
|
+
for (let blocklistURL of blocklist) {
|
|
159
|
+
if (
|
|
160
|
+
url.includes(blocklistURL.replace(/\/?$/, "/")) ||
|
|
161
|
+
source.includes(blocklistURL.replace(/\/?$/, "/"))
|
|
162
|
+
) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return true;
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const processAllowlist = (webmentions, allowlist) => {
|
|
171
|
+
return webmentions.filter((webmention) => {
|
|
172
|
+
let url = getSource(webmention);
|
|
173
|
+
let source = getSource(webmention);
|
|
174
|
+
for (let allowlistURL of allowlist) {
|
|
175
|
+
if (
|
|
176
|
+
url.includes(allowlistURL.replace(/\/?$/, "/")) ||
|
|
177
|
+
source.includes(allowlistURL.replace(/\/?$/, "/"))
|
|
178
|
+
) {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return false;
|
|
183
|
+
});
|
|
136
184
|
};
|
|
137
185
|
|
|
138
186
|
const performFetch = async (options, webmentions, url) => {
|
|
@@ -158,43 +206,14 @@ const performFetch = async (options, webmentions, url) => {
|
|
|
158
206
|
// Combine newly-fetched Webmentions with cached Webmentions
|
|
159
207
|
webmentions = feed[options.key].concat(webmentions);
|
|
160
208
|
// Remove duplicates by source URL
|
|
161
|
-
webmentions =
|
|
162
|
-
[...feed[options.key], ...webmentions],
|
|
163
|
-
(webmention) => {
|
|
164
|
-
return getSource(webmention);
|
|
165
|
-
},
|
|
166
|
-
);
|
|
209
|
+
webmentions = removeDuplicates(webmentions);
|
|
167
210
|
// Process the blocklist, if it has any entries
|
|
168
211
|
if (options.blocklist.length) {
|
|
169
|
-
webmentions = webmentions.
|
|
170
|
-
let url = getSource(webmention);
|
|
171
|
-
let source = getSource(webmention);
|
|
172
|
-
for (let blocklistURL of options.blocklist) {
|
|
173
|
-
if (
|
|
174
|
-
url.includes(blocklistURL.replace(/\/?$/, "/")) ||
|
|
175
|
-
source.includes(blocklistURL.replace(/\/?$/, "/"))
|
|
176
|
-
) {
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return true;
|
|
181
|
-
});
|
|
212
|
+
webmentions = processBlocklist(webmentions, options.blocklist);
|
|
182
213
|
}
|
|
183
214
|
// Process the allowlist, if it has any entries
|
|
184
215
|
if (options.allowlist.length) {
|
|
185
|
-
webmentions = webmentions.
|
|
186
|
-
let url = getSource(webmention);
|
|
187
|
-
let source = getSource(webmention);
|
|
188
|
-
for (let allowlistURL of options.allowlist) {
|
|
189
|
-
if (
|
|
190
|
-
url.includes(allowlistURL.replace(/\/?$/, "/")) ||
|
|
191
|
-
source.includes(allowlistURL.replace(/\/?$/, "/"))
|
|
192
|
-
) {
|
|
193
|
-
return true;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return false;
|
|
197
|
-
});
|
|
216
|
+
webmentions = processAllowlist(webmentions, options.allowlist);
|
|
198
217
|
}
|
|
199
218
|
// Sort webmentions by received date for getting most recent Webmention on subsequent requests
|
|
200
219
|
webmentions = webmentions.sort((a, b) => {
|
|
@@ -314,6 +333,16 @@ const fetchWebmentions = async (options) => {
|
|
|
314
333
|
webmentions = fetched.filtered;
|
|
315
334
|
}
|
|
316
335
|
|
|
336
|
+
// Process the blocklist, if it has any entries
|
|
337
|
+
if (options.blocklist.length) {
|
|
338
|
+
webmentions = processBlocklist(webmentions, options.blocklist);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// Process the allowlist, if it has any entries
|
|
342
|
+
if (options.allowlist.length) {
|
|
343
|
+
webmentions = processAllowlist(webmentions, options.allowlist);
|
|
344
|
+
}
|
|
345
|
+
|
|
317
346
|
await asset.save(webmentions, "json");
|
|
318
347
|
|
|
319
348
|
const performance = process.hrtime(performanceStart);
|
|
@@ -324,7 +353,8 @@ const fetchWebmentions = async (options) => {
|
|
|
324
353
|
`${chalk.grey(`[${hostname(options.domain)}]`)} ${chalk.bold(
|
|
325
354
|
webmentions.length - webmentionsCachedLength,
|
|
326
355
|
)} new Webmentions fetched into cache in ${chalk.bold(
|
|
327
|
-
(performance[0] + performance[1] / 1e9).toFixed(3) +
|
|
356
|
+
(performance[0] + performance[1] / 1e9).toFixed(3) +
|
|
357
|
+
" seconds",
|
|
328
358
|
)}.`,
|
|
329
359
|
);
|
|
330
360
|
}
|
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.9-beta.1",
|
|
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": {
|
|
@@ -53,7 +53,6 @@
|
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@11ty/eleventy-fetch": "^4.0.1",
|
|
55
55
|
"chalk": "^4.1.2",
|
|
56
|
-
"lodash.uniqby": "^4.7.0",
|
|
57
56
|
"node-fetch": "2.6.7",
|
|
58
57
|
"sanitize-html": "^2.13.0"
|
|
59
58
|
},
|