@chrisburnell/eleventy-cache-webmentions 1.0.0 → 1.1.0

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.
@@ -65,6 +65,8 @@ const defaults = {
65
65
  a: ["href"],
66
66
  },
67
67
  },
68
+ allowlist: [],
69
+ blocklist: [],
68
70
  urlReplacements: {},
69
71
  maximumHtmlLength: 1000,
70
72
  maximumHtmlText: "mentioned this in",
@@ -129,9 +131,39 @@ const filteredWebmentions = async (options) => {
129
131
  const rawWebmentions = await fetchWebmentions(options)
130
132
  let webmentions = {}
131
133
 
132
- // Sort Webmentions into groups by target
134
+ // Process the blocklist, if it has any entries
135
+ if (options.blocklist.length) {
136
+ rawWebmentions = rawWebmentions.filter((webmention) => {
137
+ let sourceUrl = getSource(webmention)
138
+
139
+ for (let url of options.blocklist) {
140
+ if (sourceUrl.includes(url.replace(/\/?$/, "/"))) {
141
+ return false
142
+ }
143
+ }
144
+
145
+ return true
146
+ })
147
+ }
148
+
149
+ // Process the allowlist, if it has any entries
150
+ if (options.allowlist.length) {
151
+ rawWebmentions = rawWebmentions.filter((webmention) => {
152
+ let sourceUrl = getSource(webmention)
153
+
154
+ for (let url of options.allowlist) {
155
+ if (sourceUrl.includes(url.replace(/\/?$/, "/"))) {
156
+ return true
157
+ }
158
+ }
159
+
160
+ return false
161
+ })
162
+ }
163
+
164
+ // Fix local URLs based on urlReplacements and sort Webmentions into groups
165
+ // by target base URL
133
166
  rawWebmentions.forEach((webmention) => {
134
- // Get the target of the Webmention and fix it up
135
167
  let url = baseUrl(fixUrl(getTarget(webmention).replace(/\/?$/, "/"), options.urlReplacements))
136
168
 
137
169
  if (!webmentions[url]) {
@@ -141,7 +173,7 @@ const filteredWebmentions = async (options) => {
141
173
  webmentions[url].push(webmention)
142
174
  })
143
175
 
144
- // Sort Webmentions in groups by url and remove duplicates by `url`
176
+ // Remove duplicates by source URL
145
177
  for (let url in webmentions) {
146
178
  webmentions[url] = uniqBy(webmentions[url], (entry) => {
147
179
  return getSource(entry)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrisburnell/eleventy-cache-webmentions",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
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,7 +18,7 @@
18
18
  "dependencies": {
19
19
  "@11ty/eleventy-fetch": "^3.0.0",
20
20
  "lodash": "^4.17.21",
21
- "node-fetch": "2.6.5",
21
+ "node-fetch": "^2.6.5",
22
22
  "sanitize-html": "^2.7.1"
23
23
  },
24
24
  "keywords": [