netlify-plugin-submit-sitemap
Advanced tools
Comparing version 0.2.3 to 0.3.0
113
index.js
@@ -1,8 +0,7 @@ | ||
const url = require('url'); | ||
const fetch = require('node-fetch'); | ||
const { | ||
CONTEXT, | ||
URL, | ||
} = process.env; | ||
import url from 'url'; | ||
import fetch from 'node-fetch'; | ||
import { isInIgnorePeriod, setLastSubmitTimestamp } from "./helpers.js"; | ||
const { CONTEXT, URL } = process.env; | ||
const providerUrls = { | ||
@@ -56,57 +55,65 @@ 'google': (sitemapUrl) => `https://www.google.com/ping?sitemap=${sitemapUrl}`, | ||
module.exports = { | ||
async onSuccess({ utils, inputs, constants }) { | ||
const { providers, baseUrl, sitemapPath } = { | ||
...defaults, ...removeEmptyValues(inputs) | ||
} | ||
export const onSuccess = async (props) => { | ||
const { utils, inputs, constants } = props | ||
const { providers, baseUrl, sitemapPath } = { | ||
...defaults, ...removeEmptyValues(inputs) | ||
} | ||
// Only run on production builds | ||
if (constants.IS_LOCAL || CONTEXT !== 'production') { | ||
console.log(`Skip submitting sitemap to ${providers.join(', ')}, because this isn't a production build`); | ||
return; | ||
} | ||
// Only run on production builds | ||
if (constants.IS_LOCAL || CONTEXT !== 'production') { | ||
console.log(`Skip submitting sitemap to ${providers.join(', ')}, because this isn't a production build`); | ||
return; | ||
} | ||
let sitemapUrl; | ||
const baseUrlWithScheme = prependScheme(baseUrl); | ||
try { | ||
sitemapUrl = (new url.URL(sitemapPath, baseUrlWithScheme)).href; | ||
} catch(error) { | ||
return utils.build.failPlugin(`Invalid sitemap URL! baseUrl: ${baseUrlWithScheme}, sitemapPath: ${sitemapPath}`, { error }); | ||
} | ||
// Do not run if we are within the ignore period | ||
if (await isInIgnorePeriod(props)) { | ||
console.log(`Skip submitting sitemap, because it's within the ignore period`); | ||
return; | ||
} | ||
// submit sitemap to all providers | ||
const submissions = await Promise.all( | ||
providers.map(provider => submitToProvider({ provider, sitemapUrl })) | ||
); | ||
let sitemapUrl; | ||
const baseUrlWithScheme = prependScheme(baseUrl); | ||
try { | ||
sitemapUrl = (new url.URL(sitemapPath, baseUrlWithScheme)).href; | ||
} catch(error) { | ||
return utils.build.failPlugin(`Invalid sitemap URL! baseUrl: ${baseUrlWithScheme}, sitemapPath: ${sitemapPath}`, { error }); | ||
} | ||
// For failed submissions, it might be better to use something like a utils.build.warn() as discussed here: | ||
// https://github.com/cdeleeuwe/netlify-plugin-submit-sitemap/issues/4 | ||
// But till then, just console.log the errors and fail the plugin. | ||
// --- | ||
// For successful submissions, it's better to use utils.status.show(), but currently Netlify doesn't show | ||
// the status in the UI yet, so also console.log() it for now | ||
// See https://github.com/cdeleeuwe/netlify-plugin-submit-sitemap/issues/5 | ||
submissions.forEach(({ error, message }) => { | ||
if (error) { | ||
console.error('\x1b[31m', message, '\x1b[0m'); | ||
} else { | ||
console.log('\x1b[32m', message, '\x1b[0m'); | ||
} | ||
}); | ||
// 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'); | ||
// For failed submissions, it might be better to use something like a utils.build.warn() as discussed here: | ||
// https://github.com/cdeleeuwe/netlify-plugin-submit-sitemap/issues/4 | ||
// But till then, just console.log the errors and fail the plugin. | ||
// --- | ||
// For successful submissions, it's better to use utils.status.show(), but currently Netlify doesn't show | ||
// the status in the UI yet, so also console.log() it for now | ||
// See https://github.com/cdeleeuwe/netlify-plugin-submit-sitemap/issues/5 | ||
submissions.forEach(({ error, message }) => { | ||
if (error) { | ||
console.error('\x1b[31m', message, '\x1b[0m'); | ||
} else { | ||
console.log('\x1b[32m', message, '\x1b[0m'); | ||
} | ||
}); | ||
const errors = submissions | ||
.map(submission => submission.error) | ||
.filter(error => error); | ||
const messages = submissions | ||
.map(submission => submission.message) | ||
.join('\n'); | ||
// If there was at least 1 error, fail the plugin, but continue the build. | ||
if (errors.length > 0) { | ||
utils.build.failPlugin(`${errors.length} sitemap submission(s) failed`, { error: errors[0] }); | ||
} | ||
const errors = submissions | ||
.map(submission => submission.error) | ||
.filter(error => error); | ||
utils.status.show({ summary: 'Sitemap submitted succesfully', text: messages }); | ||
// If there was at least 1 error, fail the plugin, but continue the build. | ||
if (errors.length > 0) { | ||
utils.build.failPlugin(`${errors.length} sitemap submission(s) failed`, { error: errors[0] }); | ||
return; | ||
} | ||
}; | ||
await setLastSubmitTimestamp(props); | ||
utils.status.show({ summary: 'Sitemap submitted succesfully', text: messages }); | ||
} | ||
{ | ||
"name": "netlify-plugin-submit-sitemap", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"description": "Automatically submit your sitemap to Google, Bing, and Yandex!", | ||
"main": "index.js", | ||
"type": "module", | ||
"repository": { | ||
@@ -21,4 +22,4 @@ "type": "git", | ||
"dependencies": { | ||
"node-fetch": "^2.6.0" | ||
"node-fetch": "^3.2.3" | ||
} | ||
} |
@@ -9,4 +9,6 @@ # Netlify Build Plugin: Automatically submit your sitemap after every production build | ||
To install, add the following lines to your `netlify.toml` file: | ||
You can install this plugin in the Netlify UI from this [direct in-app installation link](https://app.netlify.com/plugins/netlify-plugin-submit-sitemap/install) or from the [Plugins directory](https://app.netlify.com/plugins). | ||
To use file-based installation, add the following lines to your `netlify.toml` file: | ||
```toml | ||
@@ -27,2 +29,5 @@ [build] | ||
# Time in seconds to not submit the sitemap after successful submission | ||
ignorePeriod = 0 | ||
# Enabled providers to submit sitemap to (optional, default = 'google', 'bing', 'yandex'). Possible providers are currently only 'google', 'bing', 'yandex'. | ||
@@ -37,1 +42,11 @@ providers = [ | ||
Note: The `[[plugins]]` line is required for each plugin, even if you have other plugins in your `netlify.toml` file already. | ||
To complete file-based installation, from your project's base directory, use npm, yarn, or any other Node.js package manager to add this plugin to `devDependencies` in `package.json`. | ||
``` | ||
npm install -D netlify-plugin-submit-sitemap | ||
``` | ||
## Notes | ||
- DuckDuckGo is not a supported provider because it currently doesn't offer any manual method where you can enter your sitemap or webpage URLs for indexing; more information can be found [here](https://www.monsterinsights.com/submit-website-to-search-engines/) |
Sorry, the diff of this file is not supported yet
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
8092
5
125
50
Yes
2
+ Addeddata-uri-to-buffer@4.0.1(transitive)
+ Addedfetch-blob@3.2.0(transitive)
+ Addedformdata-polyfill@4.0.10(transitive)
+ Addednode-domexception@1.0.0(transitive)
+ Addednode-fetch@3.3.2(transitive)
+ Addedweb-streams-polyfill@3.3.3(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removedtr46@0.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)
Updatednode-fetch@^3.2.3