netlify-plugin-submit-sitemap
Advanced tools
Comparing version 0.1.0 to 0.1.1
44
index.js
const url = require('url'); | ||
const fetch = require('node-fetch'); | ||
const { | ||
@@ -24,20 +24,18 @@ CONTEXT, | ||
const submitToProvider = async ({ utils, provider, sitemapUrl }) => { | ||
// Submit sitemap to a provider. Returns either a successful or failed submission, but no error is thrown | ||
const submitToProvider = async ({ provider, sitemapUrl }) => { | ||
if (!providerUrls[provider]) { | ||
console.error(`Provider ${provider} not found!`); | ||
return; | ||
return { message: `Provider ${provider} not found!`, error: 'Invalid provider' }; | ||
} | ||
const providerUrl = providerUrls[provider](sitemapUrl); | ||
const command = `curl -s -o /dev/null --show-error --url ${providerUrl}`; | ||
console.log(`Going to submit sitemap to ${provider} \n * URL: ${providerUrl}`); | ||
console.log(`Going to submit sitemap to ${provider}, URL: ${providerUrl}`); | ||
const { stderr } = await utils.run.command(command); | ||
if (stderr) { | ||
console.log(`\n \u274c ERROR, was not able to submit sitemap to ${provider}`); | ||
return; | ||
try { | ||
await fetch(providerUrl); | ||
} catch (error) { | ||
return { message: `\u274c ERROR, was not able to submit sitemap to ${provider}`, error }; | ||
} | ||
console.log(`\n \u2713 DONE! Sitemap submitted succesfully to ${provider}\n`); | ||
return { message: `\u2713 DONE! Sitemap submitted succesfully to ${provider}` }; | ||
} | ||
@@ -60,3 +58,3 @@ | ||
} | ||
const sitemapUrl = url.resolve(baseUrl, sitemapPath); | ||
const sitemapUrl = (new url.URL(sitemapPath, baseUrl)).href; | ||
@@ -69,6 +67,22 @@ // Only run on production branch | ||
for (const provider of providers) { | ||
await submitToProvider({ utils, provider, sitemapUrl }); | ||
// submit sitemap to all providers | ||
const submissions = await Promise.all( | ||
providers.map(provider => submitToProvider({ provider, sitemapUrl })) | ||
); | ||
const messages = submissions | ||
.map(submission => submission.message) | ||
.join('\n'); | ||
const errors = submissions | ||
.map(submission => submission.error) | ||
.filter(error => error); | ||
// If there was an error in 1 of the submissions, fail the plugin | ||
if (errors.length > 0) { | ||
utils.build.failPlugin(messages, { errors }); | ||
} | ||
utils.status.show({ summary: 'Sitemap submitted successfully', text: messages }); | ||
} | ||
}; |
{ | ||
"name": "netlify-plugin-submit-sitemap", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Automatically submit your sitemap to Google and Bing!", | ||
@@ -19,3 +19,6 @@ "main": "index.js", | ||
"netlify-plugin" | ||
] | ||
], | ||
"dependencies": { | ||
"node-fetch": "^2.6.0" | ||
} | ||
} |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
4458
69
1
1
+ Addednode-fetch@^2.6.0
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)