@chrisburnell/eleventy-cache-webmentions 0.1.9 → 0.1.12

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/.prettierrc ADDED
@@ -0,0 +1,4 @@
1
+ # .prettierrc
2
+ semi: false
3
+ printWidth: 9999
4
+ tabWidth: 4
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # eleventy-cache-webmentions
2
2
 
3
- > Cache webmentions using eleventy-cache-assets and make them available to use in collections, templates, pages, etc.
3
+ > Cache webmentions using eleventy-fetch and make them available to use in collections, templates, pages, etc.
4
4
 
5
5
  ## Installation
6
6
 
@@ -1,7 +1,7 @@
1
1
  const fetch = require("node-fetch")
2
2
  const sanitizeHTML = require("sanitize-html")
3
3
  const uniqBy = require("lodash/uniqBy")
4
- const { AssetCache } = require("@11ty/eleventy-cache-assets")
4
+ const { AssetCache } = require("@11ty/eleventy-fetch")
5
5
 
6
6
  // Load .env variables with dotenv
7
7
  require("dotenv").config()
@@ -77,7 +77,7 @@ module.exports = (eleventyConfig, options = {}) => {
77
77
  // If there is a cached file but it is outside of expiry, fetch fresh
78
78
  // results since the most recent
79
79
  if (!asset.isCacheValid(options.duration)) {
80
- const since = asset._cache.getKey(options.uniqueKey || options.key) ? asset._cache.getKey(options.uniqueKey || options.key).cachedAt : false
80
+ const since = webmentions.children.length ? webmentions.children[0]["wm-received"] : false
81
81
  const url = `https://webmention.io/api/mentions.jf2?domain=${hostname(options.domain)}&token=${TOKEN}&per-page=9001${since ? `&since=${since}` : ``}`
82
82
  await fetch(url)
83
83
  .then(async (response) => {
@@ -104,7 +104,7 @@ module.exports = (eleventyConfig, options = {}) => {
104
104
  const rawWebmentions = await fetchWebmentions()
105
105
  let webmentions = {}
106
106
 
107
- // Sort Webmentions into groups by target
107
+ // Sort Webmentions into groups by `wm-target`
108
108
  rawWebmentions.children.forEach((webmention) => {
109
109
  // Get the target of the Webmention and fix it up
110
110
  let url = baseUrl(fixUrl(webmention["wm-target"].replace(/\/?$/, "/"), options.urlReplacements))
@@ -116,10 +116,10 @@ module.exports = (eleventyConfig, options = {}) => {
116
116
  webmentions[url].push(webmention)
117
117
  })
118
118
 
119
- // Sort Webmentions in groups by url and remove duplicates by wm-id
119
+ // Sort Webmentions in groups by url and remove duplicates by `url`
120
120
  for (let url in webmentions) {
121
121
  webmentions[url] = uniqBy(webmentions[url], (item) => {
122
- return item["wm-id"]
122
+ return item["url"]
123
123
  })
124
124
  }
125
125
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@chrisburnell/eleventy-cache-webmentions",
3
- "version": "0.1.9",
4
- "description": "Cache webmentions from webmention.io using eleventy-cache-assets.",
3
+ "version": "0.1.12",
4
+ "description": "Cache webmentions from webmention.io using eleventy-fetch.",
5
5
  "main": "eleventy-cache-webmentions.js",
6
6
  "author": "Chris Burnell <me@chrisburnell.com>",
7
7
  "license": "MIT",
@@ -16,7 +16,7 @@
16
16
  "node": ">=10"
17
17
  },
18
18
  "dependencies": {
19
- "@11ty/eleventy-cache-assets": "^2.3.0",
19
+ "@11ty/eleventy-fetch": "^3.0.0",
20
20
  "dotenv": "^10.0.0",
21
21
  "lodash": "^4.17.21",
22
22
  "node-fetch": "2.6.5",