@chrisburnell/eleventy-cache-webmentions 1.0.0-beta.3 → 1.0.0-beta.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.
- package/eleventy-cache-webmentions.js +32 -33
- package/package.json +3 -3
|
@@ -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:
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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,33 @@ const getWebmentions = async (options, url, allowedTypes = {}) => {
|
|
|
160
159
|
return []
|
|
161
160
|
}
|
|
162
161
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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 > options.maximumHtmlLength) {
|
|
173
|
+
console.log(entry.data.url, "too long")
|
|
174
|
+
entry.content = `${options.maximumHtmlText} <a href="${getSource(entry)}">${getSource(entry)}</a>`
|
|
175
|
+
} else if (html.length && Object.keys(options.allowedHTML).length) {
|
|
176
|
+
// console.log("sanitize")
|
|
177
|
+
entry.content = sanitizeHTML(html, options.allowedHTML)
|
|
178
|
+
} else {
|
|
179
|
+
// console.log("default")
|
|
180
|
+
entry.content = html
|
|
181
|
+
}
|
|
171
182
|
return entry
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
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
|
-
})
|
|
187
|
-
|
|
188
|
-
return results
|
|
183
|
+
})
|
|
184
|
+
// sort by published
|
|
185
|
+
.sort((a, b) => {
|
|
186
|
+
return epoch(getPublished(a)) - epoch(getPublished(b))
|
|
187
|
+
})
|
|
188
|
+
)
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
const getWebmentionsFilter = async (options, url, allowedTypes, callback) => {
|
|
@@ -213,7 +213,6 @@ module.exports = (eleventyConfig, options = {}) => {
|
|
|
213
213
|
|
|
214
214
|
return {
|
|
215
215
|
defaults: defaults,
|
|
216
|
-
webmentions: filteredWebmentions(options),
|
|
217
216
|
fetchWebmentions: fetchWebmentions,
|
|
218
217
|
filteredWebmentions: filteredWebmentions,
|
|
219
218
|
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
|
+
"version": "1.0.0-beta.4",
|
|
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>",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@11ty/eleventy-fetch": "^3.0.0",
|
|
20
20
|
"lodash": "^4.17.21",
|
|
21
|
-
"node-fetch": "2.
|
|
22
|
-
"sanitize-html": "^2.
|
|
21
|
+
"node-fetch": "3.2.10",
|
|
22
|
+
"sanitize-html": "^2.7.1"
|
|
23
23
|
},
|
|
24
24
|
"keywords": [
|
|
25
25
|
"eleventy",
|