-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathindex.js
43 lines (36 loc) · 1.41 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* Generates a sitemap */
const { env } = require('process')
const makeSitemap = require('./make_sitemap')
const getInputsDir = ({ inputs }) => inputs.dir || inputs.distPath || inputs.buildDir
const getBuildDir = ({ inputs, constants }) => {
// Backwards compat... Correct opt is buildDir
const buildDir = getInputsDir({ inputs }) || constants.PUBLISH_DIR
// constants.PUBLISH_DIR is always an absolute path
if (buildDir === constants.PUBLISH_DIR) {
return buildDir
}
// remove leading / to treat the dir a a relative one
const trimmedBuildDir = buildDir.startsWith('/') ? buildDir.slice(1) : buildDir
return trimmedBuildDir || '.'
}
module.exports = {
onPostBuild: async ({ constants, inputs, utils }) => {
const baseUrl = inputs.baseUrl || env.NETLIFY_PLUGIN_SITEMAP_BASEURL || env.URL
const urlPrefix = inputs.urlPrefix || env.NETLIFY_PLUGIN_SITEMAP_URL_PREFIX || null
const buildDir = getBuildDir({ inputs, constants })
console.log('Creating sitemap from files...')
const data = await makeSitemap({
fileName: inputs.filePath,
homepage: baseUrl,
distPath: buildDir,
exclude: inputs.exclude,
prettyURLs: inputs.prettyURLs,
changeFreq: inputs.changeFreq,
priority: inputs.priority,
trailingSlash: inputs.trailingSlash,
failBuild: utils.build.failBuild,
urlPrefix,
})
console.log('Sitemap Built!', data.sitemapPath)
},
}