Skip to content

Commit 75dd98b

Browse files
authored
Merge pull request newrelic#684 from newrelic/jerel/data-dictionary-nav
Fix attribute dictionary nav
2 parents 30d08ed + 8b02771 commit 75dd98b

File tree

4 files changed

+90
-107
lines changed

4 files changed

+90
-107
lines changed

gatsby-node.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ const externalRedirects = require('./src/data/external-redirects.json');
77
const { createFilePath } = require('gatsby-source-filesystem');
88

99
const TEMPLATE_DIR = 'src/templates/';
10+
const TRAILING_SLASH = /\/$/;
1011

1112
const hasOwnProperty = (obj, key) =>
1213
Object.prototype.hasOwnProperty.call(obj, key);
1314

15+
const hasTrailingSlash = (pathname) =>
16+
pathname === '/' ? false : TRAILING_SLASH.test(pathname);
17+
1418
exports.onPreBootstrap = async ({ reporter, store }) => {
1519
reporter.info("generating what's new post IDs");
1620
const { program } = store.getState();
@@ -278,7 +282,7 @@ exports.createResolvers = ({ createResolvers }) => {
278282
};
279283

280284
exports.onCreatePage = ({ page, actions }) => {
281-
const { createPage } = actions;
285+
const { createPage, deletePage } = actions;
282286

283287
if (page.path.match(/404/)) {
284288
page.context.layout = 'basic';
@@ -291,6 +295,18 @@ exports.onCreatePage = ({ page, actions }) => {
291295

292296
createPage(page);
293297
}
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+
}
294310
};
295311

296312
const createPageFromNode = (node, { createPage, prefix = '' }) => {

0 commit comments

Comments
 (0)