mirror of
https://github.com/fabe/gatsby-starter-deck.git
synced 2024-09-11 03:55:26 +03:00
22 lines
591 B
JavaScript
22 lines
591 B
JavaScript
// Implement the Gatsby API “onCreatePage”. This is
|
|
// called after every page is created.
|
|
exports.onCreatePage = ({ page, boundActionCreators }) => {
|
|
const { createPage, deletePage } = boundActionCreators;
|
|
|
|
return new Promise((resolve, reject) => {
|
|
// Remove trailing slash
|
|
const newPage = Object.assign({}, page, {
|
|
path: page.path === `/` ? page.path : page.path.replace(/\/$/, ``),
|
|
});
|
|
|
|
if (newPage.path !== page.path) {
|
|
// Remove the old page
|
|
deletePage(page);
|
|
// Add the new page
|
|
createPage(newPage);
|
|
}
|
|
|
|
resolve();
|
|
});
|
|
};
|