diff --git a/README.md b/README.md index bee513c..0b059c3 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/index.js b/index.js index 2eb5bc5..188b680 100644 --- a/index.js +++ b/index.js @@ -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); + }); }, }; diff --git a/package.json b/package.json index 2260784..05d469e 100644 --- a/package.json +++ b/package.json @@ -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"