@chrisburnell/eleventy-cache-webmentions 0.1.3 → 0.1.7
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.
|
@@ -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) => {
|
|
@@ -41,7 +42,7 @@ const epoch = (value) => {
|
|
|
41
42
|
return new Date(value).getTime()
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
module.exports = (
|
|
45
|
+
module.exports = (eleventyConfig, options = {}) => {
|
|
45
46
|
options = Object.assign(
|
|
46
47
|
{
|
|
47
48
|
duration: "23h",
|
|
@@ -93,7 +94,7 @@ module.exports = (config, options = {}) => {
|
|
|
93
94
|
return Promise.reject(response)
|
|
94
95
|
})
|
|
95
96
|
.catch((error) => {
|
|
96
|
-
console.log(
|
|
97
|
+
console.log(`[${hostname(options.domain)}] Something went wrong with your request to webmention.io!`, error)
|
|
97
98
|
})
|
|
98
99
|
}
|
|
99
100
|
|
|
@@ -152,8 +153,10 @@ module.exports = (config, options = {}) => {
|
|
|
152
153
|
const { html, text } = entry.content
|
|
153
154
|
if (html && html.length > options.maximumHtmlLength) {
|
|
154
155
|
entry.content.value = `${options.maximumHtmlText} <a href="${entry["wm-source"]}">${entry["wm-source"]}</a>`
|
|
155
|
-
} else {
|
|
156
|
+
} else if (Object.keys(options.allowedHTML).length) {
|
|
156
157
|
entry.content.value = sanitizeHTML(html || text, options.allowedHTML)
|
|
158
|
+
} else {
|
|
159
|
+
entry.content.value = html || text
|
|
157
160
|
}
|
|
158
161
|
return entry
|
|
159
162
|
})
|
|
@@ -174,14 +177,19 @@ module.exports = (config, options = {}) => {
|
|
|
174
177
|
callback(null, webmentions)
|
|
175
178
|
}
|
|
176
179
|
|
|
177
|
-
if (
|
|
180
|
+
if (eleventyConfig && options) {
|
|
178
181
|
if (!options.domain) {
|
|
179
|
-
throw new Error("domain is a required option to be passed when adding the plugin to your
|
|
182
|
+
throw new Error("domain is a required option to be passed when adding the plugin to your eleventyConfig using addPlugin.")
|
|
180
183
|
}
|
|
181
184
|
|
|
182
|
-
|
|
183
|
-
|
|
185
|
+
// Liquid/Nunjucks Filters
|
|
186
|
+
eleventyConfig.addLiquidFilter("getWebmentions", getWebmentionsFilter)
|
|
187
|
+
eleventyConfig.addNunjucksAsyncFilter("getWebmentions", getWebmentionsFilter)
|
|
188
|
+
|
|
189
|
+
// Eleventy Data
|
|
190
|
+
eleventyConfig.addGlobalData("webmentions", filteredWebmentions)
|
|
184
191
|
} else {
|
|
192
|
+
// JavaScript
|
|
185
193
|
return filteredWebmentions
|
|
186
194
|
}
|
|
187
195
|
}
|
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.7",
|
|
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>",
|