Skip to content

Commit

Permalink
feat: add support of configFile-option (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdreizin committed Jul 23, 2018
1 parent 7eb4712 commit f64ff31
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
44 changes: 39 additions & 5 deletions README.md
Expand Up @@ -37,11 +37,12 @@ module.exports = {

This plugin uses [`generate-robotstxt`](https://github.com/itgalaxy/generate-robotstxt#usage) to generate content of `robots.txt` and it has the following options:

| Name | Type | Default | Description |
| :-------: | :--------: | :-----------------------------------: | :--------------------: |
| `host` | `String` | `${siteMetadata.siteUrl}` | Host of your site |
| `sitemap` | `String` | `${siteMetadata.siteUrl}/sitemap.xml` | Path to `sitemap.xml` |
| `policy` | `Policy[]` | `[]` | List of [`Policy`](https://github.com/itgalaxy/generate-robotstxt#usage) rules |
| Name | Type | Default | Description |
| :----------: | :--------: | :-----------------------------------: | :----------------------------------------------------------------------------: |
| `host` | `String` | `${siteMetadata.siteUrl}` | Host of your site |
| `sitemap` | `String` | `${siteMetadata.siteUrl}/sitemap.xml` | Path to `sitemap.xml` |
| `policy` | `Policy[]` | `[]` | List of [`Policy`](https://github.com/itgalaxy/generate-robotstxt#usage) rules |
| `configFile` | `String` | `undefined` | Path to external config file |

`gatsby-config.js`

Expand All @@ -64,6 +65,8 @@ module.exports = {

You can use the `env` option to set specific options in specific environment:

`gatsby-config.js`

```js
module.exports = {
plugins: [
Expand All @@ -90,6 +93,8 @@ The `env` key will be taken from `process.env.NODE_ENV`, when this is not availa

You can resolve the `env` key by using `resolveEnv` function:

`gatsby-config.js`

```js
module.exports = {
plugins: [
Expand All @@ -113,6 +118,35 @@ module.exports = {
};
```

### `configFile`-option

You can use the `configFile` option to set specific external configuration:

`gatsby-config.js`

```js
module.exports = {
plugins: [
{
resolve: 'gatsby-plugin-robots-txt',
options: {
host: 'https://www.example.com',
sitemap: 'https://www.example.com/sitemap.xml',
configFile: 'robots-txt.config.js'
}
}
]
};
```

`robots-txt.config.js`

```js
module.exports = {
policy: [{ userAgent: '*' }]
};
```

#### Netlify

If you would like to disable crawlers for [deploy-previews](https://www.netlify.com/blog/2016/07/20/introducing-deploy-previews-in-netlify/) you can use the following snippet:
Expand Down
5 changes: 3 additions & 2 deletions src/gatsby-node.js
Expand Up @@ -74,12 +74,13 @@ export async function onPostBuild({ graphql }, pluginOptions) {
mergedOptions.sitemap = url.resolve(siteUrl, 'sitemap.xml');
}

const { policy, sitemap, host, output } = mergedOptions;
const { policy, sitemap, host, output, configFile } = mergedOptions;

const content = await robotsTxt({
policy,
sitemap,
host
host,
configFile
});
const filename = path.join(publicPath, output);

Expand Down

0 comments on commit f64ff31

Please sign in to comment.