-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathrobots.js
More file actions
25 lines (24 loc) · 775 Bytes
/
robots.js
File metadata and controls
25 lines (24 loc) · 775 Bytes
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
import files from './files'
import project, { generateBase } from './project'
export default function generateRobots() {
if (files['robots.txt']) return files['robots.txt']
const lines = []
lines.push('User-Agent: *')
if (!project.disallow.includes('/')) {
lines.push(`Allow: ${project.root}`)
}
for (const path of project.disallow) {
lines.push(`Disallow: ${path}`)
}
if (project.sitemap) {
if (project.sitemap === true) {
lines.push(`Sitemap: ${generateBase()}/sitemap.xml`)
} else if (project.sitemap.indexOf('//') === -1) {
lines.push(`Sitemap: ${generateBase()}${project.sitemap}`)
} else {
lines.push(`Sitemap: ${project.sitemap}`)
}
}
files['robots.txt'] = lines.join(`\n`)
return files['robots.txt']
}