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