Skip to content

Commit 29970d8

Browse files
authored
feat(config): Add env option for base url (#60)
1 parent 32b8aa4 commit 29970d8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,11 @@ package = "@netlify/plugin-sitemap"
102102
changeFreq = "daily"
103103
priority = 0.5
104104
```
105+
106+
### Set base URL from environment variable rather than plugin input
107+
108+
You can include an environment variable (`NETLIFY_PLUGIN_SITEMAP_BASEURL`) in your Netlify site to set the base URL that will be used by the plugin. This option is useful if the `baseUrl` plugin input can't be used.
109+
Example use case: different Netlify sites built from the same repository and don't/can't have custom domains.
110+
111+
Priority of base URL assignment:
112+
plugin input `baseUrl` -> env `NETLIFY_PLUGIN_SITEMAP_BASEURL` -> Netlify site default URL

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const getBuildDir = ({ inputs, constants }) => {
1919

2020
module.exports = {
2121
onPostBuild: async ({ constants, inputs, utils }) => {
22-
const baseUrl = inputs.baseUrl || env.URL
22+
const baseUrl = inputs.baseUrl || env.NETLIFY_PLUGIN_SITEMAP_BASEURL || env.URL
2323
const buildDir = getBuildDir({ inputs, constants })
2424

2525
console.log('Creating sitemap from files...')

0 commit comments

Comments
 (0)