Skip to content

Commit d94c8e4

Browse files
LekoArtspiehmarvinjudetyhoppgatsbybot
authored
feat(gatsby): trailingSlash config option (#34268)
Co-authored-by: Michal Piechowiak <[email protected]> Co-authored-by: Jude Agboola <[email protected]> Co-authored-by: Ty Hopp <[email protected]> Co-authored-by: gatsbybot <[email protected]>
1 parent e97dc80 commit d94c8e4

File tree

81 files changed

+2340
-90
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2340
-90
lines changed

.circleci/config.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,19 @@ jobs:
467467
- store_test_results:
468468
path: e2e-tests/contentful/cypress/results
469469

470+
e2e_tests_trailing-slash:
471+
<<: *e2e-executor
472+
environment:
473+
<<: *e2e-executor-env
474+
CYPRESS_PROJECT_ID: ofxgw8
475+
CYPRESS_RECORD_KEY: 29c32742-6b85-40e0-9b45-a4c722749d52
476+
steps:
477+
- e2e-test:
478+
test_path: e2e-tests/trailing-slash
479+
test_command: yarn test
480+
- store_test_results:
481+
path: e2e-tests/trailing-slash/cypress/results
482+
470483
starters_validate:
471484
executor: node
472485
steps:
@@ -669,6 +682,8 @@ workflows:
669682
<<: *e2e-test-workflow
670683
- e2e_tests_contentful:
671684
<<: *e2e-test-workflow
685+
- e2e_tests_trailing-slash:
686+
<<: *e2e-test-workflow
672687
- e2e_tests_development_runtime:
673688
<<: *e2e-test-workflow
674689
- e2e_tests_production_runtime:

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ module.exports = {
3838
__ASSET_PREFIX__: true,
3939
_CFLAGS_: true,
4040
__GATSBY: true,
41+
__TRAILING_SLASH__: true,
4142
},
4243
rules: {
4344
"@babel/no-unused-expressions": [

docs/docs/reference/config-files/gatsby-config.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,16 @@ module.exports = {
4242
Options available to set within `gatsby-config.js` include:
4343

4444
1. [siteMetadata](#sitemetadata) (object)
45-
2. [plugins](#plugins) (array)
46-
3. [flags](#flags) (object)
47-
4. [pathPrefix](#pathprefix) (string)
48-
5. [polyfill](#polyfill) (boolean)
49-
6. [mapping](#mapping-node-types) (object)
50-
7. [proxy](#proxy) (object)
51-
8. [developMiddleware](#advanced-proxying-with-developmiddleware) (function)
45+
1. [plugins](#plugins) (array)
46+
1. [flags](#flags) (object)
47+
1. [pathPrefix](#pathprefix) (string)
48+
1. [trailingSlash](#trailingslash) (string)
49+
1. [polyfill](#polyfill) (boolean)
50+
1. [mapping](#mapping-node-types) (object)
51+
1. [proxy](#proxy) (object)
52+
1. [developMiddleware](#advanced-proxying-with-developmiddleware) (function)
53+
1. [jsxRuntime](#jsxruntime) (string)
54+
1. [jsxImportSource](#jsximportsource) (string)
5255

5356
## siteMetadata
5457

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

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

71-
## Plugins
74+
## plugins
7275

7376
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).
7477

@@ -135,7 +138,7 @@ module.exports = {
135138

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

138-
## Flags
141+
## flags
139142

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

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

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

164-
## Polyfill
167+
## trailingSlash
168+
169+
Configures the creation of URLs and whether to remove, append, or ignore trailing slashes.
170+
171+
- `always`: Always add trailing slashes to each URL, e.g. `/x` to `/x/`.
172+
- `never`: Remove all trailing slashes on each URL, e.g. `/x/` to `/x`.
173+
- `ignore`: Don't automatically modify the URL
174+
175+
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).
176+
177+
## polyfill
165178

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

e2e-tests/trailing-slash/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Project dependencies
2+
.cache
3+
node_modules
4+
yarn-error.log
5+
6+
# Build assets
7+
/public
8+
.DS_Store
9+
/assets
10+
11+
# Cypress output
12+
cypress/videos/
13+
cypress/screenshots/

e2e-tests/trailing-slash/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# trailing-slash E2E Test
2+
3+
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.
4+
5+
Locally you can run for development:
6+
7+
```shell
8+
TRAILING_SLASH=your-option yarn debug:develop
9+
```
10+
11+
And for a build + serve:
12+
13+
```shell
14+
TRAILING_SLASH=your-option yarn build && yarn debug:build
15+
```
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"videoUploadOnPasses": false,
3+
"chromeWebSecurity": false,
4+
"testFiles": ["always.js", "functions.js", "static.js"]
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"videoUploadOnPasses": false,
3+
"chromeWebSecurity": false,
4+
"testFiles": ["ignore.js", "functions.js", "static.js"]
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"videoUploadOnPasses": false,
3+
"chromeWebSecurity": false,
4+
"testFiles": ["legacy.js", "functions.js", "static.js"]
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"videoUploadOnPasses": false,
3+
"chromeWebSecurity": false,
4+
"testFiles": ["never.js", "functions.js", "static.js"]
5+
}

e2e-tests/trailing-slash/cypress.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"videoUploadOnPasses": false,
3+
"chromeWebSecurity": false
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "[email protected]",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

0 commit comments

Comments
 (0)