@chrisburnell/eleventy-cache-webmentions 0.1.0 → 0.1.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.
@@ -79,18 +79,22 @@ module.exports = (config, options = {}) => {
79
79
  if (!asset.isCacheValid(options.duration)) {
80
80
  const since = asset._cache.getKey(options.key) ? asset._cache.getKey(options.key).cachedAt : false
81
81
  const url = `https://webmention.io/api/mentions.jf2?domain=${hostname(options.domain)}&token=${TOKEN}&per-page=9001${since ? `&since=${since}` : ``}`
82
- const response = await fetch(url)
83
- if (response.ok) {
84
- const feed = await response.json()
85
- if (feed.children.length) {
86
- console.log(`[${hostname(options.domain)}] ${feed.children.length} new Webmentions fetched into cache.`)
87
- }
88
- webmentions.children = [...feed.children, ...webmentions.children].sort((a, b) => {
89
- return epoch(b.published || b["wm-received"]) - epoch(a.published || a["wm-received"])
82
+ await fetch(url)
83
+ .then(async (response) => {
84
+ if (response.ok) {
85
+ const feed = await response.json()
86
+ if (feed.children.length) {
87
+ console.log(`[${hostname(options.domain)}] ${feed.children.length} new Webmentions fetched into cache.`)
88
+ }
89
+ webmentions.children = [...feed.children, ...webmentions.children]
90
+ await asset.save(webmentions, "json")
91
+ return webmentions
92
+ }
93
+ return Promise.reject(response)
94
+ })
95
+ .catch((error) => {
96
+ console.log("Something went wrong with your request to webmention.io!", error)
90
97
  })
91
- await asset.save(webmentions, "json")
92
- return webmentions
93
- }
94
98
  }
95
99
 
96
100
  return webmentions
@@ -131,7 +135,7 @@ module.exports = (config, options = {}) => {
131
135
  }
132
136
 
133
137
  const results = webmentions[url]
134
- // filter webmentions by allowedTypes only if passed
138
+ // filter webmentions by allowed response post types
135
139
  .filter((entry) => {
136
140
  return Array.isArray(allowedTypes) ? allowedTypes.includes(entry["wm-property"]) : true
137
141
  })
@@ -178,6 +182,6 @@ module.exports = (config, options = {}) => {
178
182
  config.addLiquidFilter("getWebmentions", getWebmentionsFilter)
179
183
  config.addNunjucksAsyncFilter("getWebmentions", getWebmentionsFilter)
180
184
  } else {
181
- return filteredWebmentions()
185
+ return filteredWebmentions
182
186
  }
183
187
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrisburnell/eleventy-cache-webmentions",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Cache webmentions from webmention.io using eleventy-cache-assets.",
5
5
  "main": "eleventy-cache-webmentions.js",
6
6
  "author": "Chris Burnell <me@chrisburnell.com>",