@chrisburnell/eleventy-cache-webmentions 2.0.0 → 2.0.2

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
@@ -2,6 +2,22 @@
2
2
 
3
3
  > Cache webmentions using eleventy-fetch and make them available to use in collections, layouts, pages, etc. in Eleventy.
4
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
+ ```
20
+
5
21
  ## Quick Guide
6
22
 
7
23
  I wrote a quicker and simpler guide to getting this Eleventy plugin working that cuts out all the fluff and extra details.
@@ -281,11 +297,11 @@ If you would rather get Webmentions for a given page directly from a Layout/Incl
281
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.:
282
298
 
283
299
  ```twig
284
- {% set bookmarks = webmentions | getTypes(['bookmark-of']) %}
285
- {% set likes = webmentions | getTypes(['like-of']) %}
286
- {% set reposts = webmentions | getTypes(['repost-of']) %}
300
+ {% set bookmarks = webmentions | getWebmentionsByTypes(['bookmark-of']) %}
301
+ {% set likes = webmentions | getWebmentionsByTypes(['like-of']) %}
302
+ {% set reposts = webmentions | getWebmentionsByTypes(['repost-of']) %}
287
303
 
288
- {% set replies = webmentions | getTypes(['mention-of', 'in-reply-to']) %}
304
+ {% set replies = webmentions | getWebmentionsByTypes(['mention-of', 'in-reply-to']) %}
289
305
  ```
290
306
 
291
307
  ## Get all Webmentions at once
@@ -42,7 +42,7 @@ const getPublished = (webmention) => {
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) => {
@@ -109,52 +109,53 @@ const fetchWebmentions = async (options) => {
109
109
  const since = webmentions.length ? getPublished(webmentions[0]) : false
110
110
  // Build the URL for the fetch request
111
111
  const url = `${options.feed}${since ? `${options.feed.includes("?") ? "&" : "?"}since=${since}` : ""}`
112
- await fetch(url).then(async (response) => {
113
- if (response.ok) {
114
- const feed = await response.json()
115
- if (feed[options.key].length) {
116
- // Combine newly-fetched Webmentions with cached Webmentions
117
- webmentions = feed[options.key].concat(webmentions)
118
- // Remove duplicates by source URL
119
- webmentions = uniqBy([...feed[options.key], ...webmentions], (webmention) => {
120
- return getSource(webmention)
121
- })
122
- // Process the blocklist, if it has any entries
123
- if (options.blocklist.length) {
124
- webmentions = webmentions.filter((webmention) => {
125
- let sourceUrl = getSource(webmention)
126
- for (let url of options.blocklist) {
127
- if (sourceUrl.includes(url.replace(/\/?$/, "/"))) {
128
- return false
129
- }
130
- }
131
- return true
112
+ await fetch(url)
113
+ .then(async (response) => {
114
+ if (response.ok) {
115
+ const feed = await response.json()
116
+ if (feed[options.key].length) {
117
+ // Combine newly-fetched Webmentions with cached Webmentions
118
+ webmentions = feed[options.key].concat(webmentions)
119
+ // Remove duplicates by source URL
120
+ webmentions = uniqBy([...feed[options.key], ...webmentions], (webmention) => {
121
+ return getSource(webmention)
132
122
  })
133
- }
134
- // Process the allowlist, if it has any entries
135
- if (options.allowlist.length) {
136
- webmentions = webmentions.filter((webmention) => {
137
- let sourceUrl = getSource(webmention)
138
- for (let url of options.allowlist) {
139
- if (sourceUrl.includes(url.replace(/\/?$/, "/"))) {
140
- return true
123
+ // Process the blocklist, if it has any entries
124
+ if (options.blocklist.length) {
125
+ webmentions = webmentions.filter((webmention) => {
126
+ let sourceUrl = getSource(webmention)
127
+ for (let url of options.blocklist) {
128
+ if (sourceUrl.includes(url.replace(/\/?$/, "/"))) {
129
+ return false
130
+ }
141
131
  }
142
- }
143
- return false
144
- })
145
- }
146
- if (webmentions.length) {
147
- console.log(`[${hostname(options.domain)}] ${webmentions.length} new Webmentions fetched into cache.`)
132
+ return true
133
+ })
134
+ }
135
+ // Process the allowlist, if it has any entries
136
+ if (options.allowlist.length) {
137
+ webmentions = webmentions.filter((webmention) => {
138
+ let sourceUrl = getSource(webmention)
139
+ for (let url of options.allowlist) {
140
+ if (sourceUrl.includes(url.replace(/\/?$/, "/"))) {
141
+ return true
142
+ }
143
+ }
144
+ return false
145
+ })
146
+ }
147
+ if (webmentions.length) {
148
+ console.log(`[${hostname(options.domain)}] ${webmentions.length} new Webmentions fetched into cache.`)
149
+ }
148
150
  }
151
+ await asset.save(webmentions, "json")
152
+ return webmentions
149
153
  }
150
- await asset.save(webmentions, "json")
151
- return webmentions
152
- }
153
- return Promise.reject(response)
154
- })
155
- .catch((error) => {
156
- console.log(`[${hostname(options.domain)}] Something went wrong with your request to ${hostname(options.feed)}!`, error)
157
- })
154
+ return Promise.reject(response)
155
+ })
156
+ .catch((error) => {
157
+ console.log(`[${hostname(options.domain)}] Something went wrong with your request to ${hostname(options.feed)}!`, error)
158
+ })
158
159
  }
159
160
 
160
161
  return webmentions
@@ -238,12 +239,12 @@ const eleventyCacheWebmentions = (eleventyConfig, options = {}) => {
238
239
 
239
240
  // Liquid Filters
240
241
  eleventyConfig.addLiquidFilter("getWebmentions", getWebmentionsFilter)
242
+ eleventyConfig.addLiquidFilter("getWebmentionsByTypes", getByTypes)
241
243
  eleventyConfig.addLiquidFilter("getWebmentionPublished", getPublished)
242
244
  eleventyConfig.addLiquidFilter("getWebmentionContent", getContent)
243
245
  eleventyConfig.addLiquidFilter("getWebmentionSource", getSource)
244
246
  eleventyConfig.addLiquidFilter("getWebmentionTarget", getTarget)
245
247
  eleventyConfig.addLiquidFilter("getWebmentionType", getType)
246
- eleventyConfig.addLiquidFilter("getWebmentionsByTypes", getByTypes)
247
248
 
248
249
  // Nunjucks Filters
249
250
  eleventyConfig.addNunjucksAsyncFilter("getWebmentions", getWebmentionsFilter)
@@ -262,8 +263,14 @@ module.exports.webmentionsByUrl = filteredWebmentions
262
263
  module.exports.fetchWebmentions = fetchWebmentions
263
264
  module.exports.getWebmentions = getWebmentions
264
265
  module.exports.getByTypes = getByTypes
266
+ module.exports.getWebmentionsByTypes = getByTypes
265
267
  module.exports.getPublished = getPublished
268
+ module.exports.getWebmentionPublished = getPublished
266
269
  module.exports.getContent = getContent
270
+ module.exports.getWebmentionContent = getContent
267
271
  module.exports.getSource = getSource
272
+ module.exports.getWebmentionSource = getSource
268
273
  module.exports.getTarget = getTarget
274
+ module.exports.getWebmentionTarget = getTarget
269
275
  module.exports.getType = getType
276
+ module.exports.getWebmentionType = getType
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrisburnell/eleventy-cache-webmentions",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
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",