@chrisburnell/eleventy-cache-webmentions 0.1.1 → 0.1.5
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 +1 -1
- package/eleventy-cache-webmentions.js +16 -14
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# eleventy-cache-assets
|
|
2
2
|
|
|
3
|
-
>
|
|
3
|
+
> Cache webmentions using eleventy-cache-assets and make them available to use in collections, templates, pages, etc.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -41,7 +41,7 @@ const epoch = (value) => {
|
|
|
41
41
|
return new Date(value).getTime()
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
module.exports = (
|
|
44
|
+
module.exports = (eleventyConfig, options = {}) => {
|
|
45
45
|
options = Object.assign(
|
|
46
46
|
{
|
|
47
47
|
duration: "23h",
|
|
@@ -93,7 +93,7 @@ module.exports = (config, options = {}) => {
|
|
|
93
93
|
return Promise.reject(response)
|
|
94
94
|
})
|
|
95
95
|
.catch((error) => {
|
|
96
|
-
console.log("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)
|
|
97
97
|
})
|
|
98
98
|
}
|
|
99
99
|
|
|
@@ -126,7 +126,7 @@ module.exports = (config, options = {}) => {
|
|
|
126
126
|
return webmentions
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
const getWebmentions = async (url, allowedTypes) => {
|
|
129
|
+
const getWebmentions = async (url, allowedTypes = {}) => {
|
|
130
130
|
const webmentions = await filteredWebmentions()
|
|
131
131
|
url = absoluteURL(url, options.domain)
|
|
132
132
|
|
|
@@ -137,7 +137,7 @@ module.exports = (config, options = {}) => {
|
|
|
137
137
|
const results = webmentions[url]
|
|
138
138
|
// filter webmentions by allowed response post types
|
|
139
139
|
.filter((entry) => {
|
|
140
|
-
return
|
|
140
|
+
return typeof allowedTypes === "object" && Object.keys(allowedTypes).length ? allowedTypes.includes(entry["wm-property"]) : true
|
|
141
141
|
})
|
|
142
142
|
// remove webmentions without an author name
|
|
143
143
|
.filter((entry) => {
|
|
@@ -152,8 +152,10 @@ module.exports = (config, options = {}) => {
|
|
|
152
152
|
const { html, text } = entry.content
|
|
153
153
|
if (html && html.length > options.maximumHtmlLength) {
|
|
154
154
|
entry.content.value = `${options.maximumHtmlText} <a href="${entry["wm-source"]}">${entry["wm-source"]}</a>`
|
|
155
|
-
} else {
|
|
155
|
+
} else if (Object.keys(options.allowedHTML).length) {
|
|
156
156
|
entry.content.value = sanitizeHTML(html || text, options.allowedHTML)
|
|
157
|
+
} else {
|
|
158
|
+
entry.content.value = html || text
|
|
157
159
|
}
|
|
158
160
|
return entry
|
|
159
161
|
})
|
|
@@ -166,21 +168,21 @@ module.exports = (config, options = {}) => {
|
|
|
166
168
|
}
|
|
167
169
|
|
|
168
170
|
const getWebmentionsFilter = async (url, allowedTypes, callback) => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
} else {
|
|
173
|
-
return webmentions
|
|
171
|
+
if (typeof callback !== "function") {
|
|
172
|
+
callback = allowedTypes
|
|
173
|
+
allowedTypes = {}
|
|
174
174
|
}
|
|
175
|
+
const webmentions = await getWebmentions(url, allowedTypes)
|
|
176
|
+
callback(null, webmentions)
|
|
175
177
|
}
|
|
176
178
|
|
|
177
|
-
if (
|
|
179
|
+
if (eleventyConfig && options) {
|
|
178
180
|
if (!options.domain) {
|
|
179
|
-
throw new Error("domain is a required option to be passed when adding the plugin to your
|
|
181
|
+
throw new Error("domain is a required option to be passed when adding the plugin to your eleventyConfig using addPlugin.")
|
|
180
182
|
}
|
|
181
183
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
eleventyConfig.addLiquidFilter("getWebmentions", getWebmentionsFilter)
|
|
185
|
+
eleventyConfig.addNunjucksAsyncFilter("getWebmentions", getWebmentionsFilter)
|
|
184
186
|
} else {
|
|
185
187
|
return filteredWebmentions
|
|
186
188
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrisburnell/eleventy-cache-webmentions",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
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"
|