Skip to content

Commit

Permalink
fix: set correct slug for each page node in gatsby
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenmacdonald committed Dec 16, 2024
1 parent f67d1f7 commit 2ae234d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions www/utils/onCreateNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ function onCreateNode(node, actions, getNode) {
.split('README')[0]
.toLowerCase();

const isChangelogNode = node.fileAbsolutePath && node.fileAbsolutePath.endsWith('CHANGELOG.md');
// Is this node (page) a page about a Paragon component, from src/**/.md(x),
// or (when false) is it one of the .mdx/.tsx files in www/src/ ?
const isChangelog = node.internal.contentFilePath.endsWith('CHANGELOG.md');
const isComponentPageNode = !node.internal.contentFilePath.includes('www/src/');
const slug = (/* eslint-disable */
isChangelog ? '/changelog/' :
isComponentPageNode ? `/components${value}` :
value
);/* eslint-enable */

createNodeField({
// Name of the field you are adding
Expand All @@ -20,7 +28,7 @@ function onCreateNode(node, actions, getNode) {
// Generated value based on filepath with 'components' prefix. you
// don't need a separating '/' before the value because
// createFilePath returns a path with the leading '/'.
value: isChangelogNode ? 'changelog' : `/components${value}`,
value: slug,
});
}
}
Expand Down

0 comments on commit 2ae234d

Please sign in to comment.