@chrisburnell/eleventy-cache-webmentions 0.1.5 → 0.1.9
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 +3 -3
- package/eleventy-cache-webmentions.js +9 -4
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# eleventy-cache-
|
|
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
|
-
##
|
|
10
|
+
## Documentation
|
|
11
11
|
|
|
12
|
-
|
|
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
|
|
|
@@ -5,6 +5,7 @@ const { AssetCache } = require("@11ty/eleventy-cache-assets")
|
|
|
5
5
|
|
|
6
6
|
// Load .env variables with dotenv
|
|
7
7
|
require("dotenv").config()
|
|
8
|
+
|
|
8
9
|
const TOKEN = process.env.WEBMENTION_IO_TOKEN
|
|
9
10
|
|
|
10
11
|
const absoluteURL = (url, domain) => {
|
|
@@ -44,7 +45,6 @@ const epoch = (value) => {
|
|
|
44
45
|
module.exports = (eleventyConfig, options = {}) => {
|
|
45
46
|
options = Object.assign(
|
|
46
47
|
{
|
|
47
|
-
duration: "23h",
|
|
48
48
|
key: "webmentions",
|
|
49
49
|
allowedHTML: {
|
|
50
50
|
allowedTags: ["b", "i", "em", "strong", "a"],
|
|
@@ -60,7 +60,7 @@ module.exports = (eleventyConfig, options = {}) => {
|
|
|
60
60
|
)
|
|
61
61
|
|
|
62
62
|
const fetchWebmentions = async () => {
|
|
63
|
-
let asset = new AssetCache(options.key)
|
|
63
|
+
let asset = new AssetCache(options.uniqueKey || options.key)
|
|
64
64
|
asset.ensureDir()
|
|
65
65
|
|
|
66
66
|
let webmentions = {
|
|
@@ -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.key) ? asset._cache.getKey(options.key).cachedAt : false
|
|
80
|
+
const since = asset._cache.getKey(options.uniqueKey || options.key) ? asset._cache.getKey(options.uniqueKey || 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
82
|
await fetch(url)
|
|
83
83
|
.then(async (response) => {
|
|
@@ -93,7 +93,7 @@ module.exports = (eleventyConfig, options = {}) => {
|
|
|
93
93
|
return Promise.reject(response)
|
|
94
94
|
})
|
|
95
95
|
.catch((error) => {
|
|
96
|
-
console.log(
|
|
96
|
+
console.log(`[${hostname(options.domain)}] Something went wrong with your request to webmention.io!`, error)
|
|
97
97
|
})
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -181,9 +181,14 @@ module.exports = (eleventyConfig, options = {}) => {
|
|
|
181
181
|
throw new Error("domain is a required option to be passed when adding the plugin to your eleventyConfig using addPlugin.")
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
+
// Liquid/Nunjucks Filters
|
|
184
185
|
eleventyConfig.addLiquidFilter("getWebmentions", getWebmentionsFilter)
|
|
185
186
|
eleventyConfig.addNunjucksAsyncFilter("getWebmentions", getWebmentionsFilter)
|
|
187
|
+
|
|
188
|
+
// Eleventy Data
|
|
189
|
+
eleventyConfig.addGlobalData("webmentions", filteredWebmentions)
|
|
186
190
|
} else {
|
|
191
|
+
// JavaScript
|
|
187
192
|
return filteredWebmentions
|
|
188
193
|
}
|
|
189
194
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrisburnell/eleventy-cache-webmentions",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
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>",
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
"sanitize-html": "^2.5.2"
|
|
24
24
|
},
|
|
25
25
|
"keywords": [
|
|
26
|
-
"eleventy"
|
|
26
|
+
"eleventy",
|
|
27
|
+
"eleventy-plugin",
|
|
28
|
+
"indieweb",
|
|
29
|
+
"webmention"
|
|
27
30
|
]
|
|
28
31
|
}
|