@chrisburnell/eleventy-cache-webmentions 1.0.0-beta.3 → 1.0.0-beta.6

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.
@@ -2,7 +2,6 @@ const fetch = require("node-fetch")
2
2
  const sanitizeHTML = require("sanitize-html")
3
3
  const uniqBy = require("lodash/uniqBy")
4
4
  const { AssetCache } = require("@11ty/eleventy-fetch")
5
- const { defaultsDeep } = require("lodash")
6
5
 
7
6
  const absoluteURL = (url, domain) => {
8
7
  try {
@@ -43,7 +42,7 @@ const getPublished = (webmention) => {
43
42
  }
44
43
 
45
44
  const getContent = (webmention) => {
46
- return webmention?.["content"]["html"] || webmention["content"] || webmention?.["data"]["content"]
45
+ return webmention?.["content"]?.["html"] || webmention?.["content"] || webmention?.["data"]?.["content"] || ""
47
46
  }
48
47
 
49
48
  const getSource = (webmention) => {
@@ -67,25 +66,25 @@ const defaults = {
67
66
  },
68
67
  },
69
68
  urlReplacements: {},
70
- maximumHtmlLength: 2000,
69
+ maximumHtmlLength: 1000,
71
70
  maximumHtmlText: "mentioned this in",
72
71
  }
73
72
 
74
73
  const fetchWebmentions = async (options) => {
75
74
  if (!options.domain) {
76
- throw new Error("domain is a required field when adding the plugin to your eleventyConfig using addPlugin. See https://chrisburnell.com/eleventy-cache-webmentions/#installation for more information.")
75
+ 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
76
  }
78
77
 
79
78
  if (!options.feed) {
80
- throw new Error("feed is a required field when adding the plugin to your eleventyConfig using addPlugin. See https://chrisburnell.com/eleventy-cache-webmentions/#installation for more information.")
79
+ 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
80
  }
82
81
 
83
82
  if (!options.key) {
84
- throw new Error("key is a required field when adding the plugin to your eleventyConfig using addPlugin. See https://chrisburnell.com/eleventy-cache-webmentions/#installation for more information.")
83
+ 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
84
  }
86
85
 
87
86
  if (!options.uniqueKey) {
88
- throw new Error("uniqueKey is a required field when adding the plugin to your eleventyConfig using addPlugin. See https://chrisburnell.com/eleventy-cache-webmentions/#installation for more information.")
87
+ 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
88
  }
90
89
 
91
90
  let asset = new AssetCache(options.uniqueKey)
@@ -160,32 +159,30 @@ const getWebmentions = async (options, url, allowedTypes = {}) => {
160
159
  return []
161
160
  }
162
161
 
163
- const results = webmentions[url]
164
- // filter webmentions by allowed response post types
165
- .filter((entry) => {
166
- return typeof allowedTypes === "object" && Object.keys(allowedTypes).length ? allowedTypes.includes(getType(entry)) : true
167
- })
168
- // sanitize content of webmentions against HTML limit
169
- .map((entry) => {
170
- if (!("content" in entry) || !("data" in entry)) {
171
- return entry
172
- }
173
- const html = getContent(entry)
174
- if (html && html.length > options.maximumHtmlLength) {
175
- entry.content = `${options.maximumHtmlText} <a href="${getSource(entry)}">${getSource(entry)}</a>`
176
- } else if (Object.keys(options.allowedHTML).length) {
177
- entry.content = sanitizeHTML(html, options.allowedHTML)
178
- } else {
179
- entry.content = html
180
- }
181
- return entry
182
- })
183
- // sort by published
184
- .sort((a, b) => {
185
- return epoch(getPublished(a)) - epoch(getPublished(b))
186
- })
162
+ return (
163
+ webmentions[url]
164
+ // filter webmentions by allowed response post types
165
+ .filter((entry) => {
166
+ return typeof allowedTypes === "object" && Object.keys(allowedTypes).length ? allowedTypes.includes(getType(entry)) : true
167
+ })
168
+ // sanitize content of webmentions against HTML limit
169
+ .map((entry) => {
170
+ const html = getContent(entry)
171
+
172
+ if (html.length) {
173
+ entry.content = sanitizeHTML(html, options.allowedHTML)
174
+ if (html.length > options.maximumHtmlLength) {
175
+ entry.content = `${options.maximumHtmlText} <a href="${getSource(entry)}">${getSource(entry)}</a>`
176
+ }
177
+ }
187
178
 
188
- return results
179
+ return entry
180
+ })
181
+ // sort by published
182
+ .sort((a, b) => {
183
+ return epoch(getPublished(a)) - epoch(getPublished(b))
184
+ })
185
+ )
189
186
  }
190
187
 
191
188
  const getWebmentionsFilter = async (options, url, allowedTypes, callback) => {
@@ -213,7 +210,6 @@ module.exports = (eleventyConfig, options = {}) => {
213
210
 
214
211
  return {
215
212
  defaults: defaults,
216
- webmentions: filteredWebmentions(options),
217
213
  fetchWebmentions: fetchWebmentions,
218
214
  filteredWebmentions: filteredWebmentions,
219
215
  getWebmentions: getWebmentions,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrisburnell/eleventy-cache-webmentions",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.6",
4
4
  "description": "Fetch and cache webmentions using eleventy-fetch.",
5
5
  "main": "eleventy-cache-webmentions.js",
6
6
  "author": "Chris Burnell <me@chrisburnell.com>",
@@ -19,7 +19,7 @@
19
19
  "@11ty/eleventy-fetch": "^3.0.0",
20
20
  "lodash": "^4.17.21",
21
21
  "node-fetch": "2.6.5",
22
- "sanitize-html": "^2.5.2"
22
+ "sanitize-html": "^2.7.1"
23
23
  },
24
24
  "keywords": [
25
25
  "eleventy",