@chrisburnell/eleventy-cache-webmentions 2.1.3-beta.2 → 2.1.3
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 +6 -0
- package/eleventy-cache-webmentions.js +14 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -82,6 +82,12 @@ Make sure you get the correct values for this configuration. Check below for bot
|
|
|
82
82
|
<td>See <a href="https://www.11ty.dev/docs/plugins/cache/#cache-directory">Eleventy Fetch’s Cache Directory</a> for more information.</td>
|
|
83
83
|
<td>1.1.2</td>
|
|
84
84
|
</tr>
|
|
85
|
+
<tr>
|
|
86
|
+
<td><code>refresh</code></td>
|
|
87
|
+
<td><code>false</code></td>
|
|
88
|
+
<td>Forces fresh results from the Webmention endpoint every time.</td>
|
|
89
|
+
<td>2.1.3</td>
|
|
90
|
+
</tr>
|
|
85
91
|
<tr>
|
|
86
92
|
<td><code>duration</code></td>
|
|
87
93
|
<td><code>"1d"</code> <em>or</em> 1 day</td>
|
|
@@ -55,8 +55,8 @@ const getReceived = (webmention) => {
|
|
|
55
55
|
return (
|
|
56
56
|
webmention["wm-received"] ||
|
|
57
57
|
webmention["verified_date"] ||
|
|
58
|
-
webmention
|
|
59
|
-
webmention["published"]
|
|
58
|
+
webmention["published"] ||
|
|
59
|
+
webmention?.["data"]?.["published"]
|
|
60
60
|
);
|
|
61
61
|
};
|
|
62
62
|
|
|
@@ -94,7 +94,7 @@ const getType = (webmention) => {
|
|
|
94
94
|
|
|
95
95
|
const getByType = (webmentions, allowedType) => {
|
|
96
96
|
return webmentions.filter((webmention) => {
|
|
97
|
-
return
|
|
97
|
+
return allowedType === getType(webmention);
|
|
98
98
|
});
|
|
99
99
|
};
|
|
100
100
|
|
|
@@ -105,6 +105,7 @@ const getByTypes = (webmentions, allowedTypes) => {
|
|
|
105
105
|
};
|
|
106
106
|
|
|
107
107
|
const defaults = {
|
|
108
|
+
refresh: false,
|
|
108
109
|
duration: "1d",
|
|
109
110
|
uniqueKey: "webmentions",
|
|
110
111
|
allowedHTML: {
|
|
@@ -219,8 +220,9 @@ const fetchWebmentions = async (options) => {
|
|
|
219
220
|
|
|
220
221
|
let webmentions = [];
|
|
221
222
|
|
|
222
|
-
//
|
|
223
|
-
|
|
223
|
+
// Unless specifically getting fresh Webmentions, if there is a cached file
|
|
224
|
+
// at all, grab its contents now
|
|
225
|
+
if (asset.isCacheValid("9001y") && !options.refresh) {
|
|
224
226
|
webmentions = await asset.getCachedValue();
|
|
225
227
|
}
|
|
226
228
|
|
|
@@ -230,7 +232,7 @@ const fetchWebmentions = async (options) => {
|
|
|
230
232
|
|
|
231
233
|
// If there is a cached file but it is outside of expiry, fetch fresh
|
|
232
234
|
// results since the most recent Webmention
|
|
233
|
-
if (!asset.isCacheValid("
|
|
235
|
+
if (!asset.isCacheValid(options.refresh ? "0s" : options.duration)) {
|
|
234
236
|
// Get the received date of the most recent Webmention, if it exists
|
|
235
237
|
const since = webmentions.length ? getReceived(webmentions[0]) : false;
|
|
236
238
|
// Build the URL for the fetch request
|
|
@@ -242,13 +244,16 @@ const fetchWebmentions = async (options) => {
|
|
|
242
244
|
|
|
243
245
|
// If using webmention.io, loop through pages until no results found
|
|
244
246
|
if (url.includes("https://webmention.io")) {
|
|
247
|
+
const urlObject = new URL(url);
|
|
248
|
+
const perPage =
|
|
249
|
+
Number(urlObject.searchParams.get("per-page")) || 1000;
|
|
250
|
+
urlObject.searchParams.delete("per-page");
|
|
245
251
|
// Start on page 0, to increment per subsequent request
|
|
246
252
|
let page = 0;
|
|
247
253
|
// Loop until a break condition is hit
|
|
248
254
|
while (true) {
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
const urlPaginated = url + `&per-page=${perPage}&page=${page}`;
|
|
255
|
+
const urlPaginated =
|
|
256
|
+
urlObject.href + `&per-page=${perPage}&page=${page}`;
|
|
252
257
|
const fetched = await performFetch(
|
|
253
258
|
options,
|
|
254
259
|
webmentions,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chrisburnell/eleventy-cache-webmentions",
|
|
3
|
-
"version": "2.1.3
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "Cache webmentions using eleventy-fetch and make them available to use in collections, layouts, pages, etc. in Eleventy.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|