@chrisburnell/eleventy-cache-webmentions 1.2.4 → 1.2.6-rc.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/eleventy-cache-webmentions.js +44 -55
- package/package.json +2 -2
|
@@ -101,24 +101,50 @@ const fetchWebmentions = async (options) => {
|
|
|
101
101
|
if (!asset.isCacheValid(options.duration)) {
|
|
102
102
|
const since = webmentions.length ? getPublished(webmentions[0]) : false
|
|
103
103
|
const url = `${options.feed}${since ? `${options.feed.includes("?") ? "&" : "?"}since=${since}` : ""}`
|
|
104
|
-
await fetch(url)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
await fetch(url).then(async (response) => {
|
|
105
|
+
if (response.ok) {
|
|
106
|
+
const feed = await response.json()
|
|
107
|
+
if (feed[options.key].length) {
|
|
108
|
+
// Process the blocklist, if it has any entries
|
|
109
|
+
if (options.blocklist.length) {
|
|
110
|
+
webmentions = webmentions.filter((webmention) => {
|
|
111
|
+
let sourceUrl = getSource(webmention)
|
|
112
|
+
for (let url of options.blocklist) {
|
|
113
|
+
if (sourceUrl.includes(url.replace(/\/?$/, "/"))) {
|
|
114
|
+
return false
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return true
|
|
111
118
|
})
|
|
112
|
-
console.log(`[${hostname(options.domain)}] ${feed[options.key].length} new Webmentions fetched into cache.`)
|
|
113
119
|
}
|
|
114
|
-
|
|
115
|
-
|
|
120
|
+
// Process the allowlist, if it has any entries
|
|
121
|
+
if (options.allowlist.length) {
|
|
122
|
+
webmentions = webmentions.filter((webmention) => {
|
|
123
|
+
let sourceUrl = getSource(webmention)
|
|
124
|
+
for (let url of options.allowlist) {
|
|
125
|
+
if (sourceUrl.includes(url.replace(/\/?$/, "/"))) {
|
|
126
|
+
return true
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return false
|
|
130
|
+
})
|
|
131
|
+
}
|
|
132
|
+
// Remove duplicates by source URL
|
|
133
|
+
webmentions = uniqBy([...feed[options.key], ...webmentions], (entry) => {
|
|
134
|
+
return getSource(entry)
|
|
135
|
+
})
|
|
136
|
+
if (webmentions.length) {
|
|
137
|
+
console.log(`[${hostname(options.domain)}] ${webmentions.length} new Webmentions fetched into cache.`)
|
|
138
|
+
}
|
|
116
139
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
140
|
+
await asset.save(webmentions, "json")
|
|
141
|
+
return webmentions
|
|
142
|
+
}
|
|
143
|
+
return Promise.reject(response)
|
|
144
|
+
})
|
|
145
|
+
.catch((error) => {
|
|
146
|
+
console.log(`[${hostname(options.domain)}] Something went wrong with your request to ${hostname(options.feed)}!`, error)
|
|
147
|
+
})
|
|
122
148
|
}
|
|
123
149
|
|
|
124
150
|
return webmentions
|
|
@@ -132,36 +158,6 @@ const filteredWebmentions = async (options) => {
|
|
|
132
158
|
|
|
133
159
|
let rawWebmentions = await fetchWebmentions(options)
|
|
134
160
|
|
|
135
|
-
// Process the blocklist, if it has any entries
|
|
136
|
-
if (options.blocklist.length) {
|
|
137
|
-
rawWebmentions = rawWebmentions.filter((webmention) => {
|
|
138
|
-
let sourceUrl = getSource(webmention)
|
|
139
|
-
|
|
140
|
-
for (let url of options.blocklist) {
|
|
141
|
-
if (sourceUrl.includes(url.replace(/\/?$/, "/"))) {
|
|
142
|
-
return false
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return true
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Process the allowlist, if it has any entries
|
|
151
|
-
if (options.allowlist.length) {
|
|
152
|
-
rawWebmentions = rawWebmentions.filter((webmention) => {
|
|
153
|
-
let sourceUrl = getSource(webmention)
|
|
154
|
-
|
|
155
|
-
for (let url of options.allowlist) {
|
|
156
|
-
if (sourceUrl.includes(url.replace(/\/?$/, "/"))) {
|
|
157
|
-
return true
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return false
|
|
162
|
-
})
|
|
163
|
-
}
|
|
164
|
-
|
|
165
161
|
// Fix local URLs based on urlReplacements and sort Webmentions into groups
|
|
166
162
|
// by target base URL
|
|
167
163
|
rawWebmentions.forEach((webmention) => {
|
|
@@ -174,13 +170,6 @@ const filteredWebmentions = async (options) => {
|
|
|
174
170
|
filtered[url].push(webmention)
|
|
175
171
|
})
|
|
176
172
|
|
|
177
|
-
// Remove duplicates by source URL
|
|
178
|
-
for (let url in filtered) {
|
|
179
|
-
filtered[url] = uniqBy(filtered[url], (entry) => {
|
|
180
|
-
return getSource(entry)
|
|
181
|
-
})
|
|
182
|
-
}
|
|
183
|
-
|
|
184
173
|
const filteredCount = Object.values(filtered).reduce((count, webmentions) => count + webmentions.length, 0)
|
|
185
174
|
console.log(`[${hostname(options.domain)}] ${filteredCount} filtered Webmentions pulled from cache.`)
|
|
186
175
|
|
|
@@ -197,11 +186,11 @@ const getWebmentions = async (options, url, allowedTypes = {}) => {
|
|
|
197
186
|
|
|
198
187
|
return (
|
|
199
188
|
webmentions[url]
|
|
200
|
-
//
|
|
189
|
+
// Filter webmentions by allowed response post types
|
|
201
190
|
.filter((entry) => {
|
|
202
191
|
return typeof allowedTypes === "object" && Object.keys(allowedTypes).length ? allowedTypes.includes(getType(entry)) : true
|
|
203
192
|
})
|
|
204
|
-
//
|
|
193
|
+
// Sanitize content of webmentions against HTML limit
|
|
205
194
|
.map((entry) => {
|
|
206
195
|
const html = getContent(entry)
|
|
207
196
|
|
|
@@ -214,7 +203,7 @@ const getWebmentions = async (options, url, allowedTypes = {}) => {
|
|
|
214
203
|
|
|
215
204
|
return entry
|
|
216
205
|
})
|
|
217
|
-
//
|
|
206
|
+
// Sort by published
|
|
218
207
|
.sort((a, b) => {
|
|
219
208
|
return epoch(getPublished(a)) - epoch(getPublished(b))
|
|
220
209
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrisburnell/eleventy-cache-webmentions",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6-rc.1",
|
|
4
4
|
"description": "Fetch and cache webmentions using eleventy-fetch.",
|
|
5
5
|
"author": "Chris Burnell <me@chrisburnell.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@11ty/eleventy-fetch": "^4.0.0",
|
|
27
27
|
"lodash": "^4.17.21",
|
|
28
|
-
"node-fetch": "^
|
|
28
|
+
"node-fetch": "^2.6.7",
|
|
29
29
|
"sanitize-html": "^2.11.0"
|
|
30
30
|
},
|
|
31
31
|
"main": "eleventy-cache-webmentions.js",
|