@chrisburnell/eleventy-cache-webmentions 1.2.6-rc.2 → 2.0.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.
- package/README.md +197 -106
- package/eleventy-cache-webmentions.js +52 -31
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,37 +1,53 @@
|
|
|
1
1
|
# eleventy-cache-webmentions
|
|
2
2
|
|
|
3
|
-
> Cache webmentions using eleventy-fetch and make them available to use in collections,
|
|
3
|
+
> Cache webmentions using eleventy-fetch and make them available to use in collections, layouts, pages, etc. in Eleventy.
|
|
4
|
+
|
|
5
|
+
## Breaking change for v2.0.0
|
|
6
|
+
|
|
7
|
+
Version 2.0.0 introduces a breaking change for those migrating from earlier versions of the plugin. This affects usage of the plugin from JavaScript files; specifically, you will need to make a small change to the way that you `require()` the plugin by removing an extra set of parentheses:
|
|
8
|
+
|
|
9
|
+
**v1.2.5 and below**
|
|
10
|
+
|
|
11
|
+
```javascript
|
|
12
|
+
require("@chrisburnell/eleventy-cache-webmentions")()
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**v2.0.0 and above**
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
require("@chrisburnell/eleventy-cache-webmentions")
|
|
19
|
+
```
|
|
4
20
|
|
|
5
21
|
## Quick Guide
|
|
6
22
|
|
|
7
|
-
I wrote a quicker and simpler guide to getting this Eleventy plugin working that cuts out all the fluff and extra details.
|
|
23
|
+
I wrote a quicker and simpler guide to getting this Eleventy plugin working that cuts out all the fluff and extra details.
|
|
24
|
+
|
|
25
|
+
Check it out: [Webmention Setup for Eleventy](https://chrisburnell.com/article/webmention-eleventy-setup/).
|
|
8
26
|
|
|
9
27
|
## Installation
|
|
10
28
|
|
|
11
29
|
- **With npm:** `npm install @chrisburnell/eleventy-cache-webmentions`
|
|
12
30
|
- **Direct download:** [https://github.com/chrisburnell/eleventy-cache-webmentions/archive/master.zip](https://github.com/chrisburnell/eleventy-cache-webmentions/archive/master.zip)
|
|
13
31
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
### Add it to your config
|
|
17
|
-
|
|
18
|
-
Inside your Eleventy config file (typically `.eleventy.js`), use `addPlugin`:
|
|
32
|
+
Inside your Eleventy config file, use `addPlugin()` to add it to your project:
|
|
19
33
|
|
|
20
34
|
```javascript
|
|
21
35
|
const pluginWebmentions = require("@chrisburnell/eleventy-cache-webmentions")
|
|
22
36
|
|
|
23
|
-
module.exports = function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
module.exports = function(eleventyConfig) {
|
|
38
|
+
eleventyConfig.addPlugin(pluginWebmentions, {
|
|
39
|
+
// These 3 fields are all required!
|
|
40
|
+
domain: "https://example.com",
|
|
41
|
+
feed: "https://webmentions.example.com?token=S3cr3tT0k3n",
|
|
42
|
+
key: "array_of_webmentions"
|
|
43
|
+
})
|
|
30
44
|
}
|
|
31
45
|
```
|
|
32
46
|
|
|
33
|
-
|
|
47
|
+
Make sure you get the correct values for this configuration. Check below for both Webmention.io configuration and go-jamming configuration.
|
|
34
48
|
|
|
49
|
+
<details>
|
|
50
|
+
<summary>Full options list</summary>
|
|
35
51
|
<table>
|
|
36
52
|
<thead>
|
|
37
53
|
<tr>
|
|
@@ -116,124 +132,193 @@ module.exports = function (eleventyConfig) {
|
|
|
116
132
|
</tr>
|
|
117
133
|
</tbody>
|
|
118
134
|
</table>
|
|
135
|
+
</details>
|
|
136
|
+
|
|
137
|
+
## Usage
|
|
138
|
+
|
|
139
|
+
`eleventy-cache-webmentions` comes with a number of ways of accessing your Webmentions as [Global Data](https://www.11ty.dev/docs/data-global-custom/) in both JavaScript and Liquid/Nunjucks as well as a series of [Eleventy Filters](https://www.11ty.dev/docs/filters/) and JavaScript Functions for filtering, sorting, and reading properties about each Webmention:
|
|
119
140
|
|
|
120
|
-
|
|
141
|
+
### Global Data
|
|
142
|
+
|
|
143
|
+
<details>
|
|
144
|
+
<summary>JavaScript</summary>
|
|
121
145
|
|
|
122
146
|
```javascript
|
|
123
|
-
const
|
|
147
|
+
const {
|
|
148
|
+
defaults, // default options for the plugin
|
|
149
|
+
webmentionsByUrl, // Object containing Arrays of Webmentions by URL
|
|
150
|
+
} = require("@chrisburnell/eleventy-cache-webmentions")
|
|
151
|
+
```
|
|
124
152
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
allowedAttributes: {
|
|
136
|
-
a: ["href"],
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
allowlist: [],
|
|
140
|
-
blocklist: [],
|
|
141
|
-
urlReplacements: {},
|
|
142
|
-
maximumHtmlLength: 2000,
|
|
143
|
-
maximumHtmlText: "mentioned this in",
|
|
144
|
-
})
|
|
145
|
-
}
|
|
153
|
+
</details>
|
|
154
|
+
|
|
155
|
+
<details>
|
|
156
|
+
<summary>Liquid / Nunjucks</summary>
|
|
157
|
+
|
|
158
|
+
```twig
|
|
159
|
+
{# default options for the plugin #}
|
|
160
|
+
{{ webmentionsDefaults }}
|
|
161
|
+
{# Object containing Arrays of Webmentions by URL #}
|
|
162
|
+
{{ webmentionsByUrl }}
|
|
146
163
|
```
|
|
147
164
|
|
|
148
|
-
|
|
165
|
+
</details>
|
|
166
|
+
|
|
167
|
+
### Filters
|
|
149
168
|
|
|
150
|
-
|
|
169
|
+
<details>
|
|
170
|
+
<summary>JavaScript</summary>
|
|
151
171
|
|
|
152
172
|
```javascript
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
173
|
+
const {
|
|
174
|
+
getWebmentions, // get Array of Webmentions for a given URL
|
|
175
|
+
getByTypes, // filter Webmentions by their response type
|
|
176
|
+
getPublished, // get received/published time of a Webmention
|
|
177
|
+
getContent, // get content of a Webmention
|
|
178
|
+
getSource, // get source URL of a Webmention (where it's from)
|
|
179
|
+
getTarget, // get target URL of a Webmention (where it's sent to)
|
|
180
|
+
getType, // get response type of a Webmention
|
|
181
|
+
} = require("@chrisburnell/eleventy-cache-webmentions")
|
|
182
|
+
|
|
183
|
+
// This is NOT the best way to get Webmentions!
|
|
184
|
+
// See "Attach Webmentions to Pages using Directory Data" below.
|
|
185
|
+
const webmentions = getWebmentions({
|
|
186
|
+
domain: "https://example.com",
|
|
187
|
+
feed: "https://webmentions.example.com?token=S3cr3tT0k3n",
|
|
188
|
+
key: "array_of_webmentions"
|
|
189
|
+
}, "https://example.com/specific-page/")
|
|
190
|
+
|
|
191
|
+
const responsesOnly = getByTypes(webmentions, ['mention-of', 'in-reply-to'])
|
|
192
|
+
|
|
193
|
+
webmentions.forEach((webmention) => {
|
|
194
|
+
const published = getPublished(webmention)
|
|
195
|
+
const content = getContent(webmention)
|
|
196
|
+
const source = getSource(webmention)
|
|
197
|
+
const target = getTarget(webmention)
|
|
198
|
+
const type = getType(webmention)
|
|
157
199
|
})
|
|
200
|
+
```
|
|
158
201
|
|
|
159
|
-
|
|
202
|
+
</details>
|
|
203
|
+
|
|
204
|
+
<details>
|
|
205
|
+
<summary>Liquid / Nunjucks</summary>
|
|
206
|
+
|
|
207
|
+
```twig
|
|
208
|
+
{# get Array of Webmentions for a given URL #}
|
|
209
|
+
{% set webmentions = ("https://example.com" + page.url) | getWebmentions %}
|
|
210
|
+
|
|
211
|
+
{# filter Webmentions by their response type #}
|
|
212
|
+
{{ set responses = webmentions | getWebmentionsByTypes(['mention-of', 'in-reply-to']) }}
|
|
213
|
+
|
|
214
|
+
{% for webmention in webmentions %}
|
|
215
|
+
{# get received/published time of a Webmention #}
|
|
216
|
+
{{ webmentions | getWebmentionPublished }}
|
|
217
|
+
{# get content of a Webmention #}
|
|
218
|
+
{{ webmentions | getWebmentionContent }}
|
|
219
|
+
{# get source URL of a Webmention (where it's from) #}
|
|
220
|
+
{{ webmentions | getWebmentionSource }}
|
|
221
|
+
{# get target URL of a Webmention (where it's sent to) #}
|
|
222
|
+
{{ webmentions | getWebmentionTarget }}
|
|
223
|
+
{# get response type of a Webmention #}
|
|
224
|
+
{{ webmentions | getWebmentionType }}
|
|
225
|
+
{% endfor %}
|
|
160
226
|
```
|
|
161
227
|
|
|
162
|
-
|
|
228
|
+
</details>
|
|
163
229
|
|
|
164
|
-
|
|
165
|
-
const Webmentions = require("@chrisburnell/eleventy-cache-webmentions")(null, {
|
|
166
|
-
domain: "https://example.com",
|
|
167
|
-
feed: "https://webmentions.example.com?token=S3cr3tT0k3n",
|
|
168
|
-
key: "children",
|
|
169
|
-
})
|
|
230
|
+
## Attach Webmentions to Pages using Directory Data
|
|
170
231
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
232
|
+
Using [Eleventy’s Data Cascade](https://www.11ty.dev/docs/data-cascade/), you can attach Webmentions to each page by using [Directory Specific Data Files](https://www.11ty.dev/docs/data-template-dir/).
|
|
233
|
+
|
|
234
|
+
For example, if you have a folder, `/pages/`, and want to attach Webmentions to each page, create or add the following to a `pages.11tydata.js` file within the folder:
|
|
235
|
+
|
|
236
|
+
```javascript
|
|
237
|
+
const { getWebmentions, getPublished } = require("@chrisburnell/eleventy-cache-webmentions")
|
|
238
|
+
|
|
239
|
+
module.exports = {
|
|
240
|
+
eleventyComputed: {
|
|
241
|
+
webmentions: (data) => {
|
|
242
|
+
// Get this page's Webmentions as an Array (based on the URL)
|
|
243
|
+
const webmentionsForUrl = getWebmentions({
|
|
244
|
+
domain: "https://example.com",
|
|
245
|
+
feed: "https://webmentions.example.com?token=S3cr3tT0k3n",
|
|
246
|
+
key: "array_of_webmentions"
|
|
247
|
+
}, "https://example.com" + data.page.url)
|
|
248
|
+
|
|
249
|
+
// If there are Webmentions for this page
|
|
250
|
+
if (webmentionsForUrl.length) {
|
|
251
|
+
// Sort them (based on when they were received/published)
|
|
252
|
+
return webmentionsForUrl.sort((a, b) => {
|
|
253
|
+
return getPublished(b) - getPublished(a)
|
|
254
|
+
})
|
|
255
|
+
}
|
|
256
|
+
// Otherwise, return an empty Array
|
|
257
|
+
return []
|
|
258
|
+
},
|
|
259
|
+
},
|
|
188
260
|
}
|
|
189
261
|
```
|
|
190
262
|
|
|
191
|
-
|
|
263
|
+
This attaches an Array containing Webmentions to each page (based on its URL). You can then access this Array of Webmentions with the variable, <samp>webmentions</samp>, within a [Layout](https://www.11ty.dev/docs/layouts/), [Include](https://www.11ty.dev/docs/includes/), or from the page itself:
|
|
264
|
+
|
|
265
|
+
```twig
|
|
266
|
+
{% for webmention in webmentions %}
|
|
267
|
+
{# Do something with each Webmention #}
|
|
268
|
+
{% endfor %}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
These Arrays of Webmentions can even be accessed when building [Collections](https://www.11ty.dev/docs/collections/), allowing you to create a Collection of pages sorted by their number of Webmentions, for example:
|
|
192
272
|
|
|
193
273
|
```javascript
|
|
194
274
|
module.exports = (eleventyConfig) => {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
275
|
+
eleventyConfig.addCollection("popular", (collection) => {
|
|
276
|
+
return collection
|
|
277
|
+
.sort((a, b) => {
|
|
278
|
+
return b.data.webmentions.length - a.data.webmentions.length
|
|
279
|
+
})
|
|
280
|
+
})
|
|
200
281
|
}
|
|
201
282
|
```
|
|
202
283
|
|
|
203
|
-
##
|
|
284
|
+
## Without Directory Data
|
|
204
285
|
|
|
205
|
-
|
|
286
|
+
If you would rather get Webmentions for a given page directly from a Layout/Include/Page itself, you can do so using the Filter, `getWebmentions`:
|
|
206
287
|
|
|
207
288
|
```twig
|
|
208
|
-
{%
|
|
289
|
+
{% set webmentions = ("https://example.com" + page.url) | getWebmentions %}
|
|
290
|
+
{% for webmention in webmentions %}
|
|
291
|
+
...
|
|
292
|
+
{% endfor %}
|
|
209
293
|
```
|
|
210
294
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
```twig
|
|
214
|
-
{% raw %}{% set responses = page.url | getWebmentions %}{% endraw %}
|
|
215
|
-
```
|
|
295
|
+
## Get specific types of Webmentions
|
|
216
296
|
|
|
217
|
-
|
|
297
|
+
Instead of getting all the Webmentions for a given page, you may want to grab only certain types of Webmentions. This is useful if you want to display different types of Webmentions separately, e.g.:
|
|
218
298
|
|
|
219
299
|
```twig
|
|
220
|
-
{%
|
|
221
|
-
{% set
|
|
300
|
+
{% set bookmarks = webmentions | getTypes(['bookmark-of']) %}
|
|
301
|
+
{% set likes = webmentions | getTypes(['like-of']) %}
|
|
302
|
+
{% set reposts = webmentions | getTypes(['repost-of']) %}
|
|
303
|
+
|
|
304
|
+
{% set replies = webmentions | getTypes(['mention-of', 'in-reply-to']) %}
|
|
222
305
|
```
|
|
223
306
|
|
|
224
|
-
|
|
307
|
+
## Get all Webmentions at once
|
|
308
|
+
|
|
309
|
+
If you need it, the plugin also makes available an Object containing your cached Webmentions organised in key:value pairs, where each key is a full URL on your website and its value is an Array of Webmentions sent to that URL:
|
|
225
310
|
|
|
226
311
|
```twig
|
|
227
|
-
{%
|
|
228
|
-
{% for url, array in
|
|
229
|
-
|
|
312
|
+
{% set count = 0 %}
|
|
313
|
+
{% for url, array in webmentionsByUrl %}
|
|
314
|
+
{% set count = array.length + count %}
|
|
230
315
|
{% endfor %}
|
|
231
|
-
<p>This
|
|
316
|
+
<p>This website has received {{ count }} Webmentions!</p>
|
|
232
317
|
```
|
|
233
318
|
|
|
234
|
-
|
|
319
|
+
## Webmention.io
|
|
235
320
|
|
|
236
|
-
[Webmention.io](https://webmention.io) is a in-place Webmention receiver solution that you can use by authenticating yourself via [IndieAuth](https://indieauth.com/) (or host it yourself), and, like so much other
|
|
321
|
+
[Webmention.io](https://webmention.io) is a in-place Webmention receiver solution that you can use by authenticating yourself via [IndieAuth](https://indieauth.com/) (or host it yourself), and, like *so much* other publicly-available IndieWeb software, is built and hosted by [Aaron Parecki](https://aaronparecki.com/).
|
|
237
322
|
|
|
238
323
|
### Add your token
|
|
239
324
|
|
|
@@ -245,25 +330,31 @@ WEBMENTION_IO_TOKEN=njJql0lKXnotreal4x3Wmd
|
|
|
245
330
|
|
|
246
331
|
### Set your feed and key config options
|
|
247
332
|
|
|
333
|
+
The example below requests the [JF2](https://www.w3.org/TR/jf2/) file format, which I highly recommend using; although, there is a JSON format available from [Webmention.io](https://webmention.io) as well. The [official documentation](https://github.com/aaronpk/webmention.io) has more information on how to use these two formats.
|
|
334
|
+
|
|
335
|
+
The key difference between the two feed formats is in the *naming* of the keys: the JF2 format holds the array of Webmentions in the `children` key, whereas the JSON format holds them in the `links` key. The JF2 format, however, provides keys and values that more tightly-align with [microformats](https://indieweb.org/microformats), the method I recommend the most for marking up HTML such that it can be consumed and understood by <q>search engines, aggregators, and other tools</q> across the Indieweb.
|
|
336
|
+
|
|
248
337
|
```javascript
|
|
249
338
|
const pluginWebmentions = require("@chrisburnell/eleventy-cache-webmentions")
|
|
250
339
|
|
|
251
|
-
module.exports = function
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
340
|
+
module.exports = function(eleventyConfig) {
|
|
341
|
+
eleventyConfig.addPlugin(pluginWebmentions, {
|
|
342
|
+
domain: "https://example.com",
|
|
343
|
+
feed: `https://webmention.io/api/mentions.jf2?domain=example.com&per-page=9001&token=${process.env.WEBMENTION_IO_TOKEN}`,
|
|
344
|
+
key: "children"
|
|
345
|
+
})
|
|
257
346
|
}
|
|
258
347
|
```
|
|
259
348
|
|
|
349
|
+
If you want to use the JSON format instead, make sure that you replace `mentions.jf2` in the URL with `mentions.json` and change the value of the key from `children` to `links`.
|
|
350
|
+
|
|
260
351
|
## go-jamming
|
|
261
352
|
|
|
262
353
|
[go-jamming](https://git.brainbaking.com/wgroeneveld/go-jamming) is a self-hosted Webmention sender and receiver, built in Go by [Wouter Groeneveld](https://brainbaking.com) and available with more information on his [personal git instance](https://git.brainbaking.com/wgroeneveld/go-jamming).
|
|
263
354
|
|
|
264
355
|
### Add your token
|
|
265
356
|
|
|
266
|
-
Once you’ve set up your
|
|
357
|
+
Once you’ve set up your *go-jamming* server and you’ve defined your token, you’ll need add it to your project as an environment variable, i.e. in a `.env` file in the root of your project:
|
|
267
358
|
|
|
268
359
|
```text
|
|
269
360
|
GO_JAMMING_TOKEN=njJql0lKXnotreal4x3Wmd
|
|
@@ -274,12 +365,12 @@ GO_JAMMING_TOKEN=njJql0lKXnotreal4x3Wmd
|
|
|
274
365
|
```javascript
|
|
275
366
|
const pluginWebmentions = require("@chrisburnell/eleventy-cache-webmentions")
|
|
276
367
|
|
|
277
|
-
module.exports = function
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
368
|
+
module.exports = function(eleventyConfig) {
|
|
369
|
+
eleventyConfig.addPlugin(pluginWebmentions, {
|
|
370
|
+
domain: "https://example.com",
|
|
371
|
+
feed: `https://jam.example.com/webmention/example.com/${process.env.GO_JAMMING_TOKEN}`,
|
|
372
|
+
key: "json"
|
|
373
|
+
})
|
|
283
374
|
}
|
|
284
375
|
```
|
|
285
376
|
|
|
@@ -38,15 +38,15 @@ const epoch = (value) => {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const getPublished = (webmention) => {
|
|
41
|
-
return webmention["
|
|
41
|
+
return webmention?.["data"]?.["published"] || webmention["published"] || webmention["wm-received"] || webmention["verified_date"]
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
const getContent = (webmention) => {
|
|
45
|
-
return webmention?.["content"]?.["html"] || webmention?.["content"] || webmention?.["data"]?.["content"] || ""
|
|
45
|
+
return webmention?.["contentSanitized"] || webmention?.["content"]?.["html"] || webmention?.["content"]?.["value"] || webmention?.["content"] || webmention?.["data"]?.["content"] || ""
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
const getSource = (webmention) => {
|
|
49
|
-
return webmention["url"] || webmention
|
|
49
|
+
return webmention?.["data"]?.["url"] || webmention["url"] || webmention["wm-source"] || webmention["source"]
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
const getTarget = (webmention) => {
|
|
@@ -54,7 +54,13 @@ const getTarget = (webmention) => {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
const getType = (webmention) => {
|
|
57
|
-
return webmention["wm-property"] || webmention?.["activity"]["type"] || webmention["type"]
|
|
57
|
+
return webmention["wm-property"] || webmention?.["activity"]?.["type"] || webmention["type"]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const getByTypes = (webmentions, allowedTypes) => {
|
|
61
|
+
return webmentions.filter((webmention) => {
|
|
62
|
+
return allowedTypes.includes(getType(webmention))
|
|
63
|
+
})
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
const defaults = {
|
|
@@ -97,15 +103,17 @@ const fetchWebmentions = async (options) => {
|
|
|
97
103
|
}
|
|
98
104
|
|
|
99
105
|
// If there is a cached file but it is outside of expiry, fetch fresh
|
|
100
|
-
// results since the most recent
|
|
106
|
+
// results since the most recent Webmention
|
|
101
107
|
if (!asset.isCacheValid(options.duration)) {
|
|
108
|
+
// Get the published date of the most recent Webmention, if it exists
|
|
102
109
|
const since = webmentions.length ? getPublished(webmentions[0]) : false
|
|
110
|
+
// Build the URL for the fetch request
|
|
103
111
|
const url = `${options.feed}${since ? `${options.feed.includes("?") ? "&" : "?"}since=${since}` : ""}`
|
|
104
112
|
await fetch(url).then(async (response) => {
|
|
105
113
|
if (response.ok) {
|
|
106
114
|
const feed = await response.json()
|
|
107
115
|
if (feed[options.key].length) {
|
|
108
|
-
// Combine newly-fetched
|
|
116
|
+
// Combine newly-fetched Webmentions with cached Webmentions
|
|
109
117
|
webmentions = feed[options.key].concat(webmentions)
|
|
110
118
|
// Remove duplicates by source URL
|
|
111
119
|
webmentions = uniqBy([...feed[options.key], ...webmentions], (webmention) => {
|
|
@@ -172,9 +180,6 @@ const filteredWebmentions = async (options) => {
|
|
|
172
180
|
filtered[url].push(webmention)
|
|
173
181
|
})
|
|
174
182
|
|
|
175
|
-
const filteredCount = Object.values(filtered).reduce((count, webmentions) => count + webmentions.length, 0)
|
|
176
|
-
console.log(`[${hostname(options.domain)}] ${filteredCount} filtered Webmentions pulled from cache.`)
|
|
177
|
-
|
|
178
183
|
return filtered
|
|
179
184
|
}
|
|
180
185
|
|
|
@@ -221,28 +226,44 @@ const getWebmentionsFilter = async (options, url, allowedTypes, callback) => {
|
|
|
221
226
|
callback(null, webmentions)
|
|
222
227
|
}
|
|
223
228
|
|
|
224
|
-
|
|
229
|
+
const eleventyCacheWebmentions = (eleventyConfig, options = {}) => {
|
|
225
230
|
options = Object.assign(defaults, options)
|
|
226
231
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
232
|
+
// Global Data
|
|
233
|
+
eleventyConfig.addGlobalData("webmentionsDefaults", defaults)
|
|
234
|
+
const filtered = async () => await filteredWebmentions(options)
|
|
235
|
+
eleventyConfig.addGlobalData("webmentionsByUrl", filtered)
|
|
236
|
+
const unfiltered = async () => await filteredWebmentions(options).then((filtered) => Object.values(filtered).reduce((array, webmentions) => [...array, ...webmentions], []))
|
|
237
|
+
eleventyConfig.addGlobalData("webmentionsAll", unfiltered)
|
|
238
|
+
|
|
239
|
+
// Liquid Filters
|
|
240
|
+
eleventyConfig.addLiquidFilter("getWebmentions", getWebmentionsFilter)
|
|
241
|
+
eleventyConfig.addLiquidFilter("getWebmentionPublished", getPublished)
|
|
242
|
+
eleventyConfig.addLiquidFilter("getWebmentionContent", getContent)
|
|
243
|
+
eleventyConfig.addLiquidFilter("getWebmentionSource", getSource)
|
|
244
|
+
eleventyConfig.addLiquidFilter("getWebmentionTarget", getTarget)
|
|
245
|
+
eleventyConfig.addLiquidFilter("getWebmentionType", getType)
|
|
246
|
+
eleventyConfig.addLiquidFilter("getWebmentionsByTypes", getByTypes)
|
|
247
|
+
|
|
248
|
+
// Nunjucks Filters
|
|
249
|
+
eleventyConfig.addNunjucksAsyncFilter("getWebmentions", getWebmentionsFilter)
|
|
250
|
+
eleventyConfig.addNunjucksFilter("getWebmentionsByTypes", getByTypes)
|
|
251
|
+
eleventyConfig.addNunjucksFilter("getWebmentionPublished", getPublished)
|
|
252
|
+
eleventyConfig.addNunjucksFilter("getWebmentionContent", getContent)
|
|
253
|
+
eleventyConfig.addNunjucksFilter("getWebmentionSource", getSource)
|
|
254
|
+
eleventyConfig.addNunjucksFilter("getWebmentionTarget", getTarget)
|
|
255
|
+
eleventyConfig.addNunjucksFilter("getWebmentionType", getType)
|
|
248
256
|
}
|
|
257
|
+
|
|
258
|
+
module.exports = eleventyCacheWebmentions
|
|
259
|
+
module.exports.defaults = defaults
|
|
260
|
+
module.exports.filteredWebmentions = filteredWebmentions
|
|
261
|
+
module.exports.webmentionsByUrl = filteredWebmentions
|
|
262
|
+
module.exports.fetchWebmentions = fetchWebmentions
|
|
263
|
+
module.exports.getWebmentions = getWebmentions
|
|
264
|
+
module.exports.getByTypes = getByTypes
|
|
265
|
+
module.exports.getPublished = getPublished
|
|
266
|
+
module.exports.getContent = getContent
|
|
267
|
+
module.exports.getSource = getSource
|
|
268
|
+
module.exports.getTarget = getTarget
|
|
269
|
+
module.exports.getType = getType
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrisburnell/eleventy-cache-webmentions",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Cache webmentions using eleventy-fetch and make them available to use in collections, layouts, pages, etc. in Eleventy.",
|
|
5
5
|
"author": "Chris Burnell <me@chrisburnell.com>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"webmention"
|
|
21
21
|
],
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"eslint": "^8.
|
|
23
|
+
"eslint": "^8.56.0"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@11ty/eleventy-fetch": "^4.0.0",
|