@chrisburnell/eleventy-cache-webmentions 1.1.4 → 1.1.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/README.md CHANGED
@@ -8,8 +8,8 @@ I wrote a quicker and simpler guide to getting this Eleventy plugin working that
8
8
 
9
9
  ## Installation
10
10
 
11
- - **With npm:** `npm install @chrisburnell/eleventy-cache-webmentions`
12
- - **Direct download:** [https://github.com/chrisburnell/eleventy-cache-webmentions/archive/master.zip](https://github.com/chrisburnell/eleventy-cache-webmentions/archive/master.zip)
11
+ - **With npm:** `npm install @chrisburnell/eleventy-cache-webmentions`
12
+ - **Direct download:** [https://github.com/chrisburnell/eleventy-cache-webmentions/archive/master.zip](https://github.com/chrisburnell/eleventy-cache-webmentions/archive/master.zip)
13
13
 
14
14
  Once installed there are **two** more **required** set-up steps:
15
15
 
@@ -21,12 +21,12 @@ Inside your Eleventy config file (typically `.eleventy.js`), use `addPlugin`:
21
21
  const pluginWebmentions = require("@chrisburnell/eleventy-cache-webmentions")
22
22
 
23
23
  module.exports = function (eleventyConfig) {
24
- eleventyConfig.addPlugin(pluginWebmentions, {
25
- // these 3 fields are all required!
26
- domain: "https://example.com",
27
- feed: "https://webmentions.example.com?token=S3cr3tT0k3n",
28
- key: "children",
29
- })
24
+ eleventyConfig.addPlugin(pluginWebmentions, {
25
+ // these 3 fields are all required!
26
+ domain: "https://example.com",
27
+ feed: "https://webmentions.example.com?token=S3cr3tT0k3n",
28
+ key: "children",
29
+ })
30
30
  }
31
31
  ```
32
32
 
@@ -38,51 +38,51 @@ Advanced control over how the Webmentions are cached and processed is done by pa
38
38
  const pluginWebmentions = require("@chrisburnell/eleventy-cache-webmentions")
39
39
 
40
40
  module.exports = function (eleventyConfig) {
41
- eleventyConfig.addPlugin(pluginWebmentions, {
42
- // domain: required or the plugin will not function
43
- // this is the website that you want to pull in Webmentions for
44
- domain: "https://example.com",
45
- // feed: required or the plugin will not function
46
- // defines the URL of your Webmention server where a feed of Webmentions for your domain can be found
47
- feed: "https://webmentions.example.com?token=S3cr3tT0k3n",
48
- // key: required or the plugin will not function
49
- // dictates the key inside the feed where the array of Webmentions is located
50
- key: "children",
51
- // directory: ".cache" by default
52
- // see https://www.11ty.dev/docs/plugins/cache/#cache-directory for more info
53
- directory: ".cache",
54
- // duration: "1d" by default
55
- // see https://www.11ty.dev/docs/plugins/cache/#change-the-cache-duration for more info
56
- duration: "1d",
57
- // uniquekey: "webmentions" by default
58
- // dictates the name sent to eleventy-fetch to name the file
59
- uniqueKey: "webmentions",
60
- // allowedHTML: Object by default
61
- // see https://www.npmjs.com/package/sanitize-html for more info
62
- allowedHTML: {
63
- allowedTags: ["b", "i", "em", "strong", "a"],
64
- allowedAttributes: {
65
- a: ["href"],
66
- },
67
- },
68
- // allowlist: [] by default
69
- // array of root URLs from which webmentions are wanted exclusively
70
- allowlist: [],
71
- // blocklist: [] by default
72
- // array of root URLs from which webmentions are not wanted
73
- // exclusively
74
- blocklist: [],
75
- // urlReplacements: {} by default
76
- // object of key:value pairs containing from:to URL replacements
77
- urlReplacements: {},
78
- // maximumHtmlLength: 2000 by default
79
- // number of characters in the HTML content at which a different
80
- // message is shown instead of the content
81
- maximumHtmlLength: 2000,
82
- // maximumHtmlText: "mentioned this in" by default
83
- // message shown when maximumHtmlLength is reached
84
- maximumHtmlText: "mentioned this in",
85
- })
41
+ eleventyConfig.addPlugin(pluginWebmentions, {
42
+ // domain: required or the plugin will not function
43
+ // this is the website that you want to pull in Webmentions for
44
+ domain: "https://example.com",
45
+ // feed: required or the plugin will not function
46
+ // defines the URL of your Webmention server where a feed of Webmentions for your domain can be found
47
+ feed: "https://webmentions.example.com?token=S3cr3tT0k3n",
48
+ // key: required or the plugin will not function
49
+ // dictates the key inside the feed where the array of Webmentions is located
50
+ key: "children",
51
+ // directory: ".cache" by default
52
+ // see https://www.11ty.dev/docs/plugins/cache/#cache-directory for more info
53
+ directory: ".cache",
54
+ // duration: "1d" by default
55
+ // see https://www.11ty.dev/docs/plugins/cache/#change-the-cache-duration for more info
56
+ duration: "1d",
57
+ // uniquekey: "webmentions" by default
58
+ // dictates the name sent to eleventy-fetch to name the file
59
+ uniqueKey: "webmentions",
60
+ // allowedHTML: Object by default
61
+ // see https://www.npmjs.com/package/sanitize-html for more info
62
+ allowedHTML: {
63
+ allowedTags: ["b", "i", "em", "strong", "a"],
64
+ allowedAttributes: {
65
+ a: ["href"],
66
+ },
67
+ },
68
+ // allowlist: [] by default
69
+ // array of root URLs from which webmentions are wanted exclusively
70
+ allowlist: [],
71
+ // blocklist: [] by default
72
+ // array of root URLs from which webmentions are not wanted
73
+ // exclusively
74
+ blocklist: [],
75
+ // urlReplacements: {} by default
76
+ // object of key:value pairs containing from:to URL replacements
77
+ urlReplacements: {},
78
+ // maximumHtmlLength: 2000 by default
79
+ // number of characters in the HTML content at which a different
80
+ // message is shown instead of the content
81
+ maximumHtmlLength: 2000,
82
+ // maximumHtmlText: "mentioned this in" by default
83
+ // message shown when maximumHtmlLength is reached
84
+ maximumHtmlText: "mentioned this in",
85
+ })
86
86
  }
87
87
  ```
88
88
 
@@ -92,9 +92,9 @@ Accessing the plugin in JavaScript in the way shown below will give you an Objec
92
92
 
93
93
  ```javascript
94
94
  const Webmentions = require("@chrisburnell/eleventy-cache-webmentions")(null, {
95
- domain: "https://example.com",
96
- feed: "https://webmentions.example.com?token=S3cr3tT0k3n",
97
- key: "children",
95
+ domain: "https://example.com",
96
+ feed: "https://webmentions.example.com?token=S3cr3tT0k3n",
97
+ key: "children",
98
98
  })
99
99
 
100
100
  const webmentionsByUrl = await Webmentions()
@@ -104,28 +104,28 @@ This can prove to be very useful when building out your pages. Using [Eleventy
104
104
 
105
105
  ```javascript
106
106
  const Webmentions = require("@chrisburnell/eleventy-cache-webmentions")(null, {
107
- domain: "https://example.com",
108
- feed: "https://webmentions.example.com?token=S3cr3tT0k3n",
109
- key: "children",
107
+ domain: "https://example.com",
108
+ feed: "https://webmentions.example.com?token=S3cr3tT0k3n",
109
+ key: "children",
110
110
  })
111
111
 
112
112
  module.exports = async () => {
113
- const webmentionsByUrl = await Webmentions()
114
-
115
- return {
116
- eleventyComputed: {
117
- webmentions: (data) => {
118
- const webmentionsForUrl = webmentionsByUrl["https://example.com" + data.page.url] || []
119
-
120
- if (webmentionsForUrl.length) {
121
- return webmentionsForUrl.sort((a, b) => {
122
- return (b.data.published || b.verified_date) - (a.data.published || a.verified_date)
123
- })
124
- }
125
- return []
126
- },
127
- },
128
- }
113
+ const webmentionsByUrl = await Webmentions()
114
+
115
+ return {
116
+ eleventyComputed: {
117
+ webmentions: (data) => {
118
+ const webmentionsForUrl = webmentionsByUrl["https://example.com" + data.page.url] || []
119
+
120
+ if (webmentionsForUrl.length) {
121
+ return webmentionsForUrl.sort((a, b) => {
122
+ return (b.data.published || b.verified_date) - (a.data.published || a.verified_date)
123
+ })
124
+ }
125
+ return []
126
+ },
127
+ },
128
+ }
129
129
  }
130
130
  ```
131
131
 
@@ -133,11 +133,11 @@ You can now use this data in a number of useful ways, not limited to things like
133
133
 
134
134
  ```javascript
135
135
  module.exports = (eleventyConfig) => {
136
- eleventyConfig.addCollection("popular", (collection) => {
137
- return collection.sort((a, b) => {
138
- return b.data.webmentions.length - a.data.webmentions.length
139
- })
140
- })
136
+ eleventyConfig.addCollection("popular", (collection) => {
137
+ return collection.sort((a, b) => {
138
+ return b.data.webmentions.length - a.data.webmentions.length
139
+ })
140
+ })
141
141
  }
142
142
  ```
143
143
 
@@ -190,11 +190,11 @@ WEBMENTION_IO_TOKEN=njJql0lKXnotreal4x3Wmd
190
190
  const pluginWebmentions = require("@chrisburnell/eleventy-cache-webmentions")
191
191
 
192
192
  module.exports = function (eleventyConfig) {
193
- eleventyConfig.addPlugin(pluginWebmentions, {
194
- domain: "https://example.com",
195
- feed: `https://webmention.io/api/mentions.jf2?domain=example.com&per-page=9001&token=${process.env.WEBMENTION_IO_TOKEN}`,
196
- key: "children",
197
- })
193
+ eleventyConfig.addPlugin(pluginWebmentions, {
194
+ domain: "https://example.com",
195
+ feed: `https://webmention.io/api/mentions.jf2?domain=example.com&per-page=9001&token=${process.env.WEBMENTION_IO_TOKEN}`,
196
+ key: "children",
197
+ })
198
198
  }
199
199
  ```
200
200
 
@@ -216,11 +216,11 @@ GO_JAMMING_TOKEN=njJql0lKXnotreal4x3Wmd
216
216
  const pluginWebmentions = require("@chrisburnell/eleventy-cache-webmentions")
217
217
 
218
218
  module.exports = function (eleventyConfig) {
219
- eleventyConfig.addPlugin(pluginWebmentions, {
220
- domain: "https://example.com",
221
- feed: `https://jam.example.com/webmention/example.com/${process.env.GO_JAMMING_TOKEN}`,
222
- key: "json",
223
- })
219
+ eleventyConfig.addPlugin(pluginWebmentions, {
220
+ domain: "https://example.com",
221
+ feed: `https://jam.example.com/webmention/example.com/${process.env.GO_JAMMING_TOKEN}`,
222
+ key: "json",
223
+ })
224
224
  }
225
225
  ```
226
226
 
@@ -74,19 +74,19 @@ const defaults = {
74
74
 
75
75
  const fetchWebmentions = async (options) => {
76
76
  if (!options.domain) {
77
- throw new Error("domain is a required field when attempting to retrieve Webmentions. See https://chrisburnell.com/eleventy-cache-webmentions/#installation for more information.")
77
+ throw new Error("domain is a required field when attempting to retrieve Webmentions. See https://www.npmjs.com/package/@chrisburnell/eleventy-cache-webmentions#installation for more information.")
78
78
  }
79
79
 
80
80
  if (!options.feed) {
81
- throw new Error("feed is a required field when attempting to retrieve Webmentions. See https://chrisburnell.com/eleventy-cache-webmentions/#installation for more information.")
81
+ throw new Error("feed is a required field when attempting to retrieve Webmentions. See https://www.npmjs.com/package/@chrisburnell/eleventy-cache-webmentions#installation for more information.")
82
82
  }
83
83
 
84
84
  if (!options.key) {
85
- throw new Error("key is a required field when attempting to retrieve Webmentions. See https://chrisburnell.com/eleventy-cache-webmentions/#installation for more information.")
85
+ throw new Error("key is a required field when attempting to retrieve Webmentions. See https://www.npmjs.com/package/@chrisburnell/eleventy-cache-webmentions#installation for more information.")
86
86
  }
87
87
 
88
88
  if (!options.uniqueKey) {
89
- throw new Error("uniqueKey is a required field when attempting to retrieve Webmentions. See https://chrisburnell.com/eleventy-cache-webmentions/#installation for more information.")
89
+ throw new Error("uniqueKey is a required field when attempting to retrieve Webmentions. See https://www.npmjs.com/package/@chrisburnell/eleventy-cache-webmentions#installation for more information.")
90
90
  }
91
91
 
92
92
  let asset = new AssetCache(options.uniqueKey, options.directory)
@@ -127,9 +127,13 @@ const fetchWebmentions = async (options) => {
127
127
  return webmentions
128
128
  }
129
129
 
130
+ let filtered = {}
130
131
  const filteredWebmentions = async (options) => {
132
+ if (Object.entries(filtered).length) {
133
+ return filtered
134
+ }
135
+
131
136
  let rawWebmentions = await fetchWebmentions(options)
132
- let webmentions = {}
133
137
 
134
138
  // Process the blocklist, if it has any entries
135
139
  if (options.blocklist.length) {
@@ -166,21 +170,22 @@ const filteredWebmentions = async (options) => {
166
170
  rawWebmentions.forEach((webmention) => {
167
171
  let url = baseUrl(fixUrl(getTarget(webmention).replace(/\/?$/, "/"), options.urlReplacements))
168
172
 
169
- if (!webmentions[url]) {
170
- webmentions[url] = []
173
+
174
+ if (!filtered[url]) {
175
+ filtered[url] = []
171
176
  }
172
177
 
173
- webmentions[url].push(webmention)
178
+ filtered[url].push(webmention)
174
179
  })
175
180
 
176
181
  // Remove duplicates by source URL
177
- for (let url in webmentions) {
178
- webmentions[url] = uniqBy(webmentions[url], (entry) => {
182
+ for (let url in filtered) {
183
+ filtered[url] = uniqBy(filtered[url], (entry) => {
179
184
  return getSource(entry)
180
185
  })
181
186
  }
182
187
 
183
- return webmentions
188
+ return filtered
184
189
  }
185
190
 
186
191
  const getWebmentions = async (options, url, allowedTypes = {}) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrisburnell/eleventy-cache-webmentions",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Fetch and cache webmentions using eleventy-fetch.",
5
5
  "author": "Chris Burnell <me@chrisburnell.com>",
6
6
  "license": "MIT",