-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
57 lines (49 loc) · 1.47 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const Webmention = require("@remy/webmention");
const {
CONTEXT,
URL,
WEBMENTION_LIMIT,
WEBMENTION_FEED_PATH,
WEBMENTION_BASE_URL,
} = process.env;
module.exports = {
async onSuccess({ utils, constants, inputs }) {
const limit = inputs.limit || WEBMENTION_LIMIT || 1;
const feedPath = inputs.feedPath || WEBMENTION_FEED_PATH || "feed.xml";
const baseUrl = inputs.baseUrl || WEBMENTION_BASE_URL || URL;
const feedUrl = `${baseUrl.replace(/\$/, "")}/${feedPath}`;
if (constants.IS_LOCAL || CONTEXT !== "production") {
console.log(
"Skipping discovering webmentions because this isn't a production build"
);
return;
}
try {
await new Promise((resolve, reject) => {
console.log(
`Discovering Webmentions in ${feedUrl} with a limit of ${limit} ${
limit === 1 ? "entry" : "entries"
}`
);
console.log("");
const wm = new Webmention({ limit, send: true });
wm.on("error", (e) => reject(e));
wm.on("sent", (res) => {
console.log(
`Sent ${res.source} to ${res.endpoint.url} (${res.endpoint.type})`
);
if (res.error) {
console.log(`Error sending to ${res.endpoint.url}: ${res.error}`);
}
console.log("");
});
wm.on("end", () => {
resolve();
});
wm.fetch(feedUrl);
});
} catch (e) {
utils.build.failPlugin(e);
}
},
};