@chrisburnell/eleventy-cache-webmentions 0.1.6 → 0.1.10

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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # eleventy-cache-assets
1
+ # eleventy-cache-webmentions
2
2
 
3
3
  > Cache webmentions using eleventy-cache-assets and make them available to use in collections, templates, pages, etc.
4
4
 
@@ -7,9 +7,9 @@
7
7
  - **With npm:** `npm install @chrisburnell/eleventy-cache-webmentions`
8
8
  - **Direct download:** [https://github.com/chrisburnell/eleventy-cache-webmentions/archive/master.zip](https://github.com/chrisburnell/eleventy-cache-webmentions/archive/master.zip)
9
9
 
10
- ## Learn more
10
+ ## Documentation
11
11
 
12
- I wrote more about **eleventy-cache-webmentions** here: [https://chrisburnell.com/eleventy-cache-webmentions/](https://chrisburnell.com/eleventy-cache-webmentions/).
12
+ The full **eleventy-cache-webmentions** documentation can be found here: [chrisburnell.com/eleventy-cache-webmentions/](https://chrisburnell.com/eleventy-cache-webmentions/).
13
13
 
14
14
  ## Authors
15
15
 
@@ -3,6 +3,9 @@ const sanitizeHTML = require("sanitize-html")
3
3
  const uniqBy = require("lodash/uniqBy")
4
4
  const { AssetCache } = require("@11ty/eleventy-cache-assets")
5
5
 
6
+ // Load .env variables with dotenv
7
+ require("dotenv").config()
8
+
6
9
  const TOKEN = process.env.WEBMENTION_IO_TOKEN
7
10
 
8
11
  const absoluteURL = (url, domain) => {
@@ -42,7 +45,6 @@ const epoch = (value) => {
42
45
  module.exports = (eleventyConfig, options = {}) => {
43
46
  options = Object.assign(
44
47
  {
45
- duration: "23h",
46
48
  key: "webmentions",
47
49
  allowedHTML: {
48
50
  allowedTags: ["b", "i", "em", "strong", "a"],
@@ -58,7 +60,7 @@ module.exports = (eleventyConfig, options = {}) => {
58
60
  )
59
61
 
60
62
  const fetchWebmentions = async () => {
61
- let asset = new AssetCache(options.key)
63
+ let asset = new AssetCache(options.uniqueKey || options.key)
62
64
  asset.ensureDir()
63
65
 
64
66
  let webmentions = {
@@ -75,7 +77,7 @@ module.exports = (eleventyConfig, options = {}) => {
75
77
  // If there is a cached file but it is outside of expiry, fetch fresh
76
78
  // results since the most recent
77
79
  if (!asset.isCacheValid(options.duration)) {
78
- const since = asset._cache.getKey(options.key) ? asset._cache.getKey(options.key).cachedAt : false
80
+ const since = webmentions.children.length ? webmentions.children[0].published || webmentions.children[0]["wm-received"] : false
79
81
  const url = `https://webmention.io/api/mentions.jf2?domain=${hostname(options.domain)}&token=${TOKEN}&per-page=9001${since ? `&since=${since}` : ``}`
80
82
  await fetch(url)
81
83
  .then(async (response) => {
@@ -91,7 +93,7 @@ module.exports = (eleventyConfig, options = {}) => {
91
93
  return Promise.reject(response)
92
94
  })
93
95
  .catch((error) => {
94
- console.log("[${hostname(options.domain)}] Something went wrong with your request to webmention.io!", error)
96
+ console.log(`[${hostname(options.domain)}] Something went wrong with your request to webmention.io!`, error)
95
97
  })
96
98
  }
97
99
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chrisburnell/eleventy-cache-webmentions",
3
- "version": "0.1.6",
3
+ "version": "0.1.10",
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>",
@@ -17,11 +17,15 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@11ty/eleventy-cache-assets": "^2.3.0",
20
+ "dotenv": "^10.0.0",
20
21
  "lodash": "^4.17.21",
21
22
  "node-fetch": "2.6.5",
22
23
  "sanitize-html": "^2.5.2"
23
24
  },
24
25
  "keywords": [
25
- "eleventy"
26
+ "eleventy",
27
+ "eleventy-plugin",
28
+ "indieweb",
29
+ "webmention"
26
30
  ]
27
31
  }