-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (23 loc) · 821 Bytes
/
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
const path = require('path')
const url = require( 'url' )
const fs = require('fs')
const generateRobotsTxt = require('generate-robotstxt')
module.exports = (api, options) => {
api.afterBuild(async ({ queue, config }) => {
if (!config.siteUrl && !options.host) {
throw new Error(`Robots Txt plugin is missing a required siteUrl or host config.`)
}
let { host, sitemap, policy, output } = options
if (!host) host = config.siteUrl
if (!sitemap) sitemap = url.resolve(host, 'sitemap.xml')
const robotsTxt = await generateRobotsTxt({ policy, sitemap, host })
const filename = path.join(config.outputDir, options.output)
return fs.writeFileSync(filename, robotsTxt)
})
}
module.exports.defaultOptions = () => ({
host: '',
sitemap: '',
policy: [],
output: 'robots.txt'
})