Skip to content

Commit

Permalink
feat(gatsby): trailingSlash config option (#34268)
Browse files Browse the repository at this point in the history
Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
Co-authored-by: Jude Agboola <marvinjudehk@gmail.com>
Co-authored-by: Ty Hopp <tyhopp@users.noreply.github.com>
Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
  • Loading branch information
5 people authored Jan 28, 2022
1 parent e97dc80 commit d94c8e4
Show file tree
Hide file tree
Showing 81 changed files with 2,340 additions and 90 deletions.
15 changes: 15 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,19 @@ jobs:
- store_test_results:
path: e2e-tests/contentful/cypress/results

e2e_tests_trailing-slash:
<<: *e2e-executor
environment:
<<: *e2e-executor-env
CYPRESS_PROJECT_ID: ofxgw8
CYPRESS_RECORD_KEY: 29c32742-6b85-40e0-9b45-a4c722749d52
steps:
- e2e-test:
test_path: e2e-tests/trailing-slash
test_command: yarn test
- store_test_results:
path: e2e-tests/trailing-slash/cypress/results

starters_validate:
executor: node
steps:
Expand Down Expand Up @@ -669,6 +682,8 @@ workflows:
<<: *e2e-test-workflow
- e2e_tests_contentful:
<<: *e2e-test-workflow
- e2e_tests_trailing-slash:
<<: *e2e-test-workflow
- e2e_tests_development_runtime:
<<: *e2e-test-workflow
- e2e_tests_production_runtime:
Expand Down
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
__ASSET_PREFIX__: true,
_CFLAGS_: true,
__GATSBY: true,
__TRAILING_SLASH__: true,
},
rules: {
"@babel/no-unused-expressions": [
Expand Down
33 changes: 23 additions & 10 deletions docs/docs/reference/config-files/gatsby-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ module.exports = {
Options available to set within `gatsby-config.js` include:

1. [siteMetadata](#sitemetadata) (object)
2. [plugins](#plugins) (array)
3. [flags](#flags) (object)
4. [pathPrefix](#pathprefix) (string)
5. [polyfill](#polyfill) (boolean)
6. [mapping](#mapping-node-types) (object)
7. [proxy](#proxy) (object)
8. [developMiddleware](#advanced-proxying-with-developmiddleware) (function)
1. [plugins](#plugins) (array)
1. [flags](#flags) (object)
1. [pathPrefix](#pathprefix) (string)
1. [trailingSlash](#trailingslash) (string)
1. [polyfill](#polyfill) (boolean)
1. [mapping](#mapping-node-types) (object)
1. [proxy](#proxy) (object)
1. [developMiddleware](#advanced-proxying-with-developmiddleware) (function)
1. [jsxRuntime](#jsxruntime) (string)
1. [jsxImportSource](#jsximportsource) (string)

## siteMetadata

Expand All @@ -68,7 +71,7 @@ This way you can store it in one place, and pull it whenever you need it. If you

See a full description and sample usage in [Gatsby.js Tutorial Part Four](/docs/tutorial/part-4/#data-in-gatsby).

## Plugins
## plugins

Plugins are Node.js packages that implement Gatsby APIs. The config file accepts an array of plugins. Some plugins may need only to be listed by name, while others may take options (see the docs for individual plugins).

Expand Down Expand Up @@ -135,7 +138,7 @@ module.exports = {

See more about [Plugins](/docs/plugins/) for more on utilizing plugins, and to see available official and community plugins.

## Flags
## flags

Flags let sites enable experimental or upcoming changes that are still in testing or waiting for the next major release.

Expand All @@ -161,7 +164,17 @@ module.exports = {

See more about [Adding a Path Prefix](/docs/how-to/previews-deploys-hosting/path-prefix/).

## Polyfill
## trailingSlash

Configures the creation of URLs and whether to remove, append, or ignore trailing slashes.

- `always`: Always add trailing slashes to each URL, e.g. `/x` to `/x/`.
- `never`: Remove all trailing slashes on each URL, e.g. `/x/` to `/x`.
- `ignore`: Don't automatically modify the URL

Until Gatsby v4 it'll be set to `legacy` by default, in Gatsby v5 the default mode will be `always`. Gatsby Cloud automatically handles and supports the `trailingSlash` option, any other hosting provider (or if you're managing this on your own) should follow the "Redirects, and expected behavior from the hosting provider" section on the [initial RFC](https://github.com/gatsbyjs/gatsby/discussions/34205).

## polyfill

Gatsby uses the ES6 Promise API. Because some browsers don't support this, Gatsby includes a Promise polyfill by default.

Expand Down
13 changes: 13 additions & 0 deletions e2e-tests/trailing-slash/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Project dependencies
.cache
node_modules
yarn-error.log

# Build assets
/public
.DS_Store
/assets

# Cypress output
cypress/videos/
cypress/screenshots/
15 changes: 15 additions & 0 deletions e2e-tests/trailing-slash/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# trailing-slash E2E Test

This Cypress suite tests the `trailingSlash` option inside `gatsby-config` and its various different settings it takes. When you want to work on it, start watching packages inside the `packages` and start `gatsby-dev-cli` in this E2E test suite.

Locally you can run for development:

```shell
TRAILING_SLASH=your-option yarn debug:develop
```

And for a build + serve:

```shell
TRAILING_SLASH=your-option yarn build && yarn debug:build
```
5 changes: 5 additions & 0 deletions e2e-tests/trailing-slash/cypress-always.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"videoUploadOnPasses": false,
"chromeWebSecurity": false,
"testFiles": ["always.js", "functions.js", "static.js"]
}
5 changes: 5 additions & 0 deletions e2e-tests/trailing-slash/cypress-ignore.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"videoUploadOnPasses": false,
"chromeWebSecurity": false,
"testFiles": ["ignore.js", "functions.js", "static.js"]
}
5 changes: 5 additions & 0 deletions e2e-tests/trailing-slash/cypress-legacy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"videoUploadOnPasses": false,
"chromeWebSecurity": false,
"testFiles": ["legacy.js", "functions.js", "static.js"]
}
5 changes: 5 additions & 0 deletions e2e-tests/trailing-slash/cypress-never.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"videoUploadOnPasses": false,
"chromeWebSecurity": false,
"testFiles": ["never.js", "functions.js", "static.js"]
}
4 changes: 4 additions & 0 deletions e2e-tests/trailing-slash/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"videoUploadOnPasses": false,
"chromeWebSecurity": false
}
5 changes: 5 additions & 0 deletions e2e-tests/trailing-slash/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
Loading

0 comments on commit d94c8e4

Please sign in to comment.