@chrisburnell/eleventy-cache-webmentions 0.1.2 → 0.1.6
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.
|
@@ -3,8 +3,6 @@ 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
|
const TOKEN = process.env.WEBMENTION_IO_TOKEN
|
|
9
7
|
|
|
10
8
|
const absoluteURL = (url, domain) => {
|
|
@@ -41,7 +39,7 @@ const epoch = (value) => {
|
|
|
41
39
|
return new Date(value).getTime()
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
module.exports = (
|
|
42
|
+
module.exports = (eleventyConfig, options = {}) => {
|
|
45
43
|
options = Object.assign(
|
|
46
44
|
{
|
|
47
45
|
duration: "23h",
|
|
@@ -152,8 +150,10 @@ module.exports = (config, options = {}) => {
|
|
|
152
150
|
const { html, text } = entry.content
|
|
153
151
|
if (html && html.length > options.maximumHtmlLength) {
|
|
154
152
|
entry.content.value = `${options.maximumHtmlText} <a href="${entry["wm-source"]}">${entry["wm-source"]}</a>`
|
|
155
|
-
} else {
|
|
153
|
+
} else if (Object.keys(options.allowedHTML).length) {
|
|
156
154
|
entry.content.value = sanitizeHTML(html || text, options.allowedHTML)
|
|
155
|
+
} else {
|
|
156
|
+
entry.content.value = html || text
|
|
157
157
|
}
|
|
158
158
|
return entry
|
|
159
159
|
})
|
|
@@ -174,14 +174,19 @@ module.exports = (config, options = {}) => {
|
|
|
174
174
|
callback(null, webmentions)
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
if (
|
|
177
|
+
if (eleventyConfig && options) {
|
|
178
178
|
if (!options.domain) {
|
|
179
|
-
throw new Error("domain is a required option to be passed when adding the plugin to your
|
|
179
|
+
throw new Error("domain is a required option to be passed when adding the plugin to your eleventyConfig using addPlugin.")
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
// Liquid/Nunjucks Filters
|
|
183
|
+
eleventyConfig.addLiquidFilter("getWebmentions", getWebmentionsFilter)
|
|
184
|
+
eleventyConfig.addNunjucksAsyncFilter("getWebmentions", getWebmentionsFilter)
|
|
185
|
+
|
|
186
|
+
// Eleventy Data
|
|
187
|
+
eleventyConfig.addGlobalData("webmentions", filteredWebmentions)
|
|
184
188
|
} else {
|
|
189
|
+
// JavaScript
|
|
185
190
|
return filteredWebmentions
|
|
186
191
|
}
|
|
187
192
|
}
|
package/package.json
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrisburnell/eleventy-cache-webmentions",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
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>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
10
|
-
"url": "git@github.com:chrisburnell/
|
|
10
|
+
"url": "git@github.com:chrisburnell/eleventy-cache-webmentions.git"
|
|
11
11
|
},
|
|
12
12
|
"bugs": {
|
|
13
|
-
"url": "https://github.com/chrisburnell/
|
|
13
|
+
"url": "https://github.com/chrisburnell/eleventy-cache-webmentions/issues"
|
|
14
14
|
},
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=10"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@11ty/eleventy-cache-assets": "^2.3.0",
|
|
20
|
-
"dotenv": "^10.0.0",
|
|
21
20
|
"lodash": "^4.17.21",
|
|
22
21
|
"node-fetch": "2.6.5",
|
|
23
22
|
"sanitize-html": "^2.5.2"
|