@chrisburnell/eleventy-cache-webmentions 2.3.3 → 2.3.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/core.cjs +38 -19
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrisburnell/eleventy-cache-webmentions",
3
- "version": "2.3.3",
3
+ "version": "2.3.4",
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
  /**
@@ -74,7 +75,6 @@ module.exports = ({ AssetCache, styleText, sanitizeHTML }) => {
74
75
  refresh: false,
75
76
  duration: "1d",
76
77
  uniqueKey: "webmentions",
77
- cacheDirectory: undefined,
78
78
  allowedHTML: {
79
79
  allowedTags: ["a", "b", "em", "i", "strong"],
80
80
  allowedAttributes: {
@@ -86,6 +86,7 @@ module.exports = ({ AssetCache, styleText, sanitizeHTML }) => {
86
86
  urlReplacements: {},
87
87
  maximumHtmlLength: 1000,
88
88
  maximumHtmlText: "mentioned this in",
89
+ paginate: false,
89
90
  };
90
91
 
91
92
  /**
@@ -542,34 +543,52 @@ module.exports = ({ AssetCache, styleText, sanitizeHTML }) => {
542
543
  return webmentions;
543
544
  };
544
545
 
546
+ const webmentionsByURLCache = new Map();
547
+
545
548
  /**
546
549
  * @param {Options} options
547
550
  * @returns {Promise<{[key: string]: Array<Webmention>}>}
548
551
  */
549
552
  const webmentionsByURL = async (options) => {
550
- let rawWebmentions = await retrieveWebmentions(options);
551
-
552
- // Fix local URLs based on urlReplacements and sort Webmentions into groups
553
- // by target base URL
554
- const webmentions = {};
555
- rawWebmentions.forEach((webmention) => {
556
- const target = getTarget(webmention);
557
- if (!target) {
558
- return;
559
- }
553
+ const cacheKey = JSON.stringify([
554
+ options.domain,
555
+ options.feed,
556
+ options.key,
557
+ options.uniqueKey,
558
+ options.refresh,
559
+ ]);
560
+
561
+ if (webmentionsByURLCache.has(cacheKey)) {
562
+ return webmentionsByURLCache.get(cacheKey);
563
+ }
560
564
 
561
- let url = baseURL(
562
- fixURL(target.replace(/\/?$/, "/"), options.urlReplacements),
563
- );
565
+ const promise = retrieveWebmentions(options).then((rawWebmentions) => {
566
+ // Fix local URLs based on urlReplacements and sort Webmentions into
567
+ // groups by target base URL
568
+ const webmentions = {};
569
+ rawWebmentions.forEach((webmention) => {
570
+ const target = getTarget(webmention);
571
+ if (!target) {
572
+ return;
573
+ }
564
574
 
565
- if (!webmentions[url]) {
566
- webmentions[url] = [];
567
- }
575
+ let url = baseURL(
576
+ fixURL(target.replace(/\/?$/, "/"), options.urlReplacements),
577
+ );
568
578
 
569
- webmentions[url].push(webmention);
579
+ if (!webmentions[url]) {
580
+ webmentions[url] = [];
581
+ }
582
+
583
+ webmentions[url].push(webmention);
584
+ });
585
+
586
+ return webmentions;
570
587
  });
571
588
 
572
- return webmentions;
589
+ webmentionsByURLCache.set(cacheKey, promise);
590
+
591
+ return promise;
573
592
  };
574
593
  const webmentionsByUrl = webmentionsByURL;
575
594
  const filteredWebmentions = webmentionsByURL;