Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Netlify Build Plugin: Automatically discover any webmentions and send them after every production build

> **Note:** This is a fork of [CodeFoodPixels/netlify-plugin-webmentions](https://github.com/CodeFoodPixels/netlify-plugin-webmentions) with improved error handling that logs warnings instead of failing the build on timeouts/errors.
>
> To use this fork instead of the npm package (which also overrides the Netlify app plugin):
> ```bash
> npm install -D github:miklb/netlify-plugin-webmentions
> ```
> Then add to `netlify.toml`:
> ```toml
> [[plugins]]
> package = "netlify-plugin-webmentions"
> ```

Automatically discover any webmentions and send them after every production build.

This plugin will send webmentions to any mentioned websites that have a webmention endpoint after every production build. The plugin can be used without any configuration if using the defaults.
Expand Down
57 changes: 31 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,42 @@ module.exports = {
return;
}

try {
await new Promise((resolve, reject) => {
console.log(
`Discovering Webmentions in ${feedUrl} with a limit of ${limit} ${
limit === 1 ? "entry" : "entries"
}`
);
console.log("");
let errorCount = 0;

const wm = new Webmention({ limit, send: true });
await new Promise((resolve) => {
console.log(
`Discovering Webmentions in ${feedUrl} with a limit of ${limit} ${
limit === 1 ? "entry" : "entries"
}`
);
console.log("");

wm.on("error", (e) => reject(e));
const wm = new Webmention({ limit, send: true });

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("error", (e) => {
// Log errors but continue - timeouts shouldn't fail the build
console.log(`Warning: ${e.message || e}`);
errorCount++;
});

wm.on("end", () => {
resolve();
});
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.fetch(feedUrl);
wm.on("end", () => {
if (errorCount > 0) {
console.log(`Completed with ${errorCount} warning(s)`);
}
resolve();
});
} catch (e) {
utils.build.failPlugin(e);
}

wm.fetch(feedUrl);
});
},
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"homepage": "https://github.com/CodeFoodPixels/netlify-plugin-webmentions#readme",
"dependencies": {
"@remy/webmention": "^1.4.5"
"@remy/webmention": "^1.5.0"
},
"devDependencies": {
"prettier": "^2.2.1"
Expand Down