@chrisburnell/eleventy-cache-webmentions 0.0.1 → 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.
@@ -52,8 +52,9 @@ module.exports = (config, options = {}) => {
52
52
  a: ["href"],
53
53
  },
54
54
  },
55
- urlReplacements: [],
55
+ urlReplacements: {},
56
56
  maximumHtmlLength: 2000,
57
+ maximumHtmlText: "mentioned this in",
57
58
  },
58
59
  options
59
60
  )
@@ -78,18 +79,22 @@ module.exports = (config, options = {}) => {
78
79
  if (!asset.isCacheValid(options.duration)) {
79
80
  const since = asset._cache.getKey(options.key) ? asset._cache.getKey(options.key).cachedAt : false
80
81
  const url = `https://webmention.io/api/mentions.jf2?domain=${hostname(options.domain)}&token=${TOKEN}&per-page=9001${since ? `&since=${since}` : ``}`
81
- const response = await fetch(url)
82
- if (response.ok) {
83
- const feed = await response.json()
84
- if (feed.children.length) {
85
- console.log(`[${hostname(options.domain)}] ${feed.children.length} new Webmentions fetched into cache.`)
86
- }
87
- webmentions.children = [...feed.children, ...webmentions.children].sort((a, b) => {
88
- 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)
89
97
  })
90
- await asset.save(webmentions, "json")
91
- return webmentions
92
- }
93
98
  }
94
99
 
95
100
  return webmentions
@@ -130,7 +135,7 @@ module.exports = (config, options = {}) => {
130
135
  }
131
136
 
132
137
  const results = webmentions[url]
133
- // filter webmentions by allowedTypes only if passed
138
+ // filter webmentions by allowed response post types
134
139
  .filter((entry) => {
135
140
  return Array.isArray(allowedTypes) ? allowedTypes.includes(entry["wm-property"]) : true
136
141
  })
@@ -146,7 +151,7 @@ module.exports = (config, options = {}) => {
146
151
  }
147
152
  const { html, text } = entry.content
148
153
  if (html && html.length > options.maximumHtmlLength) {
149
- entry.content.value = `mentioned this in <a href="${entry["wm-source"]}">${entry["wm-source"]}</a>`
154
+ entry.content.value = `${options.maximumHtmlText} <a href="${entry["wm-source"]}">${entry["wm-source"]}</a>`
150
155
  } else {
151
156
  entry.content.value = sanitizeHTML(html || text, options.allowedHTML)
152
157
  }
@@ -174,8 +179,9 @@ module.exports = (config, options = {}) => {
174
179
  throw new Error("domain is a required option to be passed when adding the plugin to your config using addPlugin.")
175
180
  }
176
181
 
182
+ config.addLiquidFilter("getWebmentions", getWebmentionsFilter)
177
183
  config.addNunjucksAsyncFilter("getWebmentions", getWebmentionsFilter)
178
184
  } else {
179
- return filteredWebmentions()
185
+ return filteredWebmentions
180
186
  }
181
187
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrisburnell/eleventy-cache-webmentions",
3
- "version": "0.0.1",
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>",