@@ -7,10 +7,14 @@ const externalRedirects = require('./src/data/external-redirects.json');
7
7
const { createFilePath } = require ( 'gatsby-source-filesystem' ) ;
8
8
9
9
const TEMPLATE_DIR = 'src/templates/' ;
10
+ const TRAILING_SLASH = / \/ $ / ;
10
11
11
12
const hasOwnProperty = ( obj , key ) =>
12
13
Object . prototype . hasOwnProperty . call ( obj , key ) ;
13
14
15
+ const hasTrailingSlash = ( pathname ) =>
16
+ pathname === '/' ? false : TRAILING_SLASH . test ( pathname ) ;
17
+
14
18
exports . onPreBootstrap = async ( { reporter, store } ) => {
15
19
reporter . info ( "generating what's new post IDs" ) ;
16
20
const { program } = store . getState ( ) ;
@@ -278,7 +282,7 @@ exports.createResolvers = ({ createResolvers }) => {
278
282
} ;
279
283
280
284
exports . onCreatePage = ( { page, actions } ) => {
281
- const { createPage } = actions ;
285
+ const { createPage, deletePage } = actions ;
282
286
283
287
if ( page . path . match ( / 4 0 4 / ) ) {
284
288
page . context . layout = 'basic' ;
@@ -291,6 +295,18 @@ exports.onCreatePage = ({ page, actions }) => {
291
295
292
296
createPage ( page ) ;
293
297
}
298
+
299
+ if ( hasTrailingSlash ( page . context . slug ) ) {
300
+ deletePage ( page ) ;
301
+
302
+ createPage ( {
303
+ ...page ,
304
+ context : {
305
+ ...page . context ,
306
+ slug : page . context . slug . replace ( TRAILING_SLASH , '' ) ,
307
+ } ,
308
+ } ) ;
309
+ }
294
310
} ;
295
311
296
312
const createPageFromNode = ( node , { createPage, prefix = '' } ) => {
0 commit comments