@chrisburnell/eleventy-cache-webmentions 2.3.3 → 2.3.5
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/package.json +1 -1
- package/src/core.cjs +41 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrisburnell/eleventy-cache-webmentions",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.5",
|
|
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": {
|
package/src/core.cjs
CHANGED
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* @property {{[key: string]: string}} urlReplacements
|
|
17
17
|
* @property {number} maximumHtmlLength
|
|
18
18
|
* @property {string} maximumHtmlText
|
|
19
|
+
* @property {boolean} paginate
|
|
19
20
|
*/
|
|
20
21
|
|
|
21
22
|
/**
|
|
@@ -39,6 +40,7 @@
|
|
|
39
40
|
* @property {object} [content]
|
|
40
41
|
* @property {string} [content.html]
|
|
41
42
|
* @property {string} [content.value]
|
|
43
|
+
* @property {string} [content.text]
|
|
42
44
|
* @property {object} [data]
|
|
43
45
|
* @property {string} [data.title]
|
|
44
46
|
* @property {string} [data.url]
|
|
@@ -74,7 +76,6 @@ module.exports = ({ AssetCache, styleText, sanitizeHTML }) => {
|
|
|
74
76
|
refresh: false,
|
|
75
77
|
duration: "1d",
|
|
76
78
|
uniqueKey: "webmentions",
|
|
77
|
-
cacheDirectory: undefined,
|
|
78
79
|
allowedHTML: {
|
|
79
80
|
allowedTags: ["a", "b", "em", "i", "strong"],
|
|
80
81
|
allowedAttributes: {
|
|
@@ -86,6 +87,7 @@ module.exports = ({ AssetCache, styleText, sanitizeHTML }) => {
|
|
|
86
87
|
urlReplacements: {},
|
|
87
88
|
maximumHtmlLength: 1000,
|
|
88
89
|
maximumHtmlText: "mentioned this in",
|
|
90
|
+
paginate: false,
|
|
89
91
|
};
|
|
90
92
|
|
|
91
93
|
/**
|
|
@@ -211,7 +213,8 @@ module.exports = ({ AssetCache, styleText, sanitizeHTML }) => {
|
|
|
211
213
|
webmention?.["contentSanitized"] ||
|
|
212
214
|
webmention?.["content"]?.["html"] ||
|
|
213
215
|
webmention?.["content"]?.["value"] ||
|
|
214
|
-
webmention?.["content"] ||
|
|
216
|
+
webmention?.["content"]?.["text"] ||
|
|
217
|
+
(typeof webmention?.["content"] === "string" && webmention["content"]) ||
|
|
215
218
|
webmention?.["data"]?.["content"] ||
|
|
216
219
|
""
|
|
217
220
|
);
|
|
@@ -542,34 +545,52 @@ module.exports = ({ AssetCache, styleText, sanitizeHTML }) => {
|
|
|
542
545
|
return webmentions;
|
|
543
546
|
};
|
|
544
547
|
|
|
548
|
+
const webmentionsByURLCache = new Map();
|
|
549
|
+
|
|
545
550
|
/**
|
|
546
551
|
* @param {Options} options
|
|
547
552
|
* @returns {Promise<{[key: string]: Array<Webmention>}>}
|
|
548
553
|
*/
|
|
549
554
|
const webmentionsByURL = async (options) => {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
555
|
+
const cacheKey = JSON.stringify([
|
|
556
|
+
options.domain,
|
|
557
|
+
options.feed,
|
|
558
|
+
options.key,
|
|
559
|
+
options.uniqueKey,
|
|
560
|
+
options.refresh,
|
|
561
|
+
]);
|
|
562
|
+
|
|
563
|
+
if (webmentionsByURLCache.has(cacheKey)) {
|
|
564
|
+
return webmentionsByURLCache.get(cacheKey);
|
|
565
|
+
}
|
|
560
566
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
567
|
+
const promise = retrieveWebmentions(options).then((rawWebmentions) => {
|
|
568
|
+
// Fix local URLs based on urlReplacements and sort Webmentions into
|
|
569
|
+
// groups by target base URL
|
|
570
|
+
const webmentions = {};
|
|
571
|
+
rawWebmentions.forEach((webmention) => {
|
|
572
|
+
const target = getTarget(webmention);
|
|
573
|
+
if (!target) {
|
|
574
|
+
return;
|
|
575
|
+
}
|
|
564
576
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
577
|
+
let url = baseURL(
|
|
578
|
+
fixURL(target.replace(/\/?$/, "/"), options.urlReplacements),
|
|
579
|
+
);
|
|
568
580
|
|
|
569
|
-
|
|
581
|
+
if (!webmentions[url]) {
|
|
582
|
+
webmentions[url] = [];
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
webmentions[url].push(webmention);
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
return webmentions;
|
|
570
589
|
});
|
|
571
590
|
|
|
572
|
-
|
|
591
|
+
webmentionsByURLCache.set(cacheKey, promise);
|
|
592
|
+
|
|
593
|
+
return promise;
|
|
573
594
|
};
|
|
574
595
|
const webmentionsByUrl = webmentionsByURL;
|
|
575
596
|
const filteredWebmentions = webmentionsByURL;
|