-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79fe10d
commit 2126c4d
Showing
4 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
User-agent: * | ||
Disallow: / |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const publicPath = path.join(__dirname, 'public'); | ||
|
||
function generateRobotsTxt() { | ||
console.log('VERCEL_ENV: ', process.env.VERCEL_ENV); | ||
const isCrawlable = process.env.VERCEL_ENV === 'production'; | ||
// Create a non-crawlable robots.txt in non-production environments | ||
const sourceFile = path.join( | ||
publicPath, | ||
isCrawlable ? 'crawlable.txt' : 'noncrawlable.txt', | ||
); | ||
const destFile = path.join(publicPath, 'robots.txt'); | ||
|
||
try { | ||
// Create robots.txt file | ||
fs.copyFileSync(sourceFile, destFile); | ||
console.log( | ||
`Generated a ${ | ||
isCrawlable ? 'crawlable' : 'non-crawlable' | ||
} public/robots.txt`, | ||
); | ||
} catch (error) { | ||
console.log(`Cannot Generate a public/robots.txt`); | ||
} | ||
} | ||
|
||
module.exports = generateRobotsTxt; |